|
[XSL-LIST Mailing List Archive Home] [By Thread] [By Date] [Recent Entries] [Reply To This Message] n squared matching problem
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
|
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








