How to use position() in XSLT for looping



I am new to XSLT and I have an XML like so;



<TerminalRoutes>
<Segment>
<From>
<previous>DEN </previous>
<current>DNV</current>
</From>
<From>
<previous>LAX </previous>
<current>LAS</current>
</From>
</Segment>
<Segment>
<To>
<previous>ATL </previous>
<current>ATN</current>
</To>
<To>
<previous>JFK</previous>
<current>LGA </current>
</To>
</Segment>
</TerminalRoutes>


I am trying to transform the XML into HTML using XSLT and I am applying this template



<xsl:template match="TerminalRoutes">
<tr>
<td>
<b>Terminal Routes</b>
</td>
<td>&#160;</td>
<td>&#160;</td>
</tr>
<tr>

<td>TERMINAL ROUTES FROM</td>
<td>
<xsl:value-of select="Segment/From/previous"></xsl:value-of>
</td>
<td>
<xsl:value-of select="Segment/From/current"></xsl:value-of>
</td>
</tr>
<tr>
<td>TERMINAL ROUTES TO</td>
<td>
<xsl:value-of select="Segment/To/previous"></xsl:value-of>
</td>
<td>
<xsl:value-of select="Segment/To/current"></xsl:value-of>
</td>
</tr>
</xsl:template>


and the resultant HTML gives me the first result set i.e the first "From" and the first "To".


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 position() function that can be used with but I am not sure how.


No comments:

Post a Comment