[XSL-LIST Mailing List Archive Home] [By Thread] [By Date] [Recent Entries] [Reply To This Message]

Re: select distinct

Subject: Re: select distinct
From: Francis Norton <francis@xxxxxxxxxxx>
Date: Mon, 18 Dec 2000 13:37:05 +0000
xsl 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


Current Thread

PURCHASE STYLUS STUDIO ONLINE TODAY!

Purchasing Stylus Studio from our online shop is Easy, Secure and Value Priced!

Buy Stylus Studio Now

Download The World's Best XML IDE!

Accelerate XML development with our award-winning XML IDE - Download a free trial today!

Don't miss another message! Subscribe to this list today.
Email
First Name
Last Name
Company
Subscribe in XML format
RSS 2.0
Atom 0.3
Site Map | Privacy Policy | Terms of Use | Trademarks
Free Stylus Studio XML Training:
W3C Member
Stylus Studio® and DataDirect XQuery ™are products from DataDirect Technologies, is a registered trademark of Progress Software Corporation, in the U.S. and other countries. © 2004-2013 All Rights Reserved.