GNOME Bugzilla – Bug 148773
keys don't work inside an exsl:node-set
Last modified: 2009-08-15 18:40:50 UTC
Keys should work inside documents created using exsl:node-set, but they don't seem to. It is easiest to explain with an extract from a thread I started on the xslt mailing list; this is / will be archived at http://www.biglist.com/lists/xsl-list/archives/200407/msg00844.html Phil> All that is stopping me is that XSLT doesn't - as far as Phil> I know - allow for keys to be used on exsl:node-set()s, David Carlisle> keys, once set up, automatically apply, separately, David Carlisle> to any document that is used and so if your David Carlisle> exsl:node-set() returns a node set consisting of David Carlisle> a root node / which it will if it is given a result David Carlisle> tree fragment coming from xsl:variable, then your David Carlisle> keys will apply to that. Phil> Thanks for the suggestion David. But I can't get it to work. Phil> Here's my test code: <xsl:transform version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:exsl="http://exslt.org/common" extension-element-prefixes="exsl"> <xsl:key name="k" match="a" use="@x"/> <xsl:template match="/"> <xsl:variable name="v"> <n> <a x="1" y="A"/> <a x="2" y="B"/> </n> </xsl:variable> <xsl:apply-templates select="exsl:node-set($v)/*"/> </xsl:template> <xsl:template match="n"> <!-- <xsl:apply-templates select="a[@x='1']"/> --> <xsl:apply-templates select="key('k','1')"/> </xsl:template> <xsl:template match="a"> <xsl:value-of select="@y"/> </xsl:template> </xsl:transform> Phil> I get no output. But when I use the non-key lookup Phil> (commented out) I get "A", as expected. This is with Phil> libxslt's xsltproc. Does it work correctly on other Phil> processors? David Carlisle> It works in saxon: David Carlisle> $ saxon keys.xsl keys.xsl David Carlisle> <?xml version="1.0" encoding="utf-8"?>A This is with libxslt 1.1.7, which seems to be the newest version is Debian Testing. Regards, --Phil.
paphio:~ -> xsltproc --version tst.xsl tst.xsl Using libxml 20611, libxslt 10108 and libexslt 806 xsltproc was compiled against libxml 20611, libxslt 10108 and libexslt 806 libxslt 10108 was compiled against libxml 20611 libexslt 806 was compiled against libxml 20611 <?xml version="1.0"?> A paphio:~ -> This Work fine in the latest released version apparently, Daniel
Hi Daniel, thanks for looking at this so quickly. There's a problem with the example; if you supply the stylesheet as the XML input to the processor, i.e. "xsltproc tst.xsl tst.xsl" it will find the <a> elements within the variable declaration. Please try again but with a different file as the XML input file, e.g. foo.xml = "<foo/>". This seems to fail for me with libxslt 1.1.8, but I have confirmed with David Carlisle that it works in Saxon. Regards, --Phil.
I added some code to libxslt to assure keys are generated (when needed) for node-sets, and it certainly fixes your example: bill@bbrack bug148773 $ ./xsltproc bug.xsl bug.xml <?xml version="1.0"?> A Changed source is in cvs (several different source files involved). Please check that your original file is now handled correctly, and re-open the bug if there is any problem. Thanks for the report and the details. Bill
Bill, Thanks. I probably won't be able to try this for a couple of weeks (I'm going on holiday) but I will check and confirm then. --Phil.
Hello again, I can confirm that this seems to solve my original problem, as well as some other key-related oddities that I was seeing. (Or at least they have been fixed by some change since 1.1.8). Thanks! However I'm not yet seeing the expected speedup that keys should give me. I'll file another bug if I can track down what is going on. --Phil.
Note the recent (16 Aug 04) enhancement to transform.c to fix bug133289 - this may be related to your performance concerns. Bill
This should be fixed in release libxslt-1.1.9. thanks, Daniel