Subject: RE: XSL:Copy w/ Processing Optimization Suggestions
From: "Michael Kay" <mhk@xxxxxxxxx>
Date: Thu, 13 Mar 2003 17:18:12 -0000
|
> Here's what I'm currently doing:
> XSL:
> <?xml version="1.0"?>
> <xsl:stylesheet version="1.0" xmlns:xsl
> ="http://www.w3.org/1999/XSL/Transform">
> <xsl:output method="xml" />
>
> <xsl:template match="/">
> <xsl:apply-templates />
> </xsl:template>
>
> <xsl:template match="*|@*|processing-instruction()|text()">
> <!-- This seems to be the worst part. I'm doing string
> comarisons on the node name on every node in the tree.
> That's gotta be bad... -->
> <xsl:if test="not(name()='Part') or
> (contains(@DisplayValue,'BM5125') )">
> <xsl:copy>
> <xsl:apply-templates
> select="*|@*|processing-instruction()|text()">
> <xsl:sort order="ascending" select="@DisplayValue" />
> </xsl:apply-templates>
> </xsl:copy>
> </xsl:if>
> </xsl:template>
Firstly, you can use copy-of rather than apply-templates to process the
attributes.
You can use a direct nametest rather than a string comparison on the
name, and if your data is to be believed, you can use starts-with rather
than contains. You can also use template rules rather than xsl:if to
distinguish the two kinds of processing to be performed
<xsl:template match="*">
<xsl:copy-of select="@*"/>
<xsl:copy>
<xsl:apply-templates/>
</xsl:copy>
</xsl:template>
<xsl:template match="Part[not(starts-with(@DisplayValue,
'BM5125'))]"/>
Michael Kay
Software AG
home: Michael.H.Kay@xxxxxxxxxxxx
work: Michael.Kay@xxxxxxxxxxxxxx
XSL-List info and archive: http://www.mulberrytech.com/xsl/xsl-list
|