xsl-list
[Top] [All Lists]

Re: [xsl] bad programming for speedup?

2007-07-24 05:05:01
On 7/24/07, Michael Kay <mike(_at_)saxonica(_dot_)com> wrote:
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

Ahh I missed that bit.  To do sibling recursion in this case you need:

 <xsl:template match="@* | node()">
   <xsl:copy>
     <xsl:apply-templates select="@*"/>
     <xsl:apply-templates select="node()[1]"/>
   </xsl:copy>
   <xsl:apply-templates select="following-sibling::node()[1]"/>
 </xsl:template>

 <xsl:template match="row">
                <table>
                        <xsl:apply-templates select="." mode="copy"/>
                </table>
                <xsl:apply-templates 
select="following-sibling::*[not(self::row)][1]"/>
 </xsl:template>

 <xsl:template match="row" mode="copy">
                <xsl:copy-of select="."/>
                <xsl:apply-templates select="following-sibling::*[1][self::row]" 
mode="copy"/>
 </xsl:template>


cheers
andrew
--
http://andrewjwelch.com

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