Numbering paragraphs

Discussion in 'XML' started by ar, Jun 25, 2003.

  1. ar

    ar Guest

    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
    ar, Jun 25, 2003
    #1
    1. Advertising

  2. ar

    Marrow Guest

    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

    "ar" <> wrote in message
    news:bdbokp$2g7$...
    > 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
    >
    >
    Marrow, Jun 25, 2003
    #2
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Rlrcstr

    Collapsable paragraphs...

    Rlrcstr, May 16, 2005, in forum: ASP .Net
    Replies:
    7
    Views:
    673
    Rlrcstr
    May 17, 2005
  2. jersie0
    Replies:
    0
    Views:
    671
    jersie0
    Nov 23, 2003
  3. Jeff
    Replies:
    3
    Views:
    9,107
    kleinbaas
    Apr 13, 2010
  4. City Dweller

    Default leading for paragraphs

    City Dweller, Apr 6, 2006, in forum: HTML
    Replies:
    13
    Views:
    1,086
    Nije Nego
    Apr 8, 2006
  5. Jesse Engle

    allowing user to enter paragraphs

    Jesse Engle, Mar 6, 2004, in forum: C Programming
    Replies:
    13
    Views:
    534
Loading...

Share This Page