xsl-list
[Top] [All Lists]

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

2008-09-30 04:49:24

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/


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