This is the mail archive of the
xsl-list@mulberrytech.com
mailing list .
Re: QUESTION about xsl:number
- To: xsl-list at mulberrytech dot com
- Subject: Re: QUESTION about xsl:number
- From: "G. Ken Holman" <gkholman at CraneSoftwrights dot com>
- Date: Fri, 05 May 2000 16:53:59 -0400
- Reply-To: xsl-list at mulberrytech dot com
At 00/05/04 13:21 -0700, Kelvin Zheng wrote:
>My question is how to number its child nodes as:
>
>
> XML
>
> 1. Definition
> 1.1 XML
> 1.2 XSL
>
> 2. Implementation
>
>I have tried <xsl:number level="multiple" format="1. " />, but the document
>looks like:
>
> XML
>
> 1. Definition
> 1. XML
> 2. XSL
>
> 2. Implementation
Correct ... because you haven't told it what needs to be counted ... as a
result it is only counting the current element.
The example below (not accommodating white space) illustrates how using a
union in the pattern gives the processor a list of things to count.
I hope this helps.
.......... Ken
T:\ftemp>type test2.xml
<document>
<section type="title" shownumber="no">
XML sample
</section>
<section type="index" shownumber="yes">
Definition
<definition>
XML
</definition>
<definition>
XSL
</definition>
</section>
<section type="index" shownumber="yes">
Implementation
</section>
</document>
T:\ftemp>type test2.xsl
<?xml version="1.0"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
version="1.0">
<xsl:output method="text"/>
<xsl:template match="/"> <!--root rule-->
<xsl:apply-templates select="//section"/>
</xsl:template>
<xsl:template match="section">
<xsl:if test="@shownumber='yes'">
<xsl:number count="section[@shownumber='yes']"/>
</xsl:if>
<xsl:apply-templates/>
</xsl:template>
<xsl:template match="definition">
<xsl:number count="section[@shownumber='yes']
|definition"
level="multiple" format="1."/>
<xsl:value-of select="."/>
</xsl:template>
</xsl:stylesheet>
T:\ftemp>xt test2.xml test2.xsl
XML sample
1
Definition
1.1.
XML
1.2.
XSL
2
Implementation
--
G. Ken Holman mailto:gkholman@CraneSoftwrights.com
Crane Softwrights Ltd. http://www.CraneSoftwrights.com/s/
Box 266, Kars, Ontario CANADA K0A-2E0 +1(613)489-0999 (Fax:-0995)
Web site: XSL/XML/DSSSL/SGML services, training, libraries, products.
Practical Transformation Using XSLT and XPath ISBN 1-894049-04-7
Next instructor-led training: 2000-05-11/12,2000-05-15,
- 2000-06-12,2000-06-13,2001-01-27
XSL-List info and archive: http://www.mulberrytech.com/xsl/xsl-list