[XSL-LIST Mailing List Archive Home] [By Thread] [By Date] [Recent Entries] [Reply To This Message]

Re: problem with numbering

Subject: Re: problem with numbering
From: Jeni Tennison <jeni@xxxxxxxxxxxxxxxx>
Date: Mon, 16 Sep 2002 16:32:04 +0100
nelement
Hi Lars,

> I have a problem with the xsl:number-element. In the following part
> of a XML-document I am not able to produce the numbering which I
> have declared in the comments.
>
> <NUMMERIERUNG>
>    <!--1.--><NELEMENT>text1</NELEMENT>
>    <!--2.--><NELEMENT>text2</NELEMENT>
>    <NUMMERIERUNG>
>     <!--2.1--><NELEMENT>text21</NELEMENT>
>     <!--2.2--><NELEMENT>text22</NELEMENT>
>    </NUMMERIERUNG>
>    <!--3.--><NELEMENT>text3</NELEMENT>
> </NUMMERIERUNG>

That's a tough one. The multi-level numbering in XSLT is designed to
work with structures in which the ancestors of an element give it its
numbering; here, when an NELEMENT is nested inside a NUMMERIERUNG,
you're using the element before an element's parent to give it its
numbering.

I think that it's probably easiest to create a recursive template for
numbering NELEMENT elements. If an NELEMENT element's parent as a
NELEMENT preceding sibling, then apply templates to that to get the
first part of the number; the end of the number can be supplied
through a basic xsl:number:

<xsl:template match="NELEMENT" mode="number">
  <xsl:apply-templates mode="number"
    select="../preceding-sibling::*[1][self::NELEMENT]" />
  <xsl:number format="1." />
</xsl:template>

Apply templates in 'number' mode to get an NELEMENT element's number.
To get the output you want, for example, use:

<xsl:template match="NELEMENT">
  <xsl:apply-templates select="." mode="number" />
  <xsl:value-of select="." />
</xsl:template>

Cheers,

Jeni

---
Jeni Tennison
http://www.jenitennison.com/


 XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list


Current Thread

PURCHASE STYLUS STUDIO ONLINE TODAY!

Purchasing Stylus Studio from our online shop is Easy, Secure and Value Priced!

Buy Stylus Studio Now

Download The World's Best XML IDE!

Accelerate XML development with our award-winning XML IDE - Download a free trial today!

Don't miss another message! Subscribe to this list today.
Email
First Name
Last Name
Company
Subscribe in XML format
RSS 2.0
Atom 0.3
Site Map | Privacy Policy | Terms of Use | Trademarks
Free Stylus Studio XML Training:
W3C Member
Stylus Studio® and DataDirect XQuery ™are products from DataDirect Technologies, is a registered trademark of Progress Software Corporation, in the U.S. and other countries. © 2004-2013 All Rights Reserved.