GNOME Bugzilla – Bug 769756
xsl:number count="comment()" level="any" and xsl:number count="processing-instruction()" level="any" not giving correct results
Last modified: 2016-08-13 18:55:11 UTC
Created attachment 333126 [details] input sample for processing instruction numbering I have found a problem with libxslt when using <xsl:number count="comment()" level="any" /> or <xsl:number count="processing-instruction()" level="any" /> instead of starting the numbering with 1, like other XSLT processors do (tested with Saxon 6.5.5, MSXML, Transformiix), libxslt starts numbering with 0 and reverts to 0 when counting a comment or processing instruction outside the root element. Here are the test cases: Input sample for the comment numbering: <?xml version="1.0" encoding="UTF-8"?> <!-- first comment --> <root> <!-- second comment --> <foo> <!-- third comment --> </foo> </root> <!-- fourth comment --> XSLT test code: <?xml version="1.0" encoding="UTF-8"?> <xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0"> <xsl:template match="node()|@*"> <xsl:copy> <xsl:apply-templates select="node()|@*" /> </xsl:copy> </xsl:template> <xsl:template match="comment()"> <xsl:comment> <xsl:value-of select="."/> <xsl:text> id="</xsl:text> <xsl:number count="comment()" level="any" /> <xsl:text>"</xsl:text> </xsl:comment> </xsl:template> </xsl:stylesheet> Expected output: <?xml version="1.0" encoding="utf-8"?><!-- first comment id="1"--><root> <!-- second comment id="2"--> <foo> <!-- third comment id="3"--> </foo> </root><!-- fourth comment id="4"--> xsltproc output: <?xml version="1.0"?> <!-- first comment id="0"--> <root> <!-- second comment id="1"--> <foo> <!-- third comment id="2"--> </foo> </root><!-- fourth comment id="0"--> Test input for the processing instruction numbering: <?xml version="1.0" encoding="UTF-8"?> <?pi first?> <root> <?pi second?> <foo> <?pi third?> </foo> </root> <?pi fourth?> Test code: <?xml version="1.0" encoding="UTF-8"?> <xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0"> <xsl:template match="node()|@*"> <xsl:copy> <xsl:apply-templates select="node()|@*" /> </xsl:copy> </xsl:template> <xsl:template match="processing-instruction()"> <xsl:processing-instruction name="{name()}"> <xsl:value-of select="."/> <xsl:text> id="</xsl:text> <xsl:number count="processing-instruction()" level="any" /> <xsl:text>"</xsl:text> </xsl:processing-instruction> </xsl:template> </xsl:stylesheet> Expected result: <?xml version="1.0" encoding="utf-8"?><?pi first id="1"?><root> <?pi second id="2"?> <foo> <?pi third id="3"?> </foo> </root><?pi fourth id="4"?> Output with xsltproc: <?xml version="1.0"?> <?pi first id="0"?><root> <?pi second id="1"?> <foo> <?pi third id="2"?> </foo> </root><?pi fourth id="0"?>
Created attachment 333127 [details] XSLT test case for xsl:number count="processing-instruction()" level="any"
Created attachment 333128 [details] input sample for comment numbering test case
Created attachment 333129 [details] XSLT test case for xsl:number count="comment()" level="any"
Fixed with the following commit: https://git.gnome.org/browse/libxslt/commit/?id=8345634c5482ca04293ae1862d52fa9dd764aeca The problem wasn't the count pattern, but iterating preceding nodes when the current node wasn't an element.