[XSL-LIST Mailing List Archive Home] [By Thread] [By Date] [Recent Entries] [Reply To This Message]

Re: position accross multiple node sets?

Subject: Re: position accross multiple node sets?
From: Jeni Tennison <jeni@xxxxxxxxxxxxxxxx>
Date: Wed, 14 Aug 2002 10:37:54 +0100
xslt position nod
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


Current Thread

PURCHASE STYLUS STUDIO ONLINE TODAY!

Purchasing Stylus Studio from our online shop is Easy, Secure and Value Priced!

Buy Stylus Studio Now

Download The World's Best XML IDE!

Accelerate XML development with our award-winning XML IDE - Download a free trial today!

Don't miss another message! Subscribe to this list today.
Email
First Name
Last Name
Company
Subscribe in XML format
RSS 2.0
Atom 0.3
Site Map | Privacy Policy | Terms of Use | Trademarks
Free Stylus Studio XML Training:
W3C Member
Stylus Studio® and DataDirect XQuery ™are products from DataDirect Technologies, is a registered trademark of Progress Software Corporation, in the U.S. and other countries. © 2004-2013 All Rights Reserved.