xsl-list
[Top] [All Lists]

RE: How to speed up parsing ??

2003-07-31 11:16:02
These are inherently different 
<xsl:value-of> 
The <xsl:value-of> element can be used to select the value of an XML element 
and add it to the output stream of the transformation.

while
<xsl:copy-of>
The xsl:copy-of element can be used to insert a result tree fragment into the 
result tree, without first converting it to a string as xsl:value-of does (see 
[7.6.1 Generating Text with xsl:value-of]). The required select attribute 
contains an expression. When the result of evaluating the expression is a 
result tree fragment, the complete fragment is copied into the result tree. 
When the result is a node-set, all the nodes in the set are copied in document 
order into the result tree; copying an element node copies the attribute nodes, 
namespace nodes and children of the element node as well as the element node 
itself; a root node is copied by copying its children. When the result is 
neither a node-set nor a result tree fragment, the result is converted to a 
string and then inserted into the result tree, as with xsl:value-of.

Hence these work as one only in very restricted cases.
Do Google searches for value-of and copy-of and copy-of and see the results.

Thanks,
Ashish


-----Original Message-----
From: owner-xsl-list(_at_)lists(_dot_)mulberrytech(_dot_)com
[mailto:owner-xsl-list(_at_)lists(_dot_)mulberrytech(_dot_)com]On Behalf Of 
Django
(Oznog) Blais
Sent: Thursday, July 31, 2003 12:30 PM
To: xsl-list(_at_)lists(_dot_)mulberrytech(_dot_)com
Subject: Re: [xsl] How to speed up parsing ??


Hi,

Very good job Ashish!

You said "<xsl:value-of>  in preference to <xsl:apply-templates>"

What's about <xsl:copy-of> instead of  <xsl:value-of> ?

Thanks,
Django

----- Original Message ----- 
From: "Tengshe, Ashish" <Tengshe(_dot_)Ashish(_at_)principal(_dot_)com>
To: <xsl-list(_at_)lists(_dot_)mulberrytech(_dot_)com>
Sent: Thursday, July 31, 2003 12:10 PM
Subject: RE: [xsl] How to speed up parsing ??


Hi,
Here is a thread that you might want to see
http://sources.redhat.com/ml/xsl-list/2001-02/msg01730.html click on
'Thread Index' to see all responses.
The general consensus from the Gurus seem to be that for-each is not
slower than apply-templates, just one needs to find out when it is
appropriate to use.
One post even quotes the Apache website as saying "for-each is faster
because there is no template matching involved". I think you may need to
look in other places to increase performance.

This may not be relevant to you but I thought I'd just post these
performance tips, you can see if any apply to you
These are from noted author Michael Kay and other sources

1. Avoid repeated use of "//item". This is very expensive. Use an Xpath
expression that's as close to the exact one (that can identify the wanted
nodes) as possible.
2. Don't evaluate the same node-set more than once, save it in a variable.
3. Avoid <xsl:number> if you can. For example, by using position()
function.
4. Use <xsl:key>, for example to solve grouping problems. There is an
example of this in this document.
5. Avoid complex patterns in template rules. Instead, use <xsl:choose>
within the rule.
6. Be careful when using the preceding[-sibling] or following[-sibling]
axes. This often
        indicates an algorithm with n-squared performance.
7. Don't sort the same node-set more than once. If necessary, save it as a
result tree fragment
       and access it using the node-set() extension function.
8. To output the text value of a simple #PCDATA element, use
<xsl:value-of>
        in preference to <xsl:apply-templates>.
More...
1. Keep the source documents small. If necessary split the document first.
2. Keep the XSLT processor (and Java VM) loaded in memory between runs
3. If you use the same stylesheet repeatedly, compile it first.
4. If you use the same source document repeatedly, keep it in memory.
5. If you perform the same transformation repeatedly, don't. Store the
result instead.
6. Keep the output document small. For example, if you're generating HTML,
use CSS.
7. Never validate the same source document more than once.
8. Split complex transformations into several stages.

More...
· Follow good performance engineering practice: record the time a
stylesheet takes before and after making each change, and change it back if
it doesn't improve
· Use small documents rather than large ones
· Don't assume that the processor makes a particular optimization
· Use variables for storing Xpath results, do not access same nodes again.
· Use temporary trees (result tree fragments in XSLT 1.0)
· A 10% improvement is considered industry benchmark to justify a
substantial change.

More...from the Apache Website
· Avoid using predicates in '*' patterns
· Avoid using id/key-patterns
· Avoid union expressions where possible
· Sort stored node-sets once
· Cache input documents

Lastly,
· Follow Design Patterns!

Also, probably not logical at all, but I read on one forum that if this
guy used  <xsl:apply-templates select="*"/> instead of
<xsl:apply-templates/> the performance increased drastically. Just something
to try.

Thanks,
Ashish



-----Original Message-----
From: owner-xsl-list(_at_)lists(_dot_)mulberrytech(_dot_)com
[mailto:owner-xsl-list(_at_)lists(_dot_)mulberrytech(_dot_)com]On Behalf Of 
Dipesh
Khakhkhar
Sent: Wednesday, July 30, 2003 6:16 PM
To: xsl-list(_at_)lists(_dot_)mulberrytech(_dot_)com
Subject: [xsl] How to speed up parsing ??


Hi,

I would like to know how can i speed up parsing xml file.
I am having huge xml file (approx 30-50 MB). I have written xsl to get
text
out it. I am getting it properly but it is taking lotta time.

I have used "apply templates " frequently to go to the respective node. As
per
my knowledge "for-each" and "apply-templates" does the same thing and i
assume
internally they must be working alike. WILL THERE BE SPEED ENHANCEMENT IF
I
USE FOR-EACH INSTEAD OF USING APPLY_TEMPLATES.

Or if you do programatically the same thing will i be achieving speed
enhancement ??

My current xsl is drastically slow. Pls give me some hints and suggestion
to
enhance performance of my xsl processing.

Eagerly waiting for reply.

Regards,
Dipesh


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


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




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


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



<Prev in Thread] Current Thread [Next in Thread>