[
Lists Home |
Date Index |
Thread Index
]
Robert Hansson wrote:
> Hi!
>
> I have been taking over a project with thousands of lines of XSLT code
> that I need to change because of performance and readability problems.
> About the performance issues I
>
> need someone to tell me which of the following two examples is the
> best one for performance, what’s the differences and what to think about.
>
> Example 1:
>
> <xsl:element name="div"><xsl:attribute name="id"><xsl:value-of
> select="@id"/></xsl:attribute></xsl:element>
>
> Example 2:
>
> <div id="{@id}"></div>
>
The 2nd example is smaller and contains the same information. The
difference in performance is mainly in parsing the stylesheet and is
negligible.
If you have a set of attributes that is always the same, consider
<xsl:attribute-set> and <xsl:use-attribute-sets>.
If your output is HTML, factoring out some style information in a CSS
can be a good idea.
A more substantial possible performance leak is the use of // instead of
/ in XPath expressions: if sure to get the titles via "bib / book /
title", don't use "// title" for convenience as this forces the XSLT
processor to search each and every descendant element.
Other performance leaks related to this can be inherent in the structure
of your documents: e.g. the authors can use a tag <news> everywhere in
the document, which the stylesheet maintainer has to collect using a "//
news" that costs a whole traversal. If you can control the document
structure, gathering all <news> under a <newsitems> in the beginning is
much nicer. It does not really harm convenience, and with
"/newsitems/news" you can iterate over all <news> with only a fraction
of the cost. In general, if the structured of your documents keeps
important data together, the less time spent for processing the document
with the stylesheet.
If you use an XSLT processor in Java, and you are annoyed by the JVM
startup time, then maybe Java 1.5 Tiger can help you a bit. In any case,
transformations happening in a server component (e.g. a servlet) are not
affected by this - don't use a Java XSLT processor in a JVMs in a CGI
script. If you are profiling, then write a Java program with a loop to
count the time spent - this might be a good time to measure improvements
anyway.
hope this helps. cheers,
Burak
|