After an evaluation, GNOME has moved from Bugzilla to GitLab. Learn more about GitLab.
No new issues can be reported in GNOME Bugzilla anymore.
To report an issue in a GNOME project, go to GNOME GitLab.
Do not go to GNOME Gitlab for: Bluefish, Doxygen, GnuCash, GStreamer, java-gnome, LDTP, NetworkManager, Tomboy.
Bug 70131 - xslt pattern problem
xslt pattern problem
Status: VERIFIED FIXED
Product: libxslt
Classification: Platform
Component: general
1.0.10
Other All
: Normal normal
: ---
Assigned To: Daniel Veillard
Daniel Veillard
Depends on:
Blocks:
 
 
Reported: 2002-01-31 03:23 UTC by cbozeman
Modified: 2009-08-15 18:40 UTC
See Also:
GNOME target: ---
GNOME version: ---



Description cbozeman 2002-01-31 03:23:04 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>
Comment 1 Daniel Veillard 2002-02-11 12:27:05 UTC
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
Comment 2 cbozeman 2002-02-12 04:11:33 UTC
xt is also:
found=6 6
found=2 2
found=4 4
It looks correct, thanks.
Comment 3 Daniel Veillard 2002-02-12 08:41:24 UTC
Excellent, so the bug is fixed in the libxml2-2.4.15/libxslt-1.0.12
releases !

  thanks again,

Daniel