3

In example of functions as i see there is use of xsl:sequence when i change this with xsl:value-of it gives same result, what is the benefits of using xsl:sequence rather than xsl:value-of.

Rupesh_Kr
  • 3,395
  • 2
  • 17
  • 32

1 Answers1

4

Always use xsl:sequence.

xsl:sequence returns the result of its select expression.

xsl:value-of takes the result of the select expression and wraps it into a text node. If the declared result of the function is (say) xs:integer, the text node will then be atomized and converted to an xs:integer. So for example

<xsl:function name="f:add" as="xs:integer">
  <xsl:param name="x" as="xs:integer"/>
  <xsl:param name="y" as="xs:integer"/>
  <xsl:value-of select="$x + $y"/>
</xsl:function>

will perform an integer addition of x and y, will convert the result to a string, wrap this in a text node, atomize the text node to get an untyped atomic value, and then convert the untyped atomic value to an integer.

If you're lucky the optimizer will detect that this is all a waste of effort and avoid the overhead, but it's best not to depend on it.

There are other cases where xsl:value-of simply doesn't work, for example where the function is returning a node.

Michael Kay
  • 156,231
  • 11
  • 92
  • 164