xsl-list
[Top] [All Lists]

Re: [xsl] Why? A function that computes atomic values should use xsl:sequence rather than xsl:value-of

2020-03-31 09:02:47
When you write

<xsl:function name="f:test" as="xs:boolean">
  <xsl:value-of select="2 + 2 = 4"/>
</xsl:function>

the expression in the select attribute returns the boolean value true. The 
xsl:value-of instruction first converts this to the string "true", then wraps 
this string into a text node (which carries all the baggage of nodes, such as a 
unique identity). The function conversion rules then atomize the text node to a 
string "true", and then convert the string back to the boolean value true.

This is very inefficient. In some cases the Saxon optimizer is able to 
eliminate all the unnecessary conversions, but it isn't always possible (for 
example it gets quite complicated if the select expression is capable of 
returning an empty sequence). It's much better to write the code in a way that 
doesn't invoke all the conversion machinery in the first place.

If `<xsl:value-of>` had instead been named `<xsl:create-text-node>`, which 
would be a better name given what it does, then I suspect it wouldn't occur to 
you to ask the question.

Michael Kay
Saxonica

On 31 Mar 2020, at 14:40, Costello, Roger L. costello(_at_)mitre(_dot_)org 
<xsl-list-service(_at_)lists(_dot_)mulberrytech(_dot_)com> wrote:

Hi Folks,

I have a function that returns a xs:boolean. I used xs:value-of to return the 
value. Saxon 9.9.1.5 gives this warning message:

      A function that computes atomic values 
      should use xsl:sequence rather than
      xsl:value-of

Why?

Why should a function use xsl:sequence?

I don't recall ever seeing that warning before. Is this something new?

/Roger

--~----------------------------------------------------------------
XSL-List info and archive: http://www.mulberrytech.com/xsl/xsl-list
EasyUnsubscribe: http://lists.mulberrytech.com/unsub/xsl-list/1167547
or by email: xsl-list-unsub(_at_)lists(_dot_)mulberrytech(_dot_)com
--~--
<Prev in Thread] Current Thread [Next in Thread>