[XSL-LIST Mailing List Archive Home] [By Thread] [By Date] [Recent Entries] [Reply To This Message] Numbering quandry
Hello all, I have numbering difficulty. I'm trying to number sections hierarchically, and also to include the number of their parent section, if they have any, or their own number if they are a top-level section. This is what I have: <report> <section title="foo"> <section title="bar"> <section title="baz"/> </section> </section> <section title="things"> <section title="thing1"/> <section title="thing2"> <section title="subthing1"/> <section title="subthing2"/> <section title="subthing3"/> </section> </section> </report> This is what I want as output: <html> <head> <title>Test</title> </head> <body> <ul> <li>Section foo (1., parent 1.)</li> <ul> <li>Section bar (1.1., parent 1.)</li> <ul> <li>Section baz (1.1.1., parent 1.1.)</li> </ul> </ul> </ul> <ul> <li>Section things (2., parent 2.)</li> <ul> <li>Section thing1 (2.1., parent 2.)</li> </ul> <ul> <li>Section thing2 (2.2., parent 2.)</li> <ul> <li>Section subthing1 (2.2.1., parent 2.2.)</li> </ul> <ul> <li>Section subthing2 (2.2.2., parent 2.2.)</li> </ul> <ul> <li>Section subthing3 (2.2.3., parent 2.2.)</li> </ul> </ul> </ul> </body> </html> After checking out the FAQ I saw an example on numbering based on the parent, which gave me the idea to try this: <?xml version="1.0" ?> <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"> <xsl:template match="report"> <html> <head><title>Test</title></head> <body> <xsl:apply-templates/> </body> </html> </xsl:template> <xsl:template match="section/section"> <ul> <li> <xsl:text>Section </xsl:text> <xsl:value-of select="@title"/> <xsl:text> (</xsl:text> <xsl:number level="multiple" count="section" format="1.1.0"/> <xsl:text>, parent </xsl:text> <xsl:number level="multiple" count="section/section" format="1.1.0"/> <xsl:text>)</xsl:text> </li> <xsl:apply-templates/> </ul> </xsl:template> <xsl:template match="/report/section"> <ul> <li> <xsl:text>Section </xsl:text> <xsl:value-of select="@title"/> <xsl:text> (</xsl:text> <xsl:number level="multiple" count="section" format="1.1.0"/> <xsl:text>, parent </xsl:text> <xsl:number level="multiple" count="section" format="1.1.0"/> <xsl:text>)</xsl:text> </li> <xsl:apply-templates/> </ul> </xsl:template> </xsl:stylesheet> But this gives me: <html> <head> <META http-equiv="Content-Type" content="text/html"> <title>Test</title> </head> <body> <ul> <li>Section foo (1., parent 1.)</li> <ul> <li>Section bar (1.1., parent 1.)</li> <ul> <li>Section baz (1.1.1., parent 1.1.)</li> </ul> </ul> </ul> <ul> <li>Section things (2., parent 2.)</li> <ul> <li>Section thing1 (2.1., parent 1.)</li> </ul> <ul> <li>Section thing2 (2.2., parent 2.)</li> <ul> <li>Section subthing1 (2.2.1., parent 2.1.)</li> </ul> <ul> <li>Section subthing2 (2.2.2., parent 2.2.)</li> </ul> <ul> <li>Section subthing3 (2.2.3., parent 2.3.)</li> </ul> </ul> </ul> </body> </html> Close but not quite what I need. Anyone have any suggestions, or am I barking up the wrong tree? Thanks for considering, Stephen Blake Veritect s t e p h e n . b l a k e @ v e r i t e c t . c o m XSL-List info and archive: http://www.mulberrytech.com/xsl/xsl-list
|
PURCHASE STYLUS STUDIO ONLINE TODAY!Purchasing Stylus Studio from our online shop is Easy, Secure and Value Priced! Download The World's Best XML IDE!Accelerate XML development with our award-winning XML IDE - Download a free trial today! Subscribe in XML format
|