This is the mail archive of the
xsl-list@mulberrytech.com
mailing list .
Re: More efficient way than following-sibling?
On Wednesday 20 March 2002 11:45, Michael Glick (B) wrote:
> 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.
You might try using the same test in the xsl:if as you use for the select in
the xsl:with-param. Perhaps the xsl:if is building a list of all of the
following-sibling::node()s, even though in order to do that test you would
only have to check that there is one following-sibling::node().
Also, I wonder why you test for node() in the xsl:if, and use * in the
xsl:with-param.
<xsl:if test="$TheNode/following-sibling::*[1]">
<xsl:call-template name="GenericTemplate">
<xsl:with-param name="TheNode" select="$TheNode/following-sibling::*[1]"/>
</xsl:call-template>
</xsl:if>
If your processor isn't smart enough to only find the first following-sibling
in the xsl:if, then the [1] will force it to do that. Probably this is
what's slowing you down in large documents.
Changing the node() to a * will also help in the future (or today?) with
processors that can re-use the result of the first XPath expression when it
finds a second that is exactly the same. I think that XSLTC is planning to
do this.
Are you sure that the problem is here? Other than the missing [1], it seems
like this would be a fairly innocent transformation. If can do some
profiling on the processor, it might help show where the problem is (or show
that this solves it).
--
Peter Davis
That's the true harbinger of spring, not crocuses or swallows
returning to Capistrano, but the sound of a bat on a ball.
-- Bill Veeck
XSL-List info and archive: http://www.mulberrytech.com/xsl/xsl-list