Velocity Reviews

Velocity Reviews (http://www.velocityreviews.com/forums/index.php)
-   XML (http://www.velocityreviews.com/forums/f32-xml.html)
-   -   Creating a set in xsl (http://www.velocityreviews.com/forums/t597799-creating-a-set-in-xsl.html)

David Schwartz 03-11-2008 04:33 PM

Creating a set in xsl
 
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

Martin Honnen 03-11-2008 05:16 PM

Re: Creating a set in xsl
 
David Schwartz wrote:
> 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.

--

Martin Honnen
http://JavaScript.FAQTs.com/


All times are GMT. The time now is 10:43 AM.

Powered by vBulletin®. Copyright ©2000 - 2014, vBulletin Solutions, Inc.
SEO by vBSEO ©2010, Crawlability, Inc.