xsl-list
[Top] [All Lists]

Re: [xsl] bad programming for speedup?

2007-07-24 03:25:41
Hi Christoph,

I very much wonder what processor you are using, as the "bad" version (and it is indeed _bad_ ;) Can you tell a little about what environment you use: XSLT version (probably 1.0, see list guidelines if you are not sure how to find out), what processor and what processor version? Do you use it in a browser, if so which? Do you call it with PI or from a commandline or from something else?

see also my comments below,

Cheers,
Abel Braaksma

christoph(_dot_)naber(_at_)daimlerchrysler(_dot_)com wrote:
Hello everybody,

I'm new to this list, so let me introduce myself: My name is Christoph Naber. I come from Germany and work with XML/XSL for about 2 years now.

Welcome!

I'd be pleased to hear your opinion about a stylesheet I've written.

fasten your seatbelts ;)

The aim is to surround occurences of <row> - tags with a <table> - tag.

opinion 1: XSLT does not know anything about "tags", it works with nodes instead. After serialization, this may or may not translate into opening and closing tags.

I've done this with "good" XSL, what appears to be real slow

I'd love to see your "good" XSLT, I have yet to see something that is indeed slow

, and with a "bad" version, which inserts tags as <xsl:text>.

I completely concur with your idea of "bad". I would even say: "evil", as it is very dangerous to use d-o-e (short for disable output escaping) and to rely on it creating your < and > to create tags. You should let the serializer take care of that (which is why I am interested in your good version). The one reason I can think of why your "good" version might be slow is that it builds a very big internal tree (i.e., larger than the available memory), otherwise, the speed should not really be different (but then again, I have no idea what processor you are using so I cannot really tell).

The second version:
<xsl:template match="row" >
        <xsl:if test="name(preceding-sibling::*[1]) != 'row'">
<xsl:text disable-output-escaping="yes"><![CDATA[<table>]]></xsl:text>
        </xsl:if>
        <xsl:text>
</xsl:text>

You are testing for the first "row" to be there and you are writing your own tag??? I am very surprised it works even. D-O-E is not guaranteed to be supported, and even if it is supported, it is not guaranteed to create the output you seem to want.

        <xsl:copy>
                <xsl:copy-of select="@*" />
<xsl:apply-templates select="*" /> </xsl:copy> <xsl:if test="name(following-sibling::*[1]) != 'row'"> <xsl:text disable-output-escaping="yes"><![CDATA[</table>]]></xsl:text>
        </xsl:if>

ouch, this hurts my eyes ;) . Same here.... as above....


Again, I wonder why it works and even more, I wonder what your good code looks like. Here's a version that should work (many variants possible, this one is *very fast* if you do not need extra processing of children and it is supposed to be faster than your _bad_ version):

   <xsl:template match="/">
       <xsl:apply-templates select="your/path/to/row[1]" />
   </xsl:template>

   <xsl:template match="row">
       <table>
           <xsl:copy-of select=". | following-sibling::row" />
       </table>
   </xsl:template>


Cheers,

-- Abel Braaksma



--~------------------------------------------------------------------
XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list
To unsubscribe, go to: http://lists.mulberrytech.com/xsl-list/
or e-mail: <mailto:xsl-list-unsubscribe(_at_)lists(_dot_)mulberrytech(_dot_)com>
--~--