[XSL-LIST Mailing List Archive Home] [By Thread] [By Date] [Recent Entries] [Reply To This Message]

Re: Why? A function that computes atomic values should

Subject: Re: Why? A function that computes atomic values should use xsl:sequence rather than xsl:value-of
From: "Michael Kay mike@xxxxxxxxxxxx" <xsl-list-service@xxxxxxxxxxxxxxxxxxxxxx>
Date: Tue, 31 Mar 2020 14:02:42 -0000
Re:  Why? A function that computes atomic values should
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@xxxxxxxxx
<xsl-list-service@xxxxxxxxxxxxxxxxxxxxxx> 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

Current Thread

PURCHASE STYLUS STUDIO ONLINE TODAY!

Purchasing Stylus Studio from our online shop is Easy, Secure and Value Priced!

Buy Stylus Studio Now

Download The World's Best XML IDE!

Accelerate XML development with our award-winning XML IDE - Download a free trial today!

Don't miss another message! Subscribe to this list today.
Email
First Name
Last Name
Company
Subscribe in XML format
RSS 2.0
Atom 0.3
Site Map | Privacy Policy | Terms of Use | Trademarks
Free Stylus Studio XML Training:
W3C Member
Stylus Studio® and DataDirect XQuery ™are products from DataDirect Technologies, is a registered trademark of Progress Software Corporation, in the U.S. and other countries. © 2004-2013 All Rights Reserved.