xsl-list
[Top] [All Lists]

Re: Removing Duplicates & Formatting

2003-12-10 07:44:26

you'd probbaly better off doing this in two passes, first get the paths
then elimiate duplicates.

this uses saxon node-set extension to do two passes in one stylesheet,
more or less every xslt engine (except mozilla) has a similar extension.

<a>
  <b><c/><c/><d/></b>
  <b><d/></b>
  <c><d><e/></d></c>
  <c><d><e/></d></c>
</a>




<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"; version="1.0"
xmlns:saxon="http://icl.com/saxon";
extension-element-prefixes="saxon"

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

<xsl:key name="ref" match="elem" use="ref"/>

<xsl:template match="/">
<xsl:variable name="x">
<xsl:for-each select="//*[not(*)]">
<p>
<xsl:for-each select="ancestor-or-self::*"
/<xsl:value-of select="name()"/>
</xsl:for-each>
</p>
</xsl:for-each>
</xsl:variable>

<xsl:copy-of select="saxon:node-set($x)/p[not(.=following-sibling::p)]"/>
</xsl:template>


</xsl:stylesheet>

$ saxon path.xml path.xsl
<?xml version="1.0" encoding="utf-8"?>
<p>/a/b/c</p>
<p>/a/b/d</p>
<p>/a/c/d/e</p>


-- 
http://www.dcarlisle.demon.co.uk/matthew

________________________________________________________________________
This e-mail has been scanned for all viruses by Star Internet. The
service is powered by MessageLabs. For more information on a proactive
anti-virus service working around the clock, around the globe, visit:
http://www.star.net.uk
________________________________________________________________________

 XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list