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

Re: Creating a tree variable and using it in later pro

Subject: Re: Creating a tree variable and using it in later processing
From: Jeni Tennison <mail@xxxxxxxxxxxxxxxx>
Date: Fri, 20 Jul 2001 10:52:53 +0100
xslt sort predefined order
Hi Alan,

> As you can see, the input XML document comes to me sorted by
> <number> and not by <name> (how the document is sorted is not in my
> control :-( ). However, I need to have my input sorted by <name> and
> I need to access the sorted elements according to a certain
> predefined order -for the sake of simplicity, lets say I need to
> access alternate names in the sorted list.

With your simplified example, you could iterate over the product
elements in sorted order, and then test the position() of the product
to find the odd ones:

  <xsl:for-each select="product">
    <xsl:sort select="name" />
    <xsl:if test="position() mod 2 = 1">
      Odd product: <xsl:value-of select="name" />
    </xsl:if>
  </xsl:for-each>

The main problem with this is that it's hard to find the next product
in the sorted list. Given that you don't want to use an intermediate
node set, unfortunately the appropriate solutions are likely to
heavily depend on what you *actually* want to do rather than a
simplification. For example, if you want to group the products by
name, then a grouping solution would be more appropriate, or perhaps
your predefined order means that you can pick out the relevant
products prior to sorting them by name. Please feel free to post more
details about what you're trying to achieve and we'll try to help.

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.