Subject: Re: [xsl] 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 |
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 |
---|
|
<- Previous | Index | Next -> |
---|---|---|
Re: [xsl] Why? A function that comp, Graydon graydon@xxxx | Thread | |
Re: [xsl] Why? A function that comp, Graydon graydon@xxxx | Date | Re: [xsl] Parsing XPath in XSLT?, Wendell Piez wapiez@ |
Month |