This is the mail archive of the xsl-list@mulberrytech.com mailing list .


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

RE: More efficient way than following-sibling?


> 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


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]