I ran into a behavior related to types in XSLT/XPath that I can't explain. Here's a snippet of XSLT that shows the problem (it's not a very useful XSLT, of course, but it represents a pretty minimal demonstration my question):
<?xml version="1.0"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0">
<xsl:template match="/">
<xsl:variable name="root">
<xsl:sequence select="root(.)"/>
</xsl:variable>
<xsl:if test="root(.) is $root">
Match
</xsl:if>
</xsl:template>
</xsl:stylesheet>
You will see that "Match" is not displayed. However, if you add as="node()"
to the <xsl:variable name="root">
then "Match" is displayed.
Can anyone explain help me understand why?
You can plug this XSLT into http://xslttest.appspot.com to explore the problem. Any input XML will work (e.g., <?xml version="1.0"?><foo/>
).
Thanks, Josh.