This is the mail archive of the xsl-list@mulberrytech.com mailing list .


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]

Re: Testing if something is not there


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 :)

Cheers,

Jeni

---
Jeni Tennison
http://www.jenitennison.com/


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


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]