|
[XSL-LIST Mailing List Archive Home] [By Thread] [By Date] [Recent Entries] [Reply To This Message] Re: remove duplicates in each big entry
I use the Muenchenian method (see
http://www.jenitennison.com/xslt/grouping/index.html).
Since the text of <value> should be unique only within its parent element
<item>, I use the parent's
unique id as part of the index built by xsl:key.
<?xml version="1.0"?>
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:key name="uniqueWithinParent" match="/root/item/value"
use="concat(generate-id(parent::item),.)"/>
<xsl:template match="/|*">
<xsl:copy>
<xsl:apply-templates/>
</xsl:copy>
</xsl:template>
<xsl:template match="item">
<xsl:copy>
<xsl:apply-templates
select="value[count(.|key('uniqueWithinParent',concat(generate-id(current()),
.))[1])=1]"/>
</xsl:copy>
</xsl:template>
</xsl:stylesheet>
Instead of
<xsl:apply-templates
select="value[count(.|key('uniqueWithinParent',concat(generate-id(current()),
.))[1])=1]"/>
you can use
<xsl:apply-templates
select="value[generate-id()=generate-id(key('uniqueWithinParent',concat(gener
ate-id(current()),.))[1])]"/>
The first method uses the fact, that node sets don't hold duplicates and
therefore the union of a node and the first node returned
by the key() function is 1 if it is the same node.
The second method compares the unique id of <value> with the unique id of the
first node returned by the key() function.
Rudolf P. Weinmann
On Thu, 26 May 2005 21:08:32 +0000, you wrote:
>I don't find any example for my doubt about xsl, so i post my question.
>Supose that i have the next xml:
>
><root>
><item>
><value>foo</value>
><value>foo</value>
><value>bar</value>
></item>
><item>
><value>foo</value>
><value>cat</value>
><value>cat</value>
></item>
></root>
>
>and i would like to create a xml like this:
>
><root>
><item>
><value>foo</value>
><value>bar</value>
></item>
><item>
><value>foo</value>
><value>cat</value>
></item>
></root>
>
>As you can see, i want to remove all duplicates in each entry <item>, not in
>all document.
>The examples that i find, is about all document, not about my question.
>What lines i put in my xsl?
>
>
>Thanks,
>psc
>
>_________________________________________________________________
>Express yourself instantly with MSN Messenger! Download today it's FREE!
>http://messenger.msn.click-url.com/go/onm00200471ave/direct/01/
|
PURCHASE STYLUS STUDIO ONLINE TODAY!Purchasing Stylus Studio from our online shop is Easy, Secure and Value Priced! Download The World's Best XML IDE!Accelerate XML development with our award-winning XML IDE - Download a free trial today! Subscribe in XML format
|

Cart








