title: How to build a XPath with concat() and position() in a xsl:for-each
body: <p>I'm trying to show the following xml data as a table, each point in a row with some of its values as columns. Each point has many more values than the three in the example, but they all have the same number of values and I want to select some of them. In addition, there are several other elements with names other than 'Point[x]' including an element named 'Count' that indicates the number of points.</p>
  <pre><code>&lt;?xml version=&quot;1.0&quot; encoding=&quot;UTF-8&quot;?&gt;
  &lt;?xml-stylesheet type=&quot;text/xsl&quot; href=&quot;report.xsl&quot; ?&gt;
  &lt;root&gt;
    &lt;body&gt;
      &lt;part&gt;
          &lt;values&gt;
            &lt;item name=&quot;Foo&quot; value=&quot;123&quot; unit=&quot;&quot; /&gt;
            &lt;item name=&quot;Baa&quot; value=&quot;abc&quot; unit=&quot;&quot; /&gt;
            &lt;item name=&quot;Count&quot; value=&quot;3&quot; unit=&quot;&quot; /&gt;
            &lt;item name=&quot;Point[1].Value1&quot; value=&quot;640&quot; unit=&quot;m³&quot; /&gt;
            &lt;item name=&quot;Point[1].Value2&quot; value=&quot;20&quot; unit=&quot;°C&quot; /&gt;
            &lt;item name=&quot;Point[1].Value3&quot; value=&quot;40&quot; unit=&quot;%&quot; /&gt;
            &lt;item name=&quot;Point[1].Value4&quot; value=&quot;0&quot; unit=&quot;&quot; /&gt;
            &lt;item name=&quot;Point[2].Value1&quot; value=&quot;641&quot; unit=&quot;m³&quot; /&gt;
            &lt;item name=&quot;Point[2].Value2&quot; value=&quot;21&quot; unit=&quot;°C&quot; /&gt;
            &lt;item name=&quot;Point[2].Value3&quot; value=&quot;41&quot; unit=&quot;%&quot; /&gt;
            &lt;item name=&quot;Point[2].Value4&quot; value=&quot;0&quot; unit=&quot;&quot; /&gt;
            &lt;item name=&quot;Point[3].Value1&quot; value=&quot;642&quot; unit=&quot;m³&quot; /&gt;
            &lt;item name=&quot;Point[3].Value2&quot; value=&quot;22&quot; unit=&quot;°C&quot; /&gt;
            &lt;item name=&quot;Point[3].Value3&quot; value=&quot;42&quot; unit=&quot;%&quot; /&gt;
            &lt;item name=&quot;Point[3].Value4&quot; value=&quot;0&quot; unit=&quot;&quot; /&gt;
          &lt;/values&gt;
      &lt;/part&gt;
    &lt;/body&gt;
  &lt;/root&gt;
  </code></pre>
  <p>This is what I want to get:</p>
  <pre>
  No   Value1 [m³]   Value2 [°C]   Value3 [%]
  1    640           20            40
  2    641           21            41
  3    642           22            42
  </pre>
  <p>And this is what I get with the stylesheet below:</p>
  <pre>
  No   Value1 [m³]   Value2 [°C]   Value3 [%]   Col1              Col2              Col3
  1    640           20            40           Point[1].Value1   Point[1].Value2   123
  2    641           20            40           Point[2].Value1   Point[2].Value2   123
  3    642           20            40           Point[3].Value1   Point[3].Value2   123
  </pre>
  <p>I loop over all matches of &quot;].Value1&quot; and try to build the other XPaths with concat() and position(). As you can see in Col2 concat() works as expected. However, Col3 shows that my <code>select</code> expression isn't working.</p>
  <p>So what's the correct expression to select the correct point in each row?</p>
  <pre><code>&lt;?xml version=&quot;1.0&quot; encoding=&quot;iso-8859-1&quot;?&gt;
  &lt;xsl:stylesheet version=&quot;1.0&quot; xmlns:xsl=&quot;http://www.w3.org/1999/XSL/Transform&quot;&gt;
  
  &lt;xsl:template match=&quot;/&quot;&gt;
  &lt;html&gt;
      &lt;head&gt;&lt;/head&gt;
      &lt;body&gt;
          &lt;table&gt;
              &lt;tr&gt;
                  &lt;th&gt;No&lt;/th&gt;
                  &lt;th&gt;Value1 [m³]&lt;/th&gt;
                  &lt;th&gt;Value2 [°C]&lt;/th&gt;
                  &lt;th&gt;Value3 [%]&lt;/th&gt;
                  &lt;th&gt;Col1&lt;/th&gt;
                  &lt;th&gt;Col2&lt;/th&gt;
                  &lt;th&gt;Col3&lt;/th&gt;
              &lt;/tr&gt;
              
              &lt;xsl:for-each select=&quot;//*[contains(@name, '].Value1')]&quot;&gt;
              &lt;tr&gt;
                  &lt;td&gt;
                      &lt;xsl:value-of select=&quot;position()&quot;/&gt;
                  &lt;/td&gt;
                  &lt;td&gt;
                      &lt;xsl:value-of select=&quot;@value&quot;/&gt;
                  &lt;/td&gt;
                  &lt;td&gt;
                      &lt;xsl:value-of select=&quot;//item[@name='Point[1].Value2']/@value&quot;/&gt;
                  &lt;/td&gt;
                  &lt;td&gt;
                      &lt;xsl:value-of select=&quot;//item[@name='Point[1].Value3']/@value&quot;/&gt;
                  &lt;/td&gt;
                  
                  &lt;td&gt;
                      &lt;xsl:value-of select=&quot;@name&quot;/&gt;
                  &lt;/td&gt;
                  &lt;td&gt;
                      &lt;xsl:value-of select=&quot;concat('Point[', position(), '].Value2')&quot;/&gt;
                  &lt;/td&gt;
                  
                  &lt;td&gt;
                      &lt;xsl:value-of select=&quot;//item[concat(@name='Point[', position(), '].Value2')]/@value&quot;/&gt;
                  &lt;/td&gt;
              &lt;/tr&gt;
              &lt;/xsl:for-each&gt;
          
          &lt;/table&gt;
      &lt;/body&gt;
  &lt;/html&gt;
  &lt;/xsl:template&gt;
  
  &lt;/xsl:stylesheet&gt;
  </code></pre>
  <p>Edit: described the structure of the data in more detail</p>