Powered By Blogger

Sunday, September 15, 2013

XML-22036: (Error) Cannot convert result tree fragment to NodeSet

In this post we talk about context of error in subject.

XSLT 1.0 spec has a data type called 'result tree fragment' and this data type is introduced by XSLT variables.A result tree fragment is treated equivalently to a node-set that contains just a single root node. However, the operations permitted on a result tree fragment are a subset of those permitted on a node-set.In particular, it is not permitted to use the /, //, and [] operators on result tree fragments

For example, if we have xslt like below then that is scope for  mentioned error

 <xsl:stylesheet version="1.0"....
 <xsl:param name="InputVariable.payload" />
 <xsl:template match="/">
 <top:ResultTreeCollection>
 <top:Application>
  <xsl:value-of select="$InputVariable.payload/ns1:Applications/ns1:ApplicationName" />
  </top:Application>
...
</xsl:stylesheet>

In above XSLT, we are trying to access a BPEL variable called  "InputVariable"(having result tree fragment data type) and applying an operation '/' which is not allowed as per XSLT 1.0 spec

There are two solutions possible
  • Using Oracle xslt extension function node-set() which converts result tree fragment to node set
  • Use XSLT 2.0 version
Simplest solution is use XSLT 2.0 version  that means,  <xsl:stylesheet version="2.0">         2.0 version deprecates result tree fragment data type and implicitly convert that to node-set data type on which /, //, [] operations are allowed safely.

Same error comes when xsl:variable is defined to have sequence of nodes. For example <xsl:variable name="Applications" select="./ApplicationsList" />

1 comment: