[xslt] xsl:number level="multiple" bug



Hi

I've attached a diff file to fix the following bug -

If you use <xsl:number level="multiple"> with no count attribute, all
ancestors of the current node are counted irrespective of whether or not
they match the default count position.

Example: 136.xml
<?xml version="1.0"?>

<XML_DATA>
<chapter>First Chapter</chapter>

<chapter>Second Chapter
<chapter>Subchapter 1</chapter>
<chapter>Subchapter 2</chapter>
</chapter>

<chapter>Third Chapter
<chapter>Subchapter A</chapter>

<chapter>Subchapter B
<chapter>sub a</chapter>
<chapter>sub b</chapter>
</chapter>

<chapter>Subchapter C</chapter>
</chapter>
</XML_DATA>

--
136.xsl
<?xml version="1.0"?>
<xsl:stylesheet xmlns:xsl='http://www.w3.org/1999/XSL/Transform'
version="1.0">
<xsl:template match="/">
<xsl:for-each select="//chapter">
<xsl:number level="multiple"/>
<xsl:text> </xsl:text>
<xsl:value-of select="./text()"/>
<xsl:text>
</xsl:text>
</xsl:for-each>
</xsl:template>
</xsl:stylesheet>

C:\libxml\libxslt-1.0.18.win32\util>xsltproc 136.xsl 136.xml
<?xml version="1.0"?>
1.1 First Chapter
1.2 Second Chapter

1.2.1 Subchapter 1
1.2.2 Subchapter 2
1.3 Third Chapter

1.3.1 Subchapter A
1.3.2 Subchapter B

1.3.2.1 sub a
1.3.2.2 sub b
1.3.3 Subchapter C

The output should be

<?xml version="1.0"?>
1 First Chapter
2 Second Chapter

2.1 Subchapter 1
2.2 Subchapter 2
3 Third Chapter

3.1 Subchapter A
3.2 Subchapter B

3.2.1 sub a
3.2.2 sub b
3.3 Subchapter C

The fix adds an extra check to the case if the count attribute is not
specified (is null) to ensure that the ancestor node matches the default
count pattern (names and types identical to the current node).

One quick question related to this:
A couple of lines below my fix where you check the names of the nodes are
equal you've got the following:

       /* FIXME */
       xmlStrEqual(preceding->name, ancestor->name)

My fix borrows this bit of code for checking the name of the current node
with the ancestor. What is wrong with this bit of code that might need
fixing?

Thanks,
Richard

libxslt_number_level.diff



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]