xsl-list
[Top] [All Lists]

RE: XSL:Copy w/ Processing Optimization Suggestions

2003-03-13 10:18:12
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(_dot_)H(_dot_)Kay(_at_)ntlworld(_dot_)com
work: Michael(_dot_)Kay(_at_)softwareag(_dot_)com 


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



<Prev in Thread] Current Thread [Next in Thread>