Re: [xsl] Effecient element "filtering" technique recommendations.

Subject: Re: [xsl] Effecient element "filtering" technique recommendations.
From: Trevor Nash <tcn@xxxxxxxxxxxxx>
Date: Wed, 09 Oct 2002 18:36:52 +0100
On Mon, 07 Oct 2002 08:15:41 -0600, Ed Knoll wrote:

>I'm looking for recommendations on ways in which we can only process the
>row columns which correspond to the other columns.  My current approach
>is adding approximately 40% onto our total XSL processing time.

The fastest ay to do this is via a SAX filter.  Then the XSLT doesn't
even see the nodes it doesn't need.  It is also realtively hard to
implement, so it depends how important performance is.

On your supplied code:

 >XML::
>
><Table>
>  <Columns>
>    <Column1/>
I would try <Column>Column1</Column> here.  
> ...

>
>XSL (fragments) w/ filtering::
>
><xsl:variable name="TableColumns" select="/Table/Columns/*" />

Then:
  <xsl:variable name="TableColumns" select="/Table/Columns/*/node()"/>
i.e. a list of text nodes with the element names required.

>
><xsl:template  select="/Table/Row">
You might as well say just "Row" here.  You are asking the processor
to check that the Row element is the child of a Table which is the
document element.  If this is always true there is no point checking
it.

>   <xsl:for-each select="*">
>      <xsl:variable name="MyName" select="name()" />
>      <xsl:if test="$TableColumns[name()=$MyName]" >
Replace this with an 'existential' test:
        <xsl:if test="name()=$TableColumns">
The RHS is a node list, so the = comes out true iff there is any node
in the list with a string value equal to the LHS.

Bar typos that should work: whether it turns out faster depends on too
many things for me to offer any guarantees!  For example a really
clever optimizer could reduce your expression to much the same thing.

Trevor Nash
--
Traditional training & distance learning,
Consultancy by email

Melvaig Software Engineering Limited
voice:     +44 (0) 1445 771 271 
email:     tcn@xxxxxxxxxxxxx

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


Current Thread