|
[XSL-LIST Mailing List Archive Home] [By Thread] [By Date] [Recent Entries] [Reply To This Message] Re: copy without duplicates
At 2005-03-04 13:18 +0100, Henning Waack wrote:
I have the following problem. I have a XML-file which needs to be copied as it is, except, that each element must occur only once! As Mike mentioned, the variable-based grouping method can be used in XSLT 1.0 across multiple documents. I hope the example below helps. ......................... Ken T:\ftemp>type input.xml
<elements>
<a/>
<b/>
<link location="extern1.xml"/>
<c/>
<a/>
<link location="extern2.xml"/>
<b/>
<e/>
</elements>T:\ftemp>type extern1.xml
<elements>
<a/>
<f/>
</elements>T:\ftemp>type extern2.xml
<elements>
<g/>
<f/>
</elements>T:\ftemp>type henning.xsl
<?xml version="1.0" encoding="iso-8859-1"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
version="1.0"><xsl:output indent="yes"/> <xsl:template match="/">
<elements>
<!--collect all items to be sorted into a variable-->
<xsl:variable name="items"
select="/elements/*[not(self::link)] |
document(/elements/link/@location)/elements/*"/>
<!--loop through all, acting only on the first of each unique value-->
<xsl:for-each select="$items">
<xsl:if test="generate-id(.)=
generate-id($items[name(.)=name(current())])">
<xsl:copy-of select="."/>
</xsl:if>
</xsl:for-each>
</elements>
</xsl:template></xsl:stylesheet> T:\ftemp>saxon input.xml henning.xsl <?xml version="1.0" encoding="utf-8"?> <elements> <a/> <b/> <c/> <e/> <f/> <g/> </elements> T:\ftemp> -- World-wide on-site corporate, govt. & user group XML/XSL training. G. Ken Holman mailto:gkholman@xxxxxxxxxxxxxxxxxxxx Crane Softwrights Ltd. http://www.CraneSoftwrights.com/s/ Box 266, Kars, Ontario CANADA K0A-2E0 +1(613)489-0999 (F:-0995) Male Breast Cancer Awareness http://www.CraneSoftwrights.com/s/bc Legal business disclaimers: http://www.CraneSoftwrights.com/legal
|
PURCHASE STYLUS STUDIO ONLINE TODAY!Purchasing Stylus Studio from our online shop is Easy, Secure and Value Priced! Download The World's Best XML IDE!Accelerate XML development with our award-winning XML IDE - Download a free trial today! Subscribe in XML format
|

Cart








