GNOME Bugzilla – Bug 70131
xslt pattern problem
Last modified: 2009-08-15 18:40:50 UTC
The problem is with predicates. Given a templete with the match pattern: //b/child::*[self::aa or self::bb or self::cc][position()=last()] the stylesheet should get the last aa, bb, or cc element with element b as a parent but it doesn't. In fact I tested this with testXPath and it works. $ gnome/gnome-xml/testXPath -i abc.xml "//b/child::*[self::aa or self::bb or self::cc][position()=last()]" Object is a Node Set : Set contains 3 nodes: 1 ELEMENT cc 2 ELEMENT cc 3 ELEMENT aa I also tested with xt and it works. I suspect the precompiled pattern gets missinterpreted as get the aa, bb, or cc element if it is the last element in the context of element b; but I don't really know. test file: <?xml version="1.0"?> <a> <b> <aa>first</aa> <bb>second</bb> <cc>third</cc> <d>d</d> <e>e</e> </b> <b> <cc>first</cc> <e>e</e> </b> <b> <bb>first</bb> <aa>second</aa> <d>d</d> <d>d</d> </b> </a> test stylesheet: <?xml version='1.0'?> <xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version='1.0'> <xsl:output method="xml" indent="yes"/> <!-- ==================================================================== --> <!-- ******************************************************************** a default template rule to match any elements that are not covered by other templates ******************************************************************** --> <!-- <xsl:template match="@*|node()|comment()"> <xsl:copy> <xsl:apply-templates select="@*|node()|comment()"/> </xsl:copy> </xsl:template> --> <!-- --> <xsl:template match="//b/child::*[self::aa or self::bb or self::cc][position()=last()]"> <xsl:variable name="pos" select="position()"/> <xsl:message> <xsl:text>found=</xsl:text> <xsl:value-of select="$pos"/> <xsl:text> </xsl:text> <xsl:value-of select="position()"/> </xsl:message> <xsl:if test="position()=1"> <xsl:message> <xsl:text>found=</xsl:text> <xsl:value-of select="name(.)"/> </xsl:message> </xsl:if> <xsl:if test="position()=last()"> <xsl:message> <xsl:text>found last</xsl:text> </xsl:message> </xsl:if> </xsl:template> </xsl:stylesheet>
I think I fixed it, however I'm unsure about the position() informations in the context: orchis:~/XSLT/xsltproc -> ./xsltproc --noout tst.xsl tst.xml found=6 6 found=2 2 found=4 4 orchis:~/XSLT/xsltproc -> which mean that currently I pass as position() the position of the matching node at the //p/child::* level, not its position in the nodeset resulting of the: //b/child::*[self::aa or self::bb or self::cc][position()=last()] query. If it was the case the result messages would be found=1 3 found=2 3 found=3 3 I'm still unclear on what is the proper semantic for those. What does XT report on this example ? thanks, Daniel
xt is also: found=6 6 found=2 2 found=4 4 It looks correct, thanks.
Excellent, so the bug is fixed in the libxml2-2.4.15/libxslt-1.0.12 releases ! thanks again, Daniel