Subject: Re: [xsl] copy without duplicates From: "G. Ken Holman" <gkholman@xxxxxxxxxxxxxxxxxxxx> Date: Fri, 04 Mar 2005 21:11:53 -0500 |
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!
...
So the input document references two more documents, which should be processed and copied to the result, too.
...
Is it possible to do this with XSLT 1.0 in one stylesheet? I have already a two-stylesheet-solution, but one stylesheet would be nicer.
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: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
Current Thread |
---|
|
<- Previous | Index | Next -> |
---|---|---|
RE: [xsl] copy without duplicates, Michael Kay | Thread | Re: [xsl] copy without duplicates, Henning Waack |
RE: [xsl] A sequence of more than o, Michael Kay | Date | [xsl] How Do I Generate A Set-Diffe, Aron Bock |
Month |