Oracle Blog

Principal Product Manager

Result Tree Fragments and Node-Sets

When you use an XML fragment to initialize a variable or a parameter, then the variable or parameter is of the

"result tree fragment" datatype. This is an XSLT 1.0 specific datatype [just like node-set, but slightly different]. A result tree fragment is equivalent to a node-set that contains just the root node.

You cannot apply operators like "/", "//" or predicate on a result tree fragments. They are only applicable for node-set datatypes.

Typically,when you perform a "select" in XSLT, what you get is a node-set. For instance, <xsl:variable name="countryNames" select="/tns:Countries/tns:Country"/> means that the variable countryNames contains a node-set of "Country" nodes. You can apply operators like "/" on this variable, for instance <xsl:for-each select="$countryNames/@name"> . . . </xsl:for-each> But you cannot perform this kind of an operation on a result tree fragment.

There are two ways to solve this issue.

a) In XSLT 1.0

The resolution of this is to convert the result tree fragment into a node-set. I am not aware of any oracle specific xpath extension functions that can do this trick for you. You could use EXSLT to achieve this. EXSLT provides some very useful extensions to XSLT.They have defined an extension function node-set() that converts result tree fragments into node-sets. Alternatively, you could also write your own java routine to convert between result tree fragments and node-sets. I am an XSLT with the EXSLT xpath function for your reference. Note the namespace declaration for exsl, and the function usage.

You can code your transformations in XSLT 2.0. XSLT 2.0 deprecates ResultTreeFragments i.e. if you are modeling an XSLT 2.0 transformation, and you create a variable or a parameter that holds a tree fragment, it is implicitly a node sequence. You could then use path expressions against these variables and parameters. To make your transformations executed by an XSLT 2.0 processor, simply change the "version" attribute on the &lt;xsl:stylesheet> to "2.0".

With this approach, you can use the select expression "$param1/FileList/File" to iterate over the File elements witihn the XSLT parameter.