Re: [xsl] Optimizing XSLT iteration

Subject: Re: [xsl] Optimizing XSLT iteration
From: Abel Braaksma <>
Date: Mon, 08 Oct 2007 01:11:15 +0200
Hi Sujata,

See my comments below,

Sujata Gohad wrote:
In order to convert it to SVG format:

<?xml version=' 1.0' encoding='UTF-8'?>
<?xml-stylesheet href="hvm_to_svg.css" type="text/css"? >

Does this actually work? Are you calling an XSLT stylesheet as being type "text/css" and you call it ***.css? Your processor (which one are you using?) seems quite forgiving (or maybe I am missing something ;)

            <xsl:for-each select="component">
                <xsl:for-each select="trace">
                    <path >
                        <xsl:attribute name="class"> trace</xsl:attribute >
                        <xsl:attribute name="d">
                            <xsl:for-each select="locus[position()=1]">

This nested for-each is probably easier written and easier maintainable when you write it as apply-template/template matching pairs. This way you make use of the features of XSLT and let it choose the best execution path, instead of telling the processor what you think is best.

XSLT profiler shows that 80% of the time is spent in enumerating the
"locus" elements?

Is there a way to faster iteration of the "locus" elements?

That sounds about right. In the source snippet you showed, just about 95% of all your lines are about "locus" elements, no? So, to be fair, the processing of those elements should take about 95%, if the ratio would apply. Perhaps your code is even quicker than the apply-template approach? But I wouldn't bet on it. But even if the code runs quicker, it would still be 80% or something that is spend on the locus elements.

-- Abel Braaksma

Current Thread