GNOME Bugzilla – Bug 595312
Problem with libexslt (Exslt) node-set() and the preceding axis
Last modified: 2021-07-05 11:00:04 UTC
When I create a node-set using the Exslt node-set function on a list of XML elements with no wrapper, I find that the preceding axis does not work correctly on the nodes in the new node-set. I created the file test0.xslt which exhibits this problem when I run it from a Windows command prompt with xsltproc test0.xslt dummy.xml Look at the output for <test0> -- the <Id>0</Id> appears twice, but it should only appear once. Note that the problem occurs for the "preceding" axis but not the "following" axis. Also, a work-around is illustrated in test1.xslt, where I wrap the original list in a parent element. test2.xslt should be run against list.xml: xsltproc test2.xslt list.xml It shows that the problem is related to the Exslt c:node-set() function when it is applied to a result-tree fragment, but not to nodes in the input document. This problem doesn't occur in the oXygen debugger, which uses Xalan. On my Windows command prompt, "xsltproc --version" reports: Using libxml 20703, libxslt 10124 and libexslt 813
Created attachment 143248 [details] Test files
The following test case sheds more light on the problem. $ xsltproc test3.xslt dummy.xml <?xml version="1.0"?> <foo> <test1> <result>1 preceded by </result> <result>2 preceded by </result> <result>3 preceded by 2</result> <result>4 preceded by 23</result> <result>5 preceded by 234</result> <result>6 preceded by 2345</result> </test1> <test2> <result>1 preceded by </result> <result>2 preceded by 1</result> <result>3 preceded by 12</result> <result>4 preceded by 123</result> <result>5 preceded by 1234</result> <result>6 preceded by 12345</result> </test2> </foo> The first top-level node never appears in the preceding nodes. The test if (cur == ctxt->context->doc->children) return (NULL); in xmlXPathNextPreceding and xmlXPathNextPrecedingInternal in http://git.gnome.org/cgit/libxml2/tree/xpath.c might be the reason. This optimization doesn't seem to work for document fragments that have more than one child at the top level.
Created attachment 143257 [details] Another test case: test3.xslt
Brilliant! I like your test example much better than mine. I'm new here, so I'd like to ask -- what are the chances of this getting in the next release?
First we would need a real for patch that fixes the bug. But I'd suggest you simply use the preceding-sibling axis instead of the preceding axis. This should work as expected.
GNOME is going to shut down bugzilla.gnome.org in favor of gitlab.gnome.org. As part of that, we are mass-closing older open tickets in bugzilla.gnome.org which have not seen updates for a longer time (resources are unfortunately quite limited so not every ticket can get handled). If you can still reproduce the situation described in this ticket in a recent and supported software version, then please follow https://wiki.gnome.org/GettingInTouch/BugReportingGuidelines and create a new ticket at https://gitlab.gnome.org/GNOME/libxslt/-/issues/ Thank you for your understanding and your help.