Re: [xsl] How to find distinct nodes by value?

Subject: Re: [xsl] How to find distinct nodes by value?
From: "Mukul Gandhi" <gandhi.mukul@xxxxxxxxx>
Date: Wed, 11 Oct 2006 23:22:11 +0530
You can use XSLT 2.0 distinct-values function.

The sample stylesheet is below:

<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="2.0" xmlns:xsl="";>

<xsl:output method="xml" indent="yes" />

<xsl:template match="/">
   <xsl:for-each select="distinct-values(//myElement)">
     <myElement><xsl:value-of select="." /></myElement>


On 10/11/06, Victor Toni <xsl-list@xxxxxxxxx> wrote:
I would like to retrieve only the distinct nodes (by value) from a
"//myElement"-like  expression; <myElement> is either empty or contains
only text.

From this document


the result should be (the order doesn't matter)


In early XPath "Working Draft"s there seems to have been a function
called "distinct-nodes()" which should have done something similar but
it used the identity of the nodes.
This document still shows the function
and it was removed in

A replacement for this function found in

basically tells that

//myElement[empty(subsequence(//myElement, 1, position()-1) intersect .)]

should work to select distinct nodes (by identity).

But I haven't been able to find a solution for distinct nodes by value.

Any suggestions?

Mukul Gandhi

Current Thread