xslt: select and filter double elements

Discussion in 'XML' started by thijs.kupers@gmail.com, Dec 8, 2004.

  1. Guest

    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
    , Dec 8, 2004
    #1
    1. Advertising

  2. Joris Gillis Guest

    On 8 Dec 2004 09:53:37 -0800, <> wrote:

    > 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,



    --
    Joris Gillis (http://www.ticalc.org/cgi-bin/acct-view.cgi?userid=38041)
    Ceterum censeo XML omnibus esse utendum
    Joris Gillis, Dec 8, 2004
    #2
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Edwin G. Castro
    Replies:
    3
    Views:
    3,672
    Edwin G. Castro
    Sep 17, 2004
  2. Sydex
    Replies:
    12
    Views:
    6,483
    Victor Bazarov
    Feb 17, 2005
  3. Gerald Aichholzer
    Replies:
    2
    Views:
    2,497
    Gerald Aichholzer
    Jun 27, 2006
  4. zax75
    Replies:
    1
    Views:
    1,095
  5. palmiere
    Replies:
    1
    Views:
    396
    Erwin Moller
    Feb 9, 2004
Loading...

Share This Page