[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: "G. Ken Holman" <gkholman@xxxxxxxxxxxxxxxxxxxx>
Date: Mon, 16 Sep 2002 17:30:04 +0200
xpath get value of element
At 2002-09-16 16:15 +0200, Lars Geldner wrote:
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.

That is because your data is not structured the way you want it numbered, so you cannot use <xsl:number> ... this isn't a fault of <xsl:number>. <xsl:number> is used to reflect the structure of a document and your elements are not structured hierarchically as you want them numbered.


You will have to manually count the constructs given the structure that you have, as in the following working example:

T:\ftemp>type lars.xml lars.xsl

lars.xml


<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>

lars.xsl


<?xml version="1.0" encoding="iso-8859-1"?> <xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0">

<xsl:template match="NELEMENT">
  <xsl:for-each select="ancestor::NUMMERIERUNG">
    <xsl:if test="position() > 1">
      <xsl:value-of select="count(preceding-sibling::NELEMENT)"/>
      <xsl:text>.</xsl:text>
    </xsl:if>
  </xsl:for-each>
  <xsl:value-of select="count(preceding-sibling::NELEMENT)+1"/>
  <xsl:text> </xsl:text>
  <xsl:value-of select="."/>
</xsl:template>

</xsl:stylesheet>

T:\ftemp>xt lars.xml lars.xsl
<?xml version="1.0" encoding="utf-8"?>

   1 text1
   2 text2

    2.1 text21
    2.2 text22

3 text3

T:\ftemp>


If you really wanted to use <xsl:number> then you will have to nest the structure of your input as follows:


T:\ftemp>type lars2.xml lars2.xsl

lars2.xml


<NUMMERIERUNG> <!--1.--><NELEMENT>text1</NELEMENT> <!--2.--><NELEMENT>text2 <NUMMERIERUNG> <!--2.1--><NELEMENT>text21</NELEMENT> <!--2.2--><NELEMENT>text22</NELEMENT> </NUMMERIERUNG> </NELEMENT> <!--3.--><NELEMENT>text3</NELEMENT> </NUMMERIERUNG>

lars2.xsl


<?xml version="1.0" encoding="iso-8859-1"?> <xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0">

<xsl:template match="NELEMENT">
  <xsl:number level="multiple"/>
  <xsl:text> </xsl:text>
  <xsl:apply-templates/>
</xsl:template>

</xsl:stylesheet>

T:\ftemp>xt lars2.xml lars2.xsl
<?xml version="1.0" encoding="utf-8"?>

   1 text1
   2 text2

    2.1 text21
    2.2 text22


3 text3


T:\ftemp>

Note how I placed the 2.1 and 2.2 *inside* the 2. NELEMENT so that the structure of the document reflects the numbering that you want ... *then* I can use <xsl:number> to get the numbering of the hierarchy.

I hope this helps.

........................ Ken

--
Upcoming hands-on in-depth    Europe:         Sep 18-Sep 20,2002
XSLT/XPath and XSL-FO         North America:  Sep 30-Oct  4,2002

G. Ken Holman               mailto:gkholman@xxxxxxxxxxxxxxxxxxxx
Crane Softwrights Ltd.        http://www.CraneSoftwrights.com/s/
Box 266, Kars, Ontario CANADA K0A-2E0  +1(613)489-0999 (F:-0995)
ISBN 0-13-065196-6                     Definitive XSLT and XPath
ISBN 0-13-140374-5                             Definitive XSL-FO
ISBN 1-894049-08-X Practical Transformation Using XSLT and XPath
ISBN 1-894049-10-1             Practical Formatting Using XSL-FO
Next public training: 2002-09-18,19,30,10-03,12-08,2003-03-04,07


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.