Home. 
.

transparent

transparent

transparent

Altova Mailing List Archives


Re: [xml-dev] XSLT Element Performence

From: Burak Emir <Burak.Emir@----.-->
To: Robert Hansson <Robert.Hansson@------.--->
Date: 7/7/2004 9:09:00 AM
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&#x2019;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


transparent
Print
Mail
Like It
Disclaimer
.

These Archives are provided for informational purposes only and have been generated directly from the Altova mailing list archive system and are comprised of the lists set forth on www.altova.com/list/index.html. Therefore, Altova does not warrant or guarantee the accuracy, reliability, completeness, usefulness, non-infringement of intellectual property rights, or quality of any content on the Altova Mailing List Archive(s), regardless of who originates that content. You expressly understand and agree that you bear all risks associated with using or relying on that content. Altova will not be liable or responsible in any way for any content posted including, but not limited to, any errors or omissions in content, or for any losses or damage of any kind incurred as a result of the use of or reliance on any content. This disclaimer and limitation on liability is in addition to the disclaimers and limitations contained in the Website Terms of Use and elsewhere on the site.

.
.

transparent

transparent