dcsimg

Is it possible to use XSLT to remove elements with duplicate values from an XML file?

Nicolás Lichtmaier

XSLT does not currently provide a direct way of extracting unique nodes from a nodeset but that feature can be emulated. The trick would be to ask at each node if there has been another one. This would work:

<xsl:template match="@*|node()">
  <xsl:if test="not(node()) or not(preceding-sibling::node()[.=string(current())])">
    <xsl:copy>
      <xsl:apply-templates select="@*|node()"/>
    </xsl:copy>
  </xsl:if>
</xsl:template>