This is the mail archive of the
xsl-list@mulberrytech.com
mailing list .
RE: Finding Unique Nodes
- From: "Ivan Pedruzzi" <ivan at exln dot com>
- To: <xsl-list at lists dot mulberrytech dot com>
- Date: Tue, 2 Apr 2002 02:45:38 -0500
- Subject: RE: [xsl] Finding Unique Nodes
- Reply-to: xsl-list at lists dot mulberrytech dot com
> -----Original Message-----
> From: owner-xsl-list@lists.mulberrytech.com
> [mailto:owner-xsl-list@lists.mulberrytech.com] On Behalf Of
> Peter Davis
> Sent: Tuesday, April 02, 2002 1:25 AM
> To: xsl-list@lists.mulberrytech.com
> Subject: Re: [xsl] 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
<?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
<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>
XSL-List info and archive: http://www.mulberrytech.com/xsl/xsl-list