<xslTutorial creator="nicmila@idoox.com">
<index keywords='xsl:variable xsl:param last() position()'/>

<description><stylesheet id='id2'/> and <stylesheet id='id4'/> demonstrate different ways of setting xsl:variable, <stylesheet id='id3'/> and <stylesheet id='id5'/> of setting xsl:param.</description>

<xmlSource id="id1">
<chapter>Chapter A</chapter>
<chapter>Chapter B</chapter>
<chapter>Chapter C</chapter>
<chapter>Chapter D</chapter>
</xmlSource>

<attValues>
<value match=''></value>
</attValues>


 <xslStylesheet id="id2">
<xsl:variable name="totalChapters">
<xsl:value-of select="count(//chapter)"/>
</xsl:variable>


<xsl:template match="/">
<TABLE>

<xsl:for-each select="//chapter">
<TR><TD>
<xsl:value-of select="."/>
<xsl:text> (</xsl:text>
<xsl:value-of select="position()"/>
<xsl:text>/</xsl:text>
<xsl:value-of select="$totalChapters"/>
<xsl:text>)</xsl:text>

</TD></TR>
</xsl:for-each>
</TABLE>
</xsl:template>
</xslStylesheet>

<xslStylesheet id="id3">
<xsl:param name="totalChapters">
<xsl:value-of select="count(//chapter)"/>
</xsl:param>

<xsl:template match="/">
<TABLE>

<xsl:for-each select="//chapter">
<TR><TD>
<xsl:value-of select="."/>
<xsl:text> (</xsl:text>
<xsl:value-of select="position()"/>
<xsl:text>/</xsl:text>
<xsl:value-of select="$totalChapters"/>
<xsl:text>)</xsl:text>

</TD></TR>
</xsl:for-each>
</TABLE>
</xsl:template>
</xslStylesheet>

 <xslStylesheet id="id4">
<xsl:variable name="totalChapters" select='count(//chapter)'/>

<xsl:template match="/">
<TABLE>

<xsl:for-each select="//chapter">
<TR><TD>
<xsl:value-of select="."/>
<xsl:text> (</xsl:text>
<xsl:value-of select="position()"/>
<xsl:text>/</xsl:text>
<xsl:value-of select="$totalChapters"/>
<xsl:text>)</xsl:text>

</TD></TR>
</xsl:for-each>
</TABLE>
</xsl:template>
</xslStylesheet>

<xslStylesheet id="id5">
<xsl:param name="totalChapters" select='count(//chapter)'/>

<xsl:template match="/">
<TABLE>

<xsl:for-each select="//chapter">
<TR><TD>
<xsl:value-of select="."/>
<xsl:text> (</xsl:text>
<xsl:value-of select="position()"/>
<xsl:text>/</xsl:text>
<xsl:value-of select="$totalChapters"/>
<xsl:text>)</xsl:text>

</TD></TR>
</xsl:for-each>
</TABLE>
</xsl:template>
</xslStylesheet>
</xslTutorial>