Search

Hi.

Let's say I have an XML like this:

<entries>
    <entry>
        <email handle="e1-site-com">e1@site.com</email>
    </entry>
    <entry>
        <email handle="e2-site-com">e2@site.com</email>
    </entry>
    <entry>
        <email handle="e5-site-com">e5@site.com</email>
    </entry>
    <entry>
        <email handle="e2-site-com">e2@site.com</email>
    </entry>
    <entry>
        <email handle="e4-site-com">e4@site.com</email>
    </entry>
    <entry>
        <email handle="e5-site-com">e5@site.com</email>
    </entry>
    <entry>
        <email handle="e2-site-com">e2@site.com</email>
    </entry>
</entries>

I need to list all emails without duplicates like this:

<li>e1@site.com</li>
<li>e2@site.com</li>
<li>e5@site.com</li>
<li>e4@site.com</li>

How can I filter out the duplicates?

Thank you.

You might use keys and the generate-id() function, as described in this article. In the comments on this page there is also another interesting approach, writing the desired values to a variable:

<xsl:variable name="unique-list" select="//email[not(. = following::email)]" />

I haven't tested it, but it should work. Maybe some guru knows which method is faster?

Try something like

<xsl:variable name="unique-list" 
    select="//email[not(.=following::email)]" />   
<xsl:for-each select="$unique-list">
    <xsl:value-of select="." />
 </xsl:for-each>

I haven't tried this though.

//EDIT: michael-e was faster than me I guess :)

Thanks all for help.

@nick

Hmm, my mistake. I searched the forum only for xslt duplicates :)

Create an account or sign in to comment.

Symphony • Open Source XSLT CMS

Server Requirements

  • PHP 5.3-5.6 or 7.0-7.3
  • PHP's LibXML module, with the XSLT extension enabled (--with-xsl)
  • MySQL 5.5 or above
  • An Apache or Litespeed webserver
  • Apache's mod_rewrite module or equivalent

Compatible Hosts

Sign in

Login details