Creating a set in xsl

D

David Schwartz

I want to create the equivalent of a Smalltalk set collection, i.e., a
collection of values that are unique wrt each other -- no duplicates.

The structure is as follows:

<root>
<record>
<collection>
<item>
<item>
<item>
</collection>
</record>
<record>
<collection>
<item>
<item>
<item>
</collection>
</record>
</root>

I need a sorted, single listing of the all items without dupes.

Any help would be appreciated.

TIA,
David
 
M

Martin Honnen

David said:
I want to create the equivalent of a Smalltalk set collection, i.e., a
collection of values that are unique wrt each other -- no duplicates.

The structure is as follows:

<root>
<record>
<collection>
<item>
<item>
<item>
</collection>
</record>
<record>
<collection>
<item>
<item>
<item>
</collection>
</record>
</root>

I need a sorted, single listing of the all items without dupes.

Use Muenchian grouping with XSLT 1.0 e.g.
<xsl:stylesheet
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
version="1.0">

<xsl:key name="item"
match="item"
use="."/>

<xsl:template match="root">
<xsl:copy>
<xsl:apply-templates
select="record/collection/item[generate-id() =
generate-id(key('item', .)[1])]"
<xsl:sort select="."/>
</xsl:copy>
</xsl:template>

<xsl:template match="@* | node()">
<xsl:copy>
<xsl:apply-templates select="@* | node()"/>
</xsl:copy>
</xsl:template>

</xsl:stylesheet>

With XSLT 2.0 you can use xsl:for-each-group.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,755
Messages
2,569,536
Members
45,007
Latest member
obedient dusk

Latest Threads

Top