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

n squared matching problem

Subject: n squared matching problem
From: Alex Coll <alexcoll@xxxxxxxxx>
Date: Tue, 9 Aug 2005 13:46:50 -0700
alex coll
Hi, I'm having some performance issues with a stylesheet, and I
believe it could likely be improved but I'm inexperienced with XSL.
Here is a simplified version of the problem:

+++++++++++++++Sample xml:++++++++++++++++++++++++++++++=
<information>

<rawdatas>
	<rawdata>
		<key>A</key>
		<value>1</value>
	</rawdata>
	<rawdata>
		<key>A</key>
		<value>2</value>
	</rawdata>
	<rawdata>
		<key>B</key>
		<value>3</value>
	</rawdata>
	<rawdata>
		<key>C</key>
		<value>1</value>
	</rawdata>
	<rawdata>
		<key>B</key>
		<value>1</value>
	</rawdata>
	<rawdata>
		<key>D</key>
		<value>0</value>
	</rawdata>
	<rawdata>
		<key>E</key>
		<value>1</value>
	</rawdata>
</rawdatas>


<selectedkeys>
	<key>A</key>
	<key>B</key>
	<key>C</key>
</selectedkeys>

++++++++++++++XSL algorithm I'm using:+++++++++++++++++++++++

<xsl:template match="/information">
       <xsl:call-template name="selected-keys"/>
</xsl:template>



<xsl:template name="selected-keys">

	<xsl:for-each select="/information/selectedkeys/key">
			<xsl:call-template name="data">
				<xsl:with-param name="match" select="."/>
			</xsl:call-template>
	</xsl:for-each>

</xsl:template>
<xsl:template name="data">
	<xsl:param name="match"/>

	<xsl:for-each select="/information/rawdatas/rawdata">
			<xsl:if test="key=$match">
					Key <xsl:value-of select="$match"/> matched <xsl:value-of
select="value"/>
			</xsl:if>
	</xsl:for-each>

</xsl:template>


</information>

+++++++++++++++++++++++Outputs:+++++++++++++++++++++++++++++

Key A matched 1
Key A matched 2
Key B matched 3
Key B matched 1
Key C matched 1

I can envision a single-pass approach where the keys are hashed to a
table and the values are appended to a list on collisions, but I'm not
sure how that's accomplished in a declaritive language like XSLT.

Any help greatly appreciated.

Alex

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.