|
[XSL-LIST Mailing List Archive Home] [By Thread] [By Date] [Recent Entries] [Reply To This Message] Re: problem with numbering
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
lars.xsl
<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 text223 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
lars2.xsl
<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 text223 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
|
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
|

Cart








