This is the mail archive of the
xsl-list@mulberrytech.com
mailing list .
Re: position of parent
- To: Xavier Defrang <xavier at perceval dot net>
- Subject: Re: [xsl] position of parent
- From: Jeni Tennison <mail at jenitennison dot com>
- Date: Mon, 26 Feb 2001 11:45:20 +0000
- CC: "Mulburrytech's XSL Mailing List" <xsl-list at lists dot mulberrytech dot com>
- Organization: Jeni Tennison Consulting Ltd
- References: <Pine.LNX.4.21.0102261211110.11741-100000@elara.perceval.be>
- Reply-To: xsl-list at lists dot mulberrytech dot com
Hi Xavier,
> I've got an XML document with <chapter> elements containing
> <section> elements. I'm currently writing an XSL that
> transforms such XML documents into XHTML. I want my sheet
> to automatically number chapters and sections. For this
> purpose, i use the <xsl:value-of select="position()"/> in my
> template that match the "chapter" element.
>
> Now i'd like to have the section numbered as follow
> "ChapterNumber.SectionNumber"... so the question is how do
> I get the ChapterNumber when i'm processing a section element?
> In other words, I'd like to get the position() of the parent
> of a given node...
This sounds like a perfect opportunity for xsl:number. Try:
<xsl:number level="multiple"
count="chapter | section"
format="1.1" />
If that's not what you're after, then you can always calculate the
position of an element relative to its siblings by counting how many
previous siblings there are and adding one:
count(preceding-sibling::*) + 1
So you could do your numbering with:
concat(count(../preceding-sibling::*) + 1, '.'
count(preceding-sibling::*) + 1)
But I think you'll find xsl:number *a lot* easier.
I hope that helps,
Jeni
---
Jeni Tennison
http://www.jenitennison.com/
XSL-List info and archive: http://www.mulberrytech.com/xsl/xsl-list