title: How to use position() in XSLT for looping
body: <p>I am new to XSLT and I have an XML like so;</p>
  
  <pre><code>&lt;TerminalRoutes&gt;
          &lt;Segment&gt;
              &lt;From&gt;
                  &lt;previous&gt;DEN &lt;/previous&gt;
                  &lt;current&gt;DNV&lt;/current&gt;
              &lt;/From&gt;
              &lt;From&gt;
                  &lt;previous&gt;LAX &lt;/previous&gt;
                  &lt;current&gt;LAS&lt;/current&gt;
              &lt;/From&gt;
          &lt;/Segment&gt;
          &lt;Segment&gt;
              &lt;To&gt;
                  &lt;previous&gt;ATL &lt;/previous&gt;
                  &lt;current&gt;ATN&lt;/current&gt;
              &lt;/To&gt;
              &lt;To&gt;
                  &lt;previous&gt;JFK&lt;/previous&gt;
                  &lt;current&gt;LGA &lt;/current&gt;
              &lt;/To&gt;
          &lt;/Segment&gt;
   &lt;/TerminalRoutes&gt;
  </code></pre>
  
  <p>I am trying to transform the XML into HTML using XSLT and I am applying this template</p>
  
  <pre><code>&lt;xsl:template match="TerminalRoutes"&gt;
              &lt;tr&gt;
                  &lt;td&gt;
                      &lt;b&gt;Terminal Routes&lt;/b&gt;
                  &lt;/td&gt;
                  &lt;td&gt;&amp;#160;&lt;/td&gt;
                  &lt;td&gt;&amp;#160;&lt;/td&gt;
              &lt;/tr&gt;
              &lt;tr&gt;
  
              &lt;td&gt;TERMINAL ROUTES FROM&lt;/td&gt;
                  &lt;td&gt;
                      &lt;xsl:value-of select="Segment/From/previous"&gt;&lt;/xsl:value-of&gt;
                  &lt;/td&gt;
                  &lt;td&gt;
                      &lt;xsl:value-of select="Segment/From/current"&gt;&lt;/xsl:value-of&gt;
                  &lt;/td&gt;
              &lt;/tr&gt;
              &lt;tr&gt;
              &lt;td&gt;TERMINAL ROUTES TO&lt;/td&gt;
                  &lt;td&gt;
                      &lt;xsl:value-of select="Segment/To/previous"&gt;&lt;/xsl:value-of&gt;
                  &lt;/td&gt;
                  &lt;td&gt;
                      &lt;xsl:value-of select="Segment/To/current"&gt;&lt;/xsl:value-of&gt;
                  &lt;/td&gt;
              &lt;/tr&gt;
          &lt;/xsl:template&gt;
  </code></pre>
  
  <p>and the resultant HTML gives me the first result set i.e the first "From" and the first "To". </p>
  
  <p>What I want is to re-apply the same template, so I can capture the second result set i.e the second "From" and the second "To". I believe there is a <code>position()</code> function that can be used with  but I am not sure how.</p>