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

RE: Problem with selecting UNIQUE attribute

Subject: RE: Problem with selecting UNIQUE attribute
From: "Kevin Read" <kevin@xxxxxxxxxxxxxxxx>
Date: Sun, 17 Jun 2001 20:30:47 +0930
xsl for each unique attribute
Dimitre

many thanks, it worked like a charm - I owe you a beer!!  Next time you're
in Australia.......

I'll take a look at Jenni's site and work through the Muenchian method.  I
have a feeling that the xml packets that will be passing through are likely
to get very large.  So this will be a good pre-emptive step to take now.

Once again, thanks

Kevin


-----Original Message-----
From: Dimitre Novatchev [mailto:dnovatchev@xxxxxxxxx]
Sent: Sunday, 17 June 2001 8:23 PM
To: kevin@xxxxxxxxxxxxxxxx
Cc: xsl-list@xxxxxxxxxxxxxxxxxxxxxx
Subject: Re: Problem with selecting UNIQUE attribute


Kevin Read wrote:
>
> It seems that no matter what combination of select expressions I use on
the
> build-dirlist I am unable to select on the unique values. :-(

[snip]
>
> <xsl:template name="build-dirlist">
>  <xsl:param name="LVL"/>
>   <xsl:for-each select="//dir[@level=$LVL and
not(preceding::parameter[@name
> = @name])]">
>    <xsl:sort select="@name" order="ascending" />
>     <option>
>      <xsl:value-of select="@name"/>
>     </option>
>   </xsl:for-each>
> </xsl:template>


Hi Kevin,

The problem is in the following two lines of your code:
>   <xsl:for-each select="//dir[@level=$LVL and
not(preceding::parameter[@name
> = @name])]">

What you want is to get all "dir" elements on a level, such that their
"name"
attribute is not equal to the "name" attribute of any of the preceding
***dir***
elements.

This can be specified as:

//dir[@level=$LVL and not(@name = preceding::dir/@name)]


After this correction the template will be working correctly. Its code will
be:

<xsl:template name="build-dirlist">
 <xsl:param name="LVL"/>
  <xsl:for-each select="//dir[@level=$LVL and not(@name =
preceding::dir/@name)]">
   <xsl:sort select="@name" order="ascending" />
    <option>
     <xsl:value-of select="@name"/>
    </option>
  </xsl:for-each>



Cheers,
Dimitre Novatchev.
P.S. It is usually recommended to optimise expressions like "//dir" and also
to use
the Muenchian method for grouping, which uses keys and can be much more
efficient
than what you're using -- comparing every node with all preceding
identically typed
nodes -- this has complexity of O(N*N), where N is the number of all nodes
of this
same type in the xml source document.

__________________________________________________
Do You Yahoo!?
Spot the hottest trends in music, movies, and more.
http://buzz.yahoo.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.