mirror of
https://gitlab.gnome.org/GNOME/libxslt
synced 2026-01-07 21:58:22 +03:00
Fix <xsl:number level="any"/> for non-element nodes
Fix counting of nodes with <xsl:number level="any"/> when the current node is a - comment - processing instruction - attribute - text node - namespace node The old code skipped the current node and preceding siblings for these node types. Thanks to Martin Honnen for the report. Fixes bug #769756: https://bugzilla.gnome.org/show_bug.cgi?id=769756
This commit is contained in:
@@ -616,25 +616,7 @@ xsltNumberFormatGetAnyLevel(xsltTransformContextPtr context,
|
||||
{
|
||||
int amount = 0;
|
||||
int cnt = 0;
|
||||
xmlNodePtr cur;
|
||||
|
||||
/* select the starting node */
|
||||
switch (node->type) {
|
||||
case XML_ELEMENT_NODE:
|
||||
cur = node;
|
||||
break;
|
||||
case XML_ATTRIBUTE_NODE:
|
||||
cur = ((xmlAttrPtr) node)->parent;
|
||||
break;
|
||||
case XML_TEXT_NODE:
|
||||
case XML_PI_NODE:
|
||||
case XML_COMMENT_NODE:
|
||||
cur = node->parent;
|
||||
break;
|
||||
default:
|
||||
cur = NULL;
|
||||
break;
|
||||
}
|
||||
xmlNodePtr cur = node;
|
||||
|
||||
while (cur != NULL) {
|
||||
/* process current node */
|
||||
@@ -653,16 +635,25 @@ xsltNumberFormatGetAnyLevel(xsltTransformContextPtr context,
|
||||
(cur->type == XML_HTML_DOCUMENT_NODE))
|
||||
break; /* while */
|
||||
|
||||
while ((cur->prev != NULL) && ((cur->prev->type == XML_DTD_NODE) ||
|
||||
(cur->prev->type == XML_XINCLUDE_START) ||
|
||||
(cur->prev->type == XML_XINCLUDE_END)))
|
||||
cur = cur->prev;
|
||||
if (cur->prev != NULL) {
|
||||
for (cur = cur->prev; cur->last != NULL; cur = cur->last);
|
||||
} else {
|
||||
cur = cur->parent;
|
||||
}
|
||||
|
||||
if (cur->type == XML_NAMESPACE_DECL) {
|
||||
/*
|
||||
* The XPath module stores the parent of a namespace node in
|
||||
* the ns->next field.
|
||||
*/
|
||||
cur = (xmlNodePtr) ((xmlNsPtr) cur)->next;
|
||||
} else if (cur->type == XML_ATTRIBUTE_NODE) {
|
||||
cur = cur->parent;
|
||||
} else {
|
||||
while ((cur->prev != NULL) && ((cur->prev->type == XML_DTD_NODE) ||
|
||||
(cur->prev->type == XML_XINCLUDE_START) ||
|
||||
(cur->prev->type == XML_XINCLUDE_END)))
|
||||
cur = cur->prev;
|
||||
if (cur->prev != NULL) {
|
||||
for (cur = cur->prev; cur->last != NULL; cur = cur->last);
|
||||
} else {
|
||||
cur = cur->parent;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
array[amount++] = (double) cnt;
|
||||
|
||||
9
tests/docs/bug-195.xml
Normal file
9
tests/docs/bug-195.xml
Normal file
@@ -0,0 +1,9 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<!-- first comment -->
|
||||
<root>
|
||||
<!-- second comment -->
|
||||
<foo>
|
||||
<!-- third comment -->
|
||||
</foo>
|
||||
</root>
|
||||
<!-- fourth comment -->
|
||||
9
tests/docs/bug-196.xml
Normal file
9
tests/docs/bug-196.xml
Normal file
@@ -0,0 +1,9 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<?pi first?>
|
||||
<root>
|
||||
<?pi second?>
|
||||
<foo>
|
||||
<?pi third?>
|
||||
</foo>
|
||||
</root>
|
||||
<?pi fourth?>
|
||||
6
tests/docs/bug-197.xml
Normal file
6
tests/docs/bug-197.xml
Normal file
@@ -0,0 +1,6 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<root attr="1">
|
||||
<foo attr="2">
|
||||
<bar attr="3"/>
|
||||
</foo>
|
||||
</root>
|
||||
2
tests/docs/bug-198.xml
Normal file
2
tests/docs/bug-198.xml
Normal file
@@ -0,0 +1,2 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<root>a<foo>b<bar>c</bar>d</foo>e</root>
|
||||
6
tests/docs/bug-199.xml
Normal file
6
tests/docs/bug-199.xml
Normal file
@@ -0,0 +1,6 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<root xmlns:a="a">
|
||||
<foo xmlns:a="b">
|
||||
<bar xmlns:a="c"/>
|
||||
</foo>
|
||||
</root>
|
||||
8
tests/general/bug-195.out
Normal file
8
tests/general/bug-195.out
Normal file
@@ -0,0 +1,8 @@
|
||||
<?xml version="1.0"?>
|
||||
<!-- first comment id="1"-->
|
||||
<root>
|
||||
<!-- second comment id="2"-->
|
||||
<foo>
|
||||
<!-- third comment id="3"-->
|
||||
</foo>
|
||||
</root><!-- fourth comment id="4"-->
|
||||
19
tests/general/bug-195.xsl
Normal file
19
tests/general/bug-195.xsl
Normal file
@@ -0,0 +1,19 @@
|
||||
<?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>
|
||||
7
tests/general/bug-196.out
Normal file
7
tests/general/bug-196.out
Normal file
@@ -0,0 +1,7 @@
|
||||
<?xml version="1.0"?>
|
||||
<?pi first id="1"?><root>
|
||||
<?pi second id="2"?>
|
||||
<foo>
|
||||
<?pi third id="3"?>
|
||||
</foo>
|
||||
</root><?pi fourth id="4"?>
|
||||
19
tests/general/bug-196.xsl
Normal file
19
tests/general/bug-196.xsl
Normal file
@@ -0,0 +1,19 @@
|
||||
<?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>
|
||||
6
tests/general/bug-197.out
Normal file
6
tests/general/bug-197.out
Normal file
@@ -0,0 +1,6 @@
|
||||
<?xml version="1.0"?>
|
||||
<root attr="1">
|
||||
<foo attr="1">
|
||||
<bar attr="1"/>
|
||||
</foo>
|
||||
</root>
|
||||
16
tests/general/bug-197.xsl
Normal file
16
tests/general/bug-197.xsl
Normal file
@@ -0,0 +1,16 @@
|
||||
<?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="@*">
|
||||
<xsl:attribute name="{name()}">
|
||||
<xsl:number count="@*" level="any" />
|
||||
</xsl:attribute>
|
||||
</xsl:template>
|
||||
|
||||
</xsl:stylesheet>
|
||||
2
tests/general/bug-198.out
Normal file
2
tests/general/bug-198.out
Normal file
@@ -0,0 +1,2 @@
|
||||
<?xml version="1.0"?>
|
||||
<root>a(1)<foo>b(2)<bar>c(3)</bar>d(4)</foo>e(5)</root>
|
||||
17
tests/general/bug-198.xsl
Normal file
17
tests/general/bug-198.xsl
Normal file
@@ -0,0 +1,17 @@
|
||||
<?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="text()">
|
||||
<xsl:value-of select="."/>
|
||||
<xsl:text>(</xsl:text>
|
||||
<xsl:number count="text()" level="any" />
|
||||
<xsl:text>)</xsl:text>
|
||||
</xsl:template>
|
||||
|
||||
</xsl:stylesheet>
|
||||
6
tests/general/bug-199.out
Normal file
6
tests/general/bug-199.out
Normal file
@@ -0,0 +1,6 @@
|
||||
<?xml version="1.0"?>
|
||||
<root xmlns:a="a" ns="a(1)">
|
||||
<foo xmlns:a="b" ns="b(2)">
|
||||
<bar xmlns:a="c" ns="c(3)"/>
|
||||
</foo>
|
||||
</root>
|
||||
18
tests/general/bug-199.xsl
Normal file
18
tests/general/bug-199.xsl
Normal file
@@ -0,0 +1,18 @@
|
||||
<?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:for-each select="namespace::a">
|
||||
<xsl:attribute name="ns">
|
||||
<xsl:value-of select="."/>
|
||||
<xsl:text>(</xsl:text>
|
||||
<xsl:number count="*" level="any"/>
|
||||
<xsl:text>)</xsl:text>
|
||||
</xsl:attribute>
|
||||
</xsl:for-each>
|
||||
<xsl:apply-templates select="node()|@*"/>
|
||||
</xsl:copy>
|
||||
</xsl:template>
|
||||
|
||||
</xsl:stylesheet>
|
||||
Reference in New Issue
Block a user