GNOME Bugzilla – Bug 61962
Weird behavior between strip-space and equality test
Last modified: 2009-08-15 18:40:50 UTC
strip-case creates sometimes false results while testing for equality between nodes, for instance: xml: <?xml version="1.0" encoding="UTF-8"?> <test> <tr><td>pat</td> </tr> <tr><td>pat</td> </tr> </test> xslt: <?xml version="1.0" encoding="UTF-8"?> <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:xlink="http://www.w3.org/1999/xlink" exclude-result-prefixes="xlink"> <xsl:strip-space elements="*"/> <xsl:template match="/"> <xsl:apply-templates select="test/tr[1]"/> </xsl:template> <xsl:template match="tr"> <nb> <xsl:value-of select="count(/test/tr[. = current()])"/> </nb> </xsl:template> </xsl:stylesheet> Result is: <?xml version="1.0"?> <nb>1</nb> (should be 2) Version: Using libxml 20405, libxslt 10004 and libexslt 400 xsltproc was compiled against libxml 20403, libxslt 10004 and libexslt 400 libxslt 10004 was compiled against libxml 20403 libexslt 400 was compiled against libxml 20403 Thanks Eric
Could you explain a bit why you expect 2 ? It looks to me that /test/tr[. = current()] could at best select 1 node and hence count can at most be 1, but I may have missed something, Daniel
When I write ". = current()", "." is the current node in the XPath step while "current()" is the XSLT context node. Both are a node set containing a single node and this is a test between two node sets. Per http://www.w3.org/TR/xpath#booleans: "If both objects to be compared are node-sets, then the comparison will be true if and only if there is a node in the first node-set and a node in the second node-set such that the result of performing the comparison on the string-values of the two nodes is true." Since the 2 tr nodes have the same string value, the result should then be 2. libxslt use to get the right result if I supress the strip-case clause in the style sheet or if I remove the CR between </td> and </tr> thus my comment of being something weird with strip-case. PS: this is a highly reduced repro case taken from a real life complex transformation.
Okay, I understood, thanks for the explanations. I had to rework the way strip-space was handled, it was progressive as XSLT made progresses thought the document but as you pointed out XPath expressions could access non-stripped parts of the document. Stripping now occurs at the beginning of the processing of a document: http://cvs.gnome.org/bonsai/cvsquery.cgi?module=libxslt&branch=HEAD&branchtype=match&dir=libxslt&file=&filetype=match&who=veillard&whotype=match&sortby=Date&hours=&date=explicit&mindate=10%2F09%2F01+06%3A37&maxdate=10%2F09%2F01+06%3A39&cvsroot=%2Fcvs%2Fgnome http://cvs.gnome.org/bonsai/cvsquery.cgi?module=libxslt&branch=HEAD&branchtype=match&dir=libxslt&file=&filetype=match&who=veillard&whotype=match&sortby=Date&hours=&date=explicit&mindate=10%2F09%2F01+07%3A02&maxdate=10%2F09%2F01+07%3A04&cvsroot=%2Fcvs%2Fgnome thanks for the report and explanations ! Daniel
should be fixed in the last releases, Daniel