This is the mail archive of the xsl-list@mulberrytech.com mailing list .


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: position accross multiple node sets?


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


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]