Re: [xsl] Creating a tree variable and using it in later processing

Subject: Re: [xsl] Creating a tree variable and using it in later processing
From: Jeni Tennison <mail@xxxxxxxxxxxxxxxx>
Date: Fri, 20 Jul 2001 10:52:53 +0100
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" />

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.



Jeni Tennison

 XSL-List info and archive:

Current Thread