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 769756 - xsl:number count="comment()" level="any" and xsl:number count="processing-instruction()" level="any" not giving correct results
xsl:number count="comment()" level="any" and xsl:number count="processing-ins...
Status: RESOLVED FIXED
Product: libxslt
Classification: Platform
Component: general
1.1.28
Other Windows
: Normal normal
: ---
Assigned To: Daniel Veillard
libxml QA maintainers
Depends on:
Blocks:
 
 
Reported: 2016-08-11 17:37 UTC by Martin Honnen
Modified: 2016-08-13 18:55 UTC
See Also:
GNOME target: ---
GNOME version: ---


Attachments
input sample for processing instruction numbering (126 bytes, text/xml)
2016-08-11 17:37 UTC, Martin Honnen
Details
XSLT test case for xsl:number count="processing-instruction()" level="any" (562 bytes, text/xml)
2016-08-11 17:38 UTC, Martin Honnen
Details
input sample for comment numbering test case (165 bytes, text/xml)
2016-08-11 17:39 UTC, Martin Honnen
Details
XSLT test case for xsl:number count="comment()" level="any" (486 bytes, text/xml)
2016-08-11 17:40 UTC, Martin Honnen
Details

Description Martin Honnen 2016-08-11 17:37:34 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"?>
Comment 1 Martin Honnen 2016-08-11 17:38:46 UTC
Created attachment 333127 [details]
XSLT test case for xsl:number count="processing-instruction()" level="any"
Comment 2 Martin Honnen 2016-08-11 17:39:25 UTC
Created attachment 333128 [details]
input sample for comment numbering test case
Comment 3 Martin Honnen 2016-08-11 17:40:19 UTC
Created attachment 333129 [details]
XSLT test case for xsl:number count="comment()" level="any"
Comment 4 Nick Wellnhofer 2016-08-13 18:55:11 UTC
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.