GNOME Bugzilla – Bug 119126
Wrongly evaluated key when context node is in temporal RTF
Last modified: 2009-08-15 18:40:50 UTC
When you invoke key() function and context node is in temporal result tree fragment (e.g. constructed by node-set() function), key() function does return nothing even there is corresponding node in the source document. See attached files for demonstration of error. --- test.xsl -- <xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:exsl="http://exslt.org/common" extension-element-prefixes="exsl" version="1.0"> <!-- Make key for all elements with id attribute --> <xsl:key name="id" match="*[@id]" use="@id"/> <xsl:template match="/"> <!-- Copy whole document as RTF into variable --> <xsl:variable name="rtf"> <xsl:copy-of select="."/> </xsl:variable> <!-- Convert RTF back to nodeset --> <xsl:variable name="nodes" select="exsl:node-set($rtf)"/> <!-- Apply templates to nodeset --> <xsl:apply-templates select="$nodes/*"/> </xsl:template> <xsl:template match="link"> <xsl:text>Target content:</xsl:text> <!-- Lookup content of element with specified id in a source document --> <xsl:value-of select="key('id', @target)"/> <!-- And there is error, it prints nothing instead of content of referenced element --> </xsl:template> <xsl:template match="text()"/> </xsl:stylesheet> --- test.xml --- <test> <link target="b"/> <section id="b">Foo</section> </test>
If I do understand correctly, the current document is the RTF copy which as the node-set() extension sub-specify acts like a new document. The keys are not computed on that document, this is not a stated requirement. On the other hand the definition for key() in the XSLT-1.0 spec states: - The key function does for keys what the id function does for IDs. - and the id() function states clearly: "the result is a node-set containing the elements in the same document as the context node that..." The context document is the RTF. It has no key index, there is no semantic associated to key for result of node-set() as far as I can tell, there is nothing at http://exslt.org/exsl/functions/node-set/index.html indicating any other processing than doing the conversion... So nothing in the specs indicate that id() or key() should work when the current node is in the result of a node-set() Conclusion: your stylesheet relies on totally unspecified behaviour I have a hard time accepting as a bug, but if you have further evidence, I would take them... Daniel P.S.: I hardly see this as a major or critical bug ...
No new information, I think we can close this now, Daniel