Details
-
Bug
-
Status: Resolved
-
Major
-
Resolution: Fixed
-
1.10
-
None
-
winxp-sp2
Description
The key() function does not work when the context node is the root node of a result tree fragment obtained through exsl:node-set().
Consider the following stylesheet (applied to any input document, the actual input does not matter):
<?xml version="1.0" encoding = "ISO-8859-1"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:exsl="http://exslt.org/common">
<xsl:key name="lookup-by-name" match="*" use="local-name()"/>
<xsl:variable name="test-tree-rtf"><N1><N2><N3></N3></N2></N1></xsl:variable>
<xsl:variable name="test-tree" select="exsl:node-set($test-tree-rtf)/*"/>
<xsl:template match="/">
<!-- key() with context within the result tree fragment. -->
<xsl:for-each select="$test-tree">
<xsl:for-each select=".">
<xsl:variable name="n1" select="key('lookup-by-name', 'N1')"/>
<xsl:choose>
<xsl:when test="count($n1)=1"><xsl:message>OK </xsl:message></xsl:when>
<xsl:otherwise><xsl:message>BUG </xsl:message></xsl:otherwise>
</xsl:choose>
</xsl:for-each>
</xsl:for-each>
<!-- key() with context being the root of the result tree fragment. -->
<xsl:for-each select="$test-tree">
<xsl:for-each select="/">
<xsl:variable name="n1" select="key('lookup-by-name', 'N1')"/>
<xsl:choose>
<xsl:when test="count($n1)=1"><xsl:message>OK </xsl:message></xsl:when>
<xsl:otherwise><xsl:message>BUG </xsl:message></xsl:otherwise>
</xsl:choose>
</xsl:for-each>
</xsl:for-each>
</xsl:template>
</xsl:stylesheet>
In the two cases, the key() function should return the N1 node belonging to the result tree fragment
(because the result tree fragment is acting as the "context document" in both cases).
However, it works only in the first case (it prints "OK"), not the second (it prints "BUG").
I could find that the cause of the bug is in the function getKeyNode() of StylesheetRoot.cpp.
This function does not work when the context node is a DOCUMENT_FRAGMENT_NODE to start with.
I rewrote it so that it works in that case too (see attachment).
Best regards,
Alain Le Guennec.