home contribute faq download

FunctX XSLT Functions

functx:distinct-deep

The XML nodes with distinct values, taking into account attributes and descendants

Google
Webxsltfunctions.com

Description

The functx:distinct-deep function compares nodes based on whether they are deep-equal, then returns only the first node with each distinct value. Two nodes are deep-equal if they have the same attributes with the same values, and all the same children, in the same order, that are themselves deep-equal.

Arguments and Return Type

NameTypeDescription
$nodes node()* the sequence of nodes to test
return value node()* the distinct sequence of nodes

XSLT Function Declaration

See XQuery definition.
<xsl:function name="functx:distinct-deep" as="node()*"
              xmlns:functx="http://www.functx.com">
  <xsl:param name="nodes" as="node()*"/>

  <xsl:sequence select="
    for $seq in (1 to count($nodes))
    return $nodes[$seq][not(functx:is-node-in-sequence-deep-equal(
                          .,$nodes[position() &lt; $seq]))]
 "/>

</xsl:function>

Examples

<xsl:variable name="in-xml" as="item()*">
<authors>
   <author>
      <fName>Kate</fName>
      <lName>Jones</lName>
   </author>
   <author>
      <fName>Kate</fName>
      <lName>Jones</lName>
   </author>
   <author>
      <fName>Kate</fName>
      <lName>Doe</lName>
   </author>
</authors>
</xsl:variable>
XPath ExampleResults
functx:distinct-deep($in-xml//author)
<author>
  <fName>Kate</fName>
  <lName>Jones</lName>
</author>
<author>
  <fName>Kate</fName>
  <lName>Doe</lName>
</author>
functx:distinct-deep($in-xml//lName)
<lName>Jones</lName>
<lName>Doe</lName>
functx:distinct-deep($in-xml//fName)
<fName>Kate</fName>

Depends On

functx:is-node-in-sequence-deep-equalWhether an XML node is in a sequence, based on contents and attributes

See Also

functx:is-node-in-sequence-deep-equalWhether an XML node is in a sequence, based on contents and attributes
functx:distinct-nodesThe distinct XML nodes in a sequence (by node identity)
fn:distinct-valuesThe distinct atomic values in a sequence

History

Published OnLast UpdatedContributor(s)
2006-06-272007-02-26Priscilla Walmsley, Datypic, pwalmsley@datypic.com, http://www.datypic.com
Datypic XSLT Services

Recommended Reading:

XQuery