Re: [xsl] Testing if something is not there

Subject: Re: [xsl] Testing if something is not there
From: Jeni Tennison <jeni@xxxxxxxxxxxxxxxx>
Date: Tue, 6 Nov 2001 14:12:24 +0000
Hi Jim,

> Thanks for tips! I was about half-way there. You use a few more
> variables than I was using. Are there speed advantages to using
> variables like $Test rather than using XPaths in template match or
> for-each constructs?

You can't use variables in template match patterns (supposedly to
prevent circular references).

I was mainly using variables to help make it clearer what was going on
in the code. However, using a variable stops an XSLT processor from
evaluating the same expression multiple times. Some XSLT processors
detect when the same expression is used several times and caches the
result of the expression (e.g. Saxon caches it if you use it three
times), but using a variable forces the expression to only be
evaluated once.

This is especially useful for expensive operations (e.g. for setting
the $Test variable) and not so important for cheap operations (e.g.
for setting the $TestName variable, although that variable's necessary
given the way the current node changes in the template). I usually use
a variable if I'm using the same location path more than once, unless
it's just accessing children or attributes.

> I do have a lot of Tests under each Site. Usually there are about
> 500. So the tip to use
> <xsl:key name="TestSites" match="Test"
>          use="concat(../../SiteName, '::', FullName)" />
> was VERY helpful. Without the above key, it was taking about 30
> seconds to process my XML file. With the above key, the processing
> time was cut to 4 seconds!

Excellent :)



Jeni Tennison

 XSL-List info and archive:

Current Thread