xslt: select and filter double elements

T

thijs.kupers

Hello

I've got a problem with xslt

I wan't to filter double items

for example with the following xml:

<item>
<evt name="a"/>
<subitem>
<evt name="a"/>
<evt name="b"/>
</subitem>
<evt name="c"/>
<subitem>
<subitem>
<evt name="b"/>
<evt name="c"/>
<evt name="d"/>
</subitem>
</subitem>
</item>


After the xsl-transform i want a list of all the differend 'evt' items
for example:

<some_root_element>
<evt name="a"/>
<evt name="b"/>
<evt name="c"/>
<evt name="d"/>
</some_root_element>
Anyone any idea how to do this with xslt?

Regards,

Thijs
 
J

Joris Gillis

Hello

I've got a problem with xslt

I wan't to filter double items

for example with the following xml:
After the xsl-transform i want a list of all the differend 'evt' items

<some_root_element>
<evt name="a"/>
<evt name="b"/>
<evt name="c"/>
<evt name="d"/>
</some_root_element>
Anyone any idea how to do this with xslt?

Hi,

One approach is using 'key' and 'generate-id' (below), but there are also extension functions available for this kind of problem.

<?xml version="1.0" encoding="utf-8"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">

<xsl:key name="evt" match="evt" use="@name"/>

<xsl:template match="item">
<some_root_element>
<xsl:for-each select="//evt[generate-id()=generate-id(key('evt',@name))]">
<xsl:copy-of select="."/>
</xsl:for-each>
</some_root_element>
</xsl:template>


</xsl:stylesheet>

regards,
 

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,999
Messages
2,570,243
Members
46,836
Latest member
login dogas

Latest Threads

Top