Re: [xsl] sequence numbering.

Subject: Re: [xsl] sequence numbering.
From: Jeni Tennison <jeni@xxxxxxxxxxxxxxxx>
Date: Tue, 2 Apr 2002 19:14:07 +0100
Hi William,

> Here i was adviced by Jenni to sort the colors and store it in
> Variable.. and then use the <xalan:nodeset > for processing. in
> doing so when i try to use the <xsl:key>, it does not seem to give
> me the desired result.

When you use a key with the key() function, the processor only
searches the document that the current node is in. In your code, the
current node when you use the key is a product element from the new
node tree that you create. This new node tree doesn't contain any
colorlist element, so the key doesn't find any color elements that are
children of a colorlist element, so it doesn't return anything.

The simplest solution, I think, is to copy the colorlist into the new
$sorted-color node tree that you create at the same time as you create
the sorted list of products. So create $sorted-color with:

  <xsl:variable name="sorted-color">
    <xsl:for-each select="products/product">
      <xsl:sort select="color" data-type="text" order="descending"/>
      <xsl:copy-of select="."/>
    </xsl:for-each>
    <xsl:copy-of select="products/colorlist" />
  </xsl:variable>

and leave the rest of the code as it is.

The other option would be to store the root node of the original
document in a variable, then use an xsl:for-each to swap back out to
that document, and use the key within that xsl:for-each, but that's
more complicated.
  
Cheers,

Jeni

---
Jeni Tennison
http://www.jenitennison.com/


 XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list


Current Thread