EDIT:
I think I found a way around this issue while still using XSLT 1.0, although very verbose and probably prone to errors.
Is there a way to use the <xsl:number>
element but start counting at zero instead of one, especially when using level="multiple"
?
I'm using XSLT 1.0.
Current result: 1.2.2. Subitem_B
Expected result: 0.1.1. Subitem_B
I tried format="0"
but it only outputs the points (i.e. ... Subitem_B
)
<xsl:number level="multiple" format="0. "/>
Bonus question:
I found a way around it using translate($number,'.','-')
, but I'd still be curious to know if there is a way use a custom character instead of the points as delimiters, or even a custom format
altogether.
XML Input
<?xml version='1.0'?>
<?xml-stylesheet type="text/xsl" href="stylesheet.xsl" version="1.0"?>
<root>
<item>Main_A
<item>Item_A</item>
<item>Item_B
<item>Subitem_A</item>
<item>Subitem_B</item>
</item>
<item>Item_C</item>
</item>
<item>Main_B
<item>Item_A
<item>Subitem_A</item>
</item>
<item>Item_B</item>
</item>
</root>
XSLT 1.0 Stylesheet
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:template match="root">
<html>
<body>
<xsl:apply-templates match="item"/>
</body>
</html>
</xsl:template>
<xsl:template match="item">
<xsl:number level="multiple" format="1. "/>
<xsl:apply-templates match="item"/>
</xsl:template>
</xsl:stylesheet>
HTML Output
<html>
<body>
1. Main_A
1.1. Item_A
1.2. Item_B
1.2.1. Subitem_A
1.2.2. Subitem_B
1.3. Item_C
2. Main_B
2.1. Item_A
2.1.1. Subitem_A
2.2. Item_B
</body>
</html>