This is the mail archive of the
xsl-list@mulberrytech.com
mailing list .
RE: More efficient way than following-sibling?
- From: "Michael Kay" <michael dot h dot kay at ntlworld dot com>
- To: <xsl-list at lists dot mulberrytech dot com>
- Date: Thu, 21 Mar 2002 08:53:43 -0000
- Subject: RE: [xsl] More efficient way than following-sibling?
- Reply-to: xsl-list at lists dot mulberrytech dot com
> I am trying to find a more efficient way to determine if a node has
> siblings, and then access the next sibling.
>
> Currently, I am running the following XSLT code:
>
> <xsl:if test="$TheNode/following-sibling::node()">
> <xsl:call-template name="GenericTemplate">
> <xsl:with-param name="TheNode"
> select="$TheNode/following-sibling::*[1]"/>
> </xsl:call-template>
> </xsl:if>
>
> However, this is very expensive, when it comes to large XML documents.
>
I think in Saxon the above would be very efficient indeed. Do you have
evidence that it is inefficient on your chosen processor, or are you just
guessing?
My only quibble is that you are mixing following-sibling::node() and
following-sibling::* - you should almost certainly use the same test in both
cases.
You might get a (very small) speed-up by using a variable:
<xsl:variable name="next" select="$TheNode/following-sibling::*[1]"/>
<xsl:if test="$next">
<xsl:call-template name="GenericTemplate">
<xsl:with-param name="TheNode" select="$next"/>
</xsl:call-template>
</xsl:if>
or you might be able to turn your named template into a template rule with a
mode, so the whole thing then simplifies to:
<xsl:apply-templates select="$TheNode/following-sibling::*[1]"
mode="generic"/>
Michael Kay
Software AG
home: Michael.H.Kay@ntlworld.com
work: Michael.Kay@softwareag.com
XSL-List info and archive: http://www.mulberrytech.com/xsl/xsl-list