[XSL-LIST Mailing List Archive Home] [By Thread] [By Date]

Re: [xsl] Optimization using keys


Subject: Re: [xsl] Optimization using keys
From: António Mota <amsmota@xxxxxxxxx>
Date: Wed, 16 Feb 2005 19:39:39 +0000

I'm also trying to optimize this template

(indentity template)

       <xsl:template match="Menu">
                <xsl:choose>
                        <xsl:when
test="count(./ancestor-or-self::Menu)+count(./preceding::Menu)=number($pos)">
                                <xsl:variable name="pai" select="Menu_K"/>
                                <xsl:copy>
                                        <xsl:apply-templates
select="@*|node()[not(name()='MenuTipo' or name()='Filhos' )]"
mode="menu"/>
                                        <MenuTipo>EXP</MenuTipo>
                                        <Filhos>
                                                <xsl:for-each
select="Filhos/Menu">
                                                        <xsl:variable
name="xmldoc" select="document(concat($xmluri,'?Menu_K=',Menu_K,'&amp;Pai_K=',$pai))"/>
                                                        <xsl:variable
name="filhos" select="Filhos"/>
                                                        <xsl:variable
name="orelhas" select="Orelhas"/>
                                                       
<xsl:apply-templates select="$xmldoc/Menus/Menu" mode="menu">
                                                               
<xsl:with-param name="filhos" select="$filhos"/>
                                                               
<xsl:with-param name="orelhas" select="$orelhas"/>
                                                        </xsl:apply-templates>
                                                </xsl:for-each>
                                        </Filhos>
                                </xsl:copy>
                        </xsl:when>
                        <xsl:otherwise>
                                <xsl:copy>
                                        <xsl:apply-templates select="*"/>
                                </xsl:copy>
                        </xsl:otherwise>
                </xsl:choose>
        </xsl:template>

      <xsl:template match="Menu" mode="menu">
                <xsl:param name="filhos"/>
                <xsl:param name="orelhas"/>
                <xsl:copy>
                        <xsl:apply-templates mode="menu"/>
                        <xsl:if test="$filhos">
                                <xsl:copy-of select="$filhos"/>
                        </xsl:if>
                        <xsl:if test="$orelhas">
                                <xsl:copy-of select="$orelhas"/>
                        </xsl:if>
                </xsl:copy>
        </xsl:template>

but it is too slow and i don't know why. I thought it was the document
($xmluri is pointing to a ASP that returns a chunk of XML), but i've
tested with a small xml input tree and it's fast enough, so it seems
the problem is with the XML size. However i don't want to do much
things with it.

I'll fraze it (poor) english. Given a XML with nested Menu structures,
i want to copy all the nodes to the output tree *except* the one that
corresponds to the $pos position, wich i want to replace with the
result from document.

For each of the resulting document() nodes i want to append the
original <Filhos> and <Orelhas>.

So is there a optimized way to do this? Including the "simple copy" of
the nodes?


Thanks again.


Current Thread
Keywords
xml