xsl-list
[Top] [All Lists]

[xsl] Antwort: RE: [xsl] bad programming for speedup?

2007-07-24 05:21:06
mike(_at_)saxonica(_dot_)com schrieb am 24.07.2007 12:29:21:

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. 

thats it!

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.

I think I found one way with your help/hint of recursive templates.

The code:
<xsl:stylesheet version="1.0" 
xmlns:xsl="http://www.w3.org/1999/XSL/Transform";>
        <xsl:output method="xml" indent="yes"/>
 
        <xsl:template match="/">
                <xsl:apply-templates />
        </xsl:template>
 
        <xsl:template match="*">
                <xsl:copy>
                        <xsl:copy-of select="@*" />
                        <xsl:apply-templates select="*" /> 
                </xsl:copy>
        </xsl:template>
 
        <xsl:template match="row[position() = 1 or 
preceding-sibling::*[name() != 'row' and position() = 1]]" >
                <table>
                        <xsl:apply-templates select="." mode="more2come"/>
                </table>
        </xsl:template>

        <xsl:template match="row" mode="more2come">
                <xsl:copy>
                        <xsl:copy-of select="@*" />
                        <xsl:apply-templates select="*" /> 
                </xsl:copy>
                <xsl:if test="following-sibling::*[name() = 'row' and 
position() = 1]">
                        <xsl:apply-templates 
select="following-sibling::row[position() = 1]" mode="more2come" />
                </xsl:if>
        </xsl:template>
 
        <xsl:template match="row" >
        </xsl:template>
 
</xsl:stylesheet>

It was much easier than the solution with <xsl:key>. But I learned much 
about XPath.

Thank you for helping me to find a way..

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.

--~------------------------------------------------------------------
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>
--~--