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

Re: Finding Unique Nodes

Subject: Re: Finding Unique Nodes
From: Peter Davis <pdavis152@xxxxxxxxx>
Date: Tue, 2 Apr 2002 00:12:01 -0800
xsl transform unique
On Monday 01 April 2002 23:45, Ivan Pedruzzi wrote:
> > -----Original Message-----
> > From: owner-xsl-list@xxxxxxxxxxxxxxxxxxxxxx
> > [mailto:owner-xsl-list@xxxxxxxxxxxxxxxxxxxxxx] On Behalf Of
> > Peter Davis
> > Sent: Tuesday, April 02, 2002 1:25 AM
> > To: xsl-list@xxxxxxxxxxxxxxxxxxxxxx
> > Subject: Re:  Finding Unique Nodes
> >
> > On Monday 01 April 2002 21:04, Ivan Pedruzzi wrote:
> > > <?xml version="1.0" encoding="UTF-8"?>
> > > <xsl:stylesheet version="1.0"
> > > xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
> > > <xsl:output method="xml"/>
> > > ? <xsl:template match="/">
> > > ? ? <list>
> > > ? ? <xsl:for-each select="list/item">
> > > ? ? <xsl:sort select="list/item"/>
> >
> > This sort requires that "/list/item/list/item" exists, "list/item" is
> > relative to the "list/item" that was selected in the
> > for-each.  To do what I
> > think you are trying to do, you want:
> >
> > <xsl:sort select="."/>
> >
> > > ????????? <xsl:if test="not(following-sibling::item = .)">
>
> Right.
>
> > The test for following-sibling::item is applied on the source
> > document, *not*
> > the document after it has been sorted.  So the sorting will
> > not affect
> > anything.  Also, this is the same as:
> >
> > not(./following-sibling::item = .)
> >
> > which is always true, because a node is never a
> > following-sibling of itself.
> > Therefore, the next line (<item><xsl:value-of
> > select="."/></item>) will
> > always be executed.
>
> This is interesting because I run the script with
> MSXML3/MSXML4/XalanJ/Stylus and all of them print unique values
> If you run this stylesheet you can see yourself

You are absolutely right, I was wrong.  Sorry everyone.

Somehow I was thinking that "following-sibling::item = ." was using the 
nodes' identities, but in reality of course it compares their string() 
values.  So this does work.  Sorry Ivan.

>
> <?xml version="1.0" encoding="UTF-8"?>
> <xsl:stylesheet version="1.0"
> xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
>   <xsl:output method="xml" indent="yes"/>
>   <xsl:template match="/">
>     <list>
>       <xsl:for-each select="list/item">
>         <test><xsl:value-of select="."/>=<xsl:value-of
> select="following-sibling::item"/>=<xsl:value-of
> select="not(following-sibling::item = .)"/></test>
> 	  </xsl:for-each>
>     </list>
>   </xsl:template>
> </xsl:stylesheet>
>
> I also run your stylesheet (below) using MSXML3/MSXML4/XalanJ/Stylus the
> result is always 0

Funny, I get "1" as the result (with "Orange").  But you are right that I did 
make a typo: I forgot the [1] in:

<xsl:value-of select="count(list/item[count(key('item', string(.))[1] | .) = 
1])"/>
                                                                  ^^^

If I make that change, then it works.

Sorry for the confusion, maybe this is a bad night for my brain to be working 
:-)

>
> <xsl:stylesheet version="1.0"
> xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
> <xsl:output method="text"/>
> <xsl:key name="item" match="item" use="string(.)"/>
> <xsl:template match="/">
>   <xsl:text>Unique items: </xsl:text>
>   <xsl:value-of select="count(list/item[count(key('item', string(.)) |
> .) = 1])"/>
> </xsl:template>
> </xsl:stylesheet>

-- 
Peter Davis
Cheer Up!  Things are getting worse at a slower rate.

 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-2007 All Rights Reserved.