[xsl] XSL:Copy w/ Processing Optimization Suggestions

Subject: [xsl] XSL:Copy w/ Processing Optimization Suggestions
From: "DANA CORDES" <dcordes@xxxxxxxx>
Date: Wed, 12 Mar 2003 17:26:01 -0800
I need to convert an XML tree into a similiar tree, with some processing
performed on a subset of the data.  The full XML document is being rendered
via XSL into HTML for web display, and I have a section that contains what
will be converted into a data table.

I'm performing preprocess filtering and sorting functions through the XSL,
and I'm having memory consuption issues, so I'm trying to find an optimal
way of doing this.  I'm looking for any pointers on a better/faster/more
effecient way of doing this.

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>
</xsl:stylesheet>


Input XML:
<?xml version="1.0" encoding="utf-8"?>
<CatalogPartSpecsList>
  <Globals/>
  <Nav>
    <Catalog access="true" />
    <Login access="true" />
  </Nav>

  <Body>
    <Results>
      <Part DisplayValue="BM6015-04W-B50"/>
      <Part DisplayValue="BM5125-04W-B50"/>
      <Part DisplayValue="BM5125-04W-B40"/>
      <Part DisplayValue="BM5125-04W-B30"/>
      <Part DisplayValue="BM5115-04W-B50"/>
    </Results>
  </Body>
</CatalogPartSpecsList>

Desired XML Output:
<?xml version="1.0" encoding="utf-8"?>
<CatalogPartSpecsList>
  <Globals/>
  <Nav>
    <Catalog access="true" />
    <Login access="true" />
  </Nav>

  <Body>
    <Results>
      <Part DisplayValue="BM5125-04W-B30"/>
      <Part DisplayValue="BM5125-04W-B40"/>
      <Part DisplayValue="BM5125-04W-B50"/>
    </Results>
  </Body>
</CatalogPartSpecsList>

So, basically this all works, but I'm sure there is a much more effecient
way of doing it.  Could anyone give me some input on optimization?


Dana Cordes
Senior Programmer/Analyst
Information Technologies
New Hampshire Ball Bearing, Chatsworth
dcordes@xxxxxxxx


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


Current Thread