RE: [xsl] Re: Benefits of xsl.sequence

Subject: RE: [xsl] Re: Benefits of xsl.sequence
From: "Michael Kay" <mike@xxxxxxxxxxxx>
Date: Tue, 30 Sep 2008 09:48:57 +0100
> Why is  <xsl:sequence select="$first + $second"/> more 
> efficient than <xsl:value-of select="$first + $second"/>?
> 
> I can understand that math on atomic values ought to be more 
> efficient than math on text nodes, but is the benefits 
> something we can measure in any meaningful sense?

They aren't the same thing, so comparing their efficiency is meaningless.

* One instruction computes a number by adding two numbers. 

* The other computes a number by adding two numbers, converts the result to
a string, and then wraps the string in a text node.

If the latter is what you want to do, then use it. But if you only want the
number, then converting it to a string and wrapping the string in a text
node is a crazy waste of effort, especially if you then convert the result
back to a number, which is something one sees all too often.

Whether you can measure the difference depends entirely of course on how
often you do it. But somehow I think that if the syntax were spelt out in
full as <xsl:create-text-node select="string-join(string($first + $second),
' ')"/> then you wouldn't even consider it. 

You can't claim you are using xsl:value-of rather than xsl:sequence because
it's shorter to write. You're using a complex construct where a simple one
would do, and the only possible reason for that is ingrained habits from
XSLT 1.0.

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

Current Thread