GNOME Bugzilla – Bug 531685
Wrong interpretation of positional predicate in combination with text() node test in match patterns
Last modified: 2013-08-04 23:33:20 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:
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
Fixed in commit cd40951e.