<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">

 <xsl:template match="/">
   <html>
     <head>
       <title>This shows the context position and context size</title>
     </head>
     <body>
       <h3>Context position and context size demo.</h3>
       <xsl:apply-templates select="/books/book/chapter" />
     </body>
   </html>
 </xsl:template>

 <xsl:template match="chapter">
   <xsl:if test="position()=2">
     <p>When the context node is the second <b>Chapter</b> element node then </p>
     <p>the context position is <xsl:value-of select="position()" /></p>
     <p>and the context size is <xsl:value-of select="last()" /></p>
     <p>The text the <b>Chapter</b> element node contain is <xsl:value-of select="." /></p>
   </xsl:if>
 </xsl:template>

</xsl:stylesheet>
