This is the mail archive of the
xsl-list@mulberrytech.com
mailing list .
Re: position accross multiple node sets?
- From: Jeni Tennison <jeni at jenitennison dot com>
- To: "Jeff Barrett" <JBarrett at sawyermedia dot com>
- Cc: xsl-list at lists dot mulberrytech dot com
- Date: Wed, 14 Aug 2002 10:37:54 +0100
- Subject: Re: [xsl] position accross multiple node sets?
- Organization: Jeni Tennison Consulting Ltd
- References: <378277A8F8AD4049AD8BC80D1F2B953930AC3F@sawmailsf1.sawyermedia.local>
- Reply-to: xsl-list at lists dot mulberrytech dot com
Hi Jeff,
> I've created two templates that use position() to number the items.
> One that processes the <book/> nodes into:
>
> 0. XSLT Programmers Reference
> 1. Beginning XSLT
>
> The other uses grouping on the car's <year/> node to output:
>
> 0. 2001
> 1. 1995
> 2. 1999
>
> Making the sum-total of this template's output:
>
> 0. XSLT Programmers Reference
> 1. Beginning XSLT
> 0. 2001
> 1. 1995
> 2. 1999
>
> What I actually need output is:
>
> 0. XSLT Programmers Reference
> 1. Beginning XSLT
> 2. 2001
> 3. 1995
> 4. 1999
You've got two options, I think. The first is to apply templates to
both the books and the cars at the same time, using something like:
<xsl:apply-templates
select="book |
car[generate-id() = generate-id(key('cars', year)[1])]" />
The current node list will then contain both the books and the unique
cars, which means that when you look at the position() of the nodes
when you process them, you'll get their position within this node list
rather than within the list of just-books or just-cars.
The other option is that when you're numbering the cars, you could use
the number you would be using plus the number of books, so you have
something like:
<xsl:value-of select="position() + count(../book) - 1" />
to give you the number within the template matching the car elements.
Cheers,
Jeni
---
Jeni Tennison
http://www.jenitennison.com/
XSL-List info and archive: http://www.mulberrytech.com/xsl/xsl-list