RE: bad programming for speedup?
In trying to reverse-engineer your code, it looks to me as if you are doing a classic "group-adjacent" problem, where a group of adjacent row elements are wrapped in a table element. In XSLT 2.0 the most efficient way to do this should be <xsl:for-each-group group-adjacent="boolean(self::row)">. In 1.0 the most efficient would probably be sibling-recursion, but that's quite hard work to code if you're not used to recursive programming. On the other hand there are solutions in 1.0 that are easier to code, but which are very inefficient if the number of siblings is large (typically O(n^2)). So we need to see whether your "good" code really was good or not! As for the question: > Is it allowed to discard the rules of good programming for speed-up desires? it is of course as old as the hills, and is not specific to XSLT. The answer is that only you know the requirements of the project well-enough to decide the trade-offs between performance, portability, and maintenance cost. But most experienced software engineers (I think) will tell you that when you do this, you usually get a short-term advantage that proves expensive in the long term. The key point I think is that it's usually not necessary. In the vast majority of cases there is a way of solving the performance problems that doesn't require you to write bad code. Michael Kay http://www.saxonica.com/ > -----Original Message----- > From: christoph.naber@xxxxxxxxxxxxxxxxxxx > [mailto:christoph.naber@xxxxxxxxxxxxxxxxxxx] > Sent: 24 July 2007 11:02 > To: xsl-list@xxxxxxxxxxxxxxxxxxxxxx > Subject: bad programming for speedup? > > 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. > > I'd be pleased to hear your opinion about a stylesheet I've written. > > The aim is to surround occurences of <row> - tags with a > <table> - tag. > I've done this with "good" XSL, what appears to be real slow, > and with a "bad" version, which inserts tags as <xsl:text>. > > The second version: > <xsl:template match="row" > > <xsl:if test="name(preceding-sibling::*) != 'row'"> > <xsl:text > disable-output-escaping="yes"><![CDATA[<table>]]></xsl:text> > </xsl:if> > <xsl:text> > </xsl:text> > <xsl:copy> > <xsl:copy-of select="@*" /> > <xsl:apply-templates select="*" /> > </xsl:copy> > > <xsl:if test="name(following-sibling::*) != 'row'"> > <xsl:text > disable-output-escaping="yes"><![CDATA[</table>]]></xsl:text> > </xsl:if> > </xsl:template> > > > This solution is much faster, but it makes use of bad XSL programming. > > What are you thinking, is it allowed to discard the rules of good > programming for speed-up desires? > > Christoph Naber > > > If you are not the intended addressee, please inform us > immediately that you have received this e-mail by mistake and > delete it. We thank you for your support.
PURCHASE STYLUS STUDIO ONLINE TODAY!
Purchasing Stylus Studio from our online shop is Easy, Secure and Value Priced!
Download The World's Best XML IDE!
Accelerate XML development with our award-winning XML IDE - Download a free trial today!
Subscribe in XML format