Given the following XML input:
� <
test>
� <scan>1</scan>
� <scan>2</scan>
� <scan>3</scan>
� <scan>4</scan>
� <scan>5</scan>
� </test>
and the following XSL stylesheet:
� <xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
� � � � � � � � version="1.0">
� <xsl:output method="text"/>
� <xsl:template match="text()"/>
� <xsl:template match="test">
� � �<xsl:apply-templates/>
� </xsl:template>
� <xsl:template match="scan">
� � �content:<xsl:value-of select="."/>, position:<xsl:value-of select="position()"/>
� � �<xsl:if test="position() = last()"> I'M LAST!</xsl:if>
� </xsl:template>
� </xsl:stylesheet>
Why do I get this output?
� �content:1, position:2
� �content:2, position:4
� �content:3, position:6
� �content:4, position:8
� �content:5, position:10
It's acting as if there were other children of <test>, which there aren't.� It also doesn't seem to think the last child is really last.� This happens with both Xalan and Saxon.
If I change
� �<xsl:apply-templates/>
to either
� �<xsl:apply-templates select="*"/>
or
� �<xsl:apply-templates select="scan"/>
I get
� �content:1, position:1
� �content:2, position:2
� �content:3, position:3
� �content:4, position:4
� �content:5, position:5 I'M LAST!
which looks a lot more reasonable to me.
What's going on here?