Numbering paragraphs

A

ar

Hello,

My XML document is :
....
<paragraph title="Level 1 - Number 1">
<paragraph title="Level 2 - Number 1">
<paragraph title="Level 3 - Number 1">
...
</paragraph>
<paragraph title="Level 3 - Number 2">
...
</paragraph>
</paragraph>

<paragraph title="Level 2 - Number 2">
<paragraph title="Level 3 - Number 1">
...
</paragraph>
<paragraph title="Level 3 - Number 2">
...
</paragraph>
</paragraph>

</paragraph>
....

I'd like to number these paragraphs
1 - Level 1 - Number 1
1.1 - Level 2 - Number 1
1.1.1 - Level 3 - Number 1
1.1.2 - Level 3 - Number 2
1.2 - Level 2 - Number 2
1.2.1 - Level 3 - Number 1
1.2.2 - Level 3 - Number 2

I can have any number of paragraph levels.

Any idea on how to do that ?

Best regards
AR
 
M

Marrow

Hi AR,

Do you mean in XSLT?

If so, then <xsl:number> will do exactly what you want - for example...

<?xml version="1.0"?>
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:eek:utput method="html" indent="yes"/>
<xsl:template match="/">
<html>
<body>
<xsl:apply-templates select="paragraph"/>
</body>
</html>
</xsl:template>

<xsl:template match="paragraph">
<xsl:param name="level" select="0"/>
<div style="margin-left: {15 * $level}px;">
<xsl:number count="paragraph" level="multiple"/>
<xsl:text> </xsl:text>
<xsl:value-of select="@title"/>
<xsl:apply-templates select="paragraph">
<xsl:with-param name="level" select="$level + 1"/>
</xsl:apply-templates>
</div>
</xsl:template>
</xsl:stylesheet>

Hope this helps
Marrow
http://www.marrowsoft.com - home of Xselerator (XSLT IDE and debugger)
http://www.topxml.com/Xselerator
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,989
Messages
2,570,207
Members
46,783
Latest member
RickeyDort

Latest Threads

Top