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 531685 - Wrong interpretation of positional predicate in combination with text() node test in match patterns
Wrong interpretation of positional predicate in combination with text() node ...
Status: RESOLVED FIXED
Product: libxslt
Classification: Platform
Component: general
1.1.22
Other All
: Normal normal
: ---
Assigned To: Daniel Veillard
libxml QA maintainers
Depends on:
Blocks:
 
 
Reported: 2008-05-06 09:09 UTC by Michael Ludwig
Modified: 2013-08-04 23:33 UTC
See Also:
GNOME target: ---
GNOME version: ---



Description Michael Ludwig 2008-05-06 09:09:33 UTC
Please describe the problem:
In match patterns, positional predicates do not work correctly.

For example, a template matching the first text node below a given element node does not match as specified when there also is an attribute node on the element node in question. Actually, in the presence of attribute nodes, the positions of the following text nodes seem to shifted upwards. The same seems to happen with regard to text nodes of interspersed element nodes (mixed content).

For someone knowledgeable with regard to LibXSLT, a good way to determine what exactly is going on might be to increment the positional predicate in the example XSLT program below to 2, 3 and 4, and watch the results, which are all wrong. There are only two text() children per <E> element node; however, they are addressed with positions 1 and 3 for the first <E> element node, and with positions 2 and 4 for the second <E> element node. In both cases, they should be addressable by 1 and 2.

Steps to reproduce:
<Urmel>
  <E>1. zwei <F>drei</F> zwei eins</E>
  <E a="b">2. zwei <F>drei</F> zwei eins</E>
</Urmel>

<xsl:transform version="1.0"
  xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
  <xsl:template match="E/text()[ 1 ]">
    <xsl:value-of select="substring-before( . , ' ')"/>
    <xsl:text> * </xsl:text>
    <xsl:value-of select="substring-after( . , ' ')"/>
  </xsl:template>
  <xsl:template match="@*|node()">
    <xsl:copy>
      <xsl:apply-templates select="@*|node()"/>
    </xsl:copy>
  </xsl:template>
</xsl:transform>


Actual results:
<?xml version="1.0"?>
<Urmel>
  <E>1. * zwei <F>drei</F> zwei eins</E>
  <E a="b">2. zwei <F>drei</F> zwei eins</E>
</Urmel>

The template "E/text()[ 1 ]" does not match the first text node of the the <E> element carrying an attribute.

Expected results:
<?xml version="1.0" encoding="UTF-8"?><Urmel>
  <E>1. * zwei <F>drei</F> zwei eins</E>
  <E a="b">2. * zwei <F>drei</F> zwei eins</E>
</Urmel>

The template "E/text()[ 1 ]" matches the first text nodes of both <E> elements.

Does this happen every time?
Yes.

Other information:
Comment 1 Michael Ludwig 2008-05-07 06:41:32 UTC
This originated on XSL-List:

Re: [xsl] What to use instead of xsl:value-of
http://www.biglist.com/lists/lists.mulberrytech.com/xsl-list/archives/200805/msg00086.html
Comment 2 Nick Wellnhofer 2013-08-04 23:33:20 UTC
Fixed in commit cd40951e.