EXSLT - func:result - Version 1

Version: 1
Status: new
Element Package: func.result.zip

Element Syntax

<func:result
   select = expression>
   <-- Content: template -->
</func:result>

The exsl:return element works in a similar way to variable-binding elements as described in Section 11.2 of the XSLT 1.0 Recommendation.

Issue: exsl:return name - should exsl:return be called exsl:result instead?

Issue: exsl:reference-of - should it be possible to return node sets by building them up gradually through an extension element such as exsl:reference-of? It would ease the return of multiple nodes from a function. This is achievable by building an RTF with IDs pointing to the relevant nodes instead.

It is an error for exsl:return to appear outside the content of exsl:function. For example, the following is an error:

<xsl:template match="foo">
   <exsl:return select="." />
</xsl:template>

Issue: exsl:return parent - should the use of exsl:return be restricted to within exsl:function or is this too restrictive? Are there any other places where exsl:return might be useful?

It is an error if instantiating the content of the exsl:function element results in the instantion of more than one exsl:return elements. An XSLT processor may signal the error; if it does not signal the error, it must recover by ignoring all exsl:return elements after the first.

Issue: Multiple exsl:return error - should instantiating exsl:return more than once be an unrecoverable error?

The following is an error if the value of the context node when the function is called is equal to the string 'yes', as two exsl:return elements are instantiated: one within the xsl:if and one directly within the exsl:function:

<exsl:function name="my:func1">
   <xsl:if test=". = 'yes'">
      <exsl:return select="true()" />
   </xsl:if>
   <exsl:return select="false()" />
</exsl:function>

If an XSLT processor recovers from this error, the above function is equivalent to:

<exsl:function name="my:func1">
   <xsl:choose>
      <xsl:when test=". = 'yes'">
	      <exsl:return select="true()" />
	   </xsl:when>
	   <xsl:otherwise>
	      <exsl:return select="false()" />
	   </xsl:otherwise>
   </xsl:choose>
</exsl:function>

It is an error if an exsl:return element occurs within an exsl:return element. Thus the following is an error:

<exsl:function name="my:func2">
   <exsl:return>
      <exsl:return select="." />
   </exsl:return>
</exsl:function>

It is an error if instantiating the content of a variable-binding element (i.e. xsl:variable, xsl:param) results in the instantiation of an exsl:return element. Thus the following is an error:

<exsl:function name="my:func3">
   <xsl:variable name="foo">
      <exsl:return select="." />
   </xsl:variable>
</exsl:function>

If no exsl:return element is instantiated during the execution of a function, the return value for the function is the empty string ('').

Issue: Return values - should the default return value from a function be a node set instead of an empty string? Attempting to interpret a string as a node set will lead to an unrecoverable error. For example:

<exsl:function name="my:root">
   <xsl:if test="false()">
      <exsl:return select="/" />
   </xsl:if>
</exsl:function>

would (accidentally) return an empty string. If it was used in:

<xsl:variable name="foo" select="my:root()/foo" />

this would cause an unrecoverable error.

Return Values

The exsl:return element can specify the value of the variable in three alternative ways.

  • If the exsl:return element has a select attribute, then the value of the attribute must be an expression and the returned value is the object that results from evaluating the expression. In this case, the content must be empty.

    Issue: exsl:return expressions - should the select attribute on exsl:return hold an extended XPath syntax that includes things such as conditional constructs?

  • If the exsl:return element does not have a select attribute and has non-empty content (i.e. the exsl:return element has one or more child nodes), then the content of the exsl:return element specifies the value. The content of the exsl:return element is a template, which is instantiated to give the returned value. The value is a result tree fragment equivalent to a node-set containing just a single root node having as children the sequence of nodes produced by instantiating the template. The base URI of the nodes in the result tree fragment is the base URI of the exsl:return element.

    It is an error if a member of the sequence of nodes created by instantiating the template is an attribute node or a namespace node, since a root node cannot have an attribute node or a namespace node as a child. An XSLT processor may signal the error; if it does not signal the error, it must recover by not adding the attribute node or namespace node.

  • If the exsl:return element has empty content and does not have a select attribute, then the returned value is an empty string. Thus

    <exsl:return />

    is equivalent to

    <exsl:return select="''"/>

An implementation of this extension element in the EXSLT func namespace must conform to the behaviour described in this document.

Change History

Submitted: 2001-02-25
Creator: Jeni Tennison(http://www.jenitennison.com)

First draft of the functionality of exsl:return.

Copyright

http://www.exslt.org/func.result.1.html last modified 2001-02-25