This is the mail archive of the xsl-list@mulberrytech.com mailing list .


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]

Re: select distinct




Richard Lander wrote:
> 
>  Hello,
> 
> I'm having some trouble with selecting distinct nodes (no duplicates). I am
> using the following algorithm at the moment, which works, but am wondering
> if there is something more elegant. generate-id() seems too heavy-handed.
> 
The following program works for de-duplicating xdr elements in an XML
Spy 3.5b2 conversion from XML Schema to XDR, it may be more or less
useful to you.

I used the "count()" rather than the "generate-id()" version of the
Muenchian method - it bought run-time (Saxon 6.0.1, input file 160k)
down from 8.5 seconds to 5.5 seconds - not to be sniffed at!

Francis.



<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform" 
xmlns:xdr="urn:schemas-microsoft-com:xml-data" 
xmlns:dt="urn:schemas-microsoft-com:datatypes">
	<xsl:output method="xml" version="1.0" encoding="UTF-8" indent="yes"/>
	<xsl:key name="eType" match="xdr:ElementType" use="@name"/>
	<!-- default is pass-through -->
	<xsl:template match="/ | * | @* | text() | comment()">
		<xsl:copy>
			<xsl:apply-templates select="* | @* | text() | comment()"/>
		</xsl:copy>
	</xsl:template>
	<!-- -->
	<!-- convert dt:type="int" to dt:type="i8" -->
	<xsl:template match="@dt:type[.='int']">
		<xsl:attribute name="dt:type">i8</xsl:attribute>
	</xsl:template>
	<!-- -->
	<!-- kill duplicate ElementTypes -->
	<xsl:template match="xdr:ElementType">
		<!-- use optimised Muenchian method to de-dupe ElementTypes -->
		<xsl:if test="count(. | (key('eType', @name)[1])) = 1">
			<xsl:copy>
				<xsl:apply-templates select="* | @* | text() | comment()"/>
			</xsl:copy>
		</xsl:if>
	</xsl:template>
</xsl:stylesheet>

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


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]