xsl-list
[Top] [All Lists]

RE: Optimization using keys

2005-02-16 12:47:59
Anything that processes each Menu element by counting how many preceding
Menu elements there are is going to be slow, in fact it's going to vary as
the square of the input document size.

If your requirement is:
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.

then what you should do is first identify the node at the Nth position, and
then when you process each node, test whether it is that one. 

The node at the n'th position is (//Menu)[$pos]

You can test whether node $A is the same node as $B in XPath 2.0 using ($A
is $B). In 1.0 you can use generate-id($A)=generate-id($B), or
count($A|$B)=1.

Michael Kay
http://www.saxonica.com/



-----Original Message-----
From: António Mota [mailto:amsmota(_at_)gmail(_dot_)com] 
Sent: 16 February 2005 19:40
To: xsl-list(_at_)lists(_dot_)mulberrytech(_dot_)com
Subject: Re: [xsl] Optimization using keys

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.

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





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



<Prev in Thread] Current Thread [Next in Thread>