How to pass variables between two templates in XSLT.
I cannot use global variable because value of variable is dependent on current node under evaluation.
Say I have XSLT of sort:
<xsl:template match="product">
<xsl:variable name="pr-pos" select="count(./preceding-sibling::product)+1"/>
..
..
..
<xsl:apply-templates select="countries/country"/>
</xsl:template>
<xsl:template match="countries/country">
<tr id="country-id">
<td><a href="#" class="action" id="{concat('a-',$pr-pos)}">+</a></td>
..
..
This gives error as $pr-pos is not accessible in second template.
How do I pass variable pr-pos’ value to other template? How can I do this?
1 Answer