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

Re: Sorting + unique copy problem

Subject: Re: Sorting + unique copy problem
From: Jeni Tennison <jeni@xxxxxxxxxxxxxxxx>
Date: Thu, 8 Nov 2001 19:05:38 +0000
xsl sort select option
Hi Annalisa,

> I tried the code XSL below and the KeyWord values are present in un
> unique copy, but they aren't sorted.

You select every KeyWord element in the document, and then apply
templates to them. The template that matches is the following:

> <xsl:template match="KeyWord">
>     <xsl:for-each select="self::node()[generate-id(.)=generate-id(key('kw',
> .)[1])]">
>     <xsl:sort select="." />
>     <option value="{.}"><xsl:value-of select="."/></option>
>     </xsl:for-each>
> </xsl:template>

The xsl:for-each in the template says 'do the following to this node
if it's the first in the document with its value'. It can only ever
select one node (the KeyWord that you're currently processing) and
will often select no nodes. So there's no list to sort. The content of
this template is the equivalent of:

<xsl:template match="KeyWord">
  <xsl:if test="generate-id() = generate-id(key('kw', .)[1])">
    <option value="{.}"><xsl:value-of select="." /></option>
  </xsl:if>
</xsl:template>

One way you could fix it is to add an xsl:sort element to the
xsl:apply-templates instruction that's telling the processor to
process the KeyWord elements:

  <xsl:apply-templates select="//KeyWord">
    <xsl:sort select="." />
  </xsl:apply-templates>

That way it will process the KeyWord elements in alphabetical order.

In addition, you could make sure that the processor only ever tries to
process keywords that it's actually going to want to do something
with, by changing the xsl:apply-templates so that it selects the
KeyWord elements with a unique value:

  <xsl:apply-templates
      select="//KeyWord[generate-id() = generate-id(key('kw', .)[1])]">
    <xsl:sort select="." />
  </xsl:apply-templates>

and then changing the template as it doesn't need to do the test any
more:

<xsl:template match="KeyWord">
  <option value="{.}"><xsl:value-of select="." /></option>
</xsl:template>

I hope that helps,

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.