Sebastien
Sebastien

Reputation: 2714

Dealing with empty sequence returned by xsl:evaluate

I am using xsl:evaluate to get the value an XPath points to.

Example code:

<xsl:variable name="input" as="xs:string">
  <xsl:evaluate xpath="$someXPath" context-item="."/>
</xsl:variable>

It works fine, but if the XPath I am passing to xsl:evaluate is wrong and points to nothing I get this error when it tries to assign the empty value to the $input variable:

XTTE0570 An empty sequence is not allowed as the value of variable $input

I also tried it this way (adding as="xs:string" to xsl:evaluate)

<xsl:variable name="input" as="xs:string">
  <xsl:evaluate xpath="$Variable[@type=$EXnn]/@element" context-item="$Attribut" as="xs:string"/>
</xsl:variable>

but I get the same type of error:

Dynamic error in expression {myXPath} called using xsl:evaluate.
  Caused by net.sf.saxon.trans.XPathException: An empty sequence is not allowed as the
  result of the expression {myXPath} evaluated by xsl:evaluate

How should I deal with the case where the XPath does not return anything?

Upvotes: 1

Views: 851

Answers (1)

Martin Honnen
Martin Honnen

Reputation: 167696

If you type the variable as as="xs:string?" it should work to store an empty sequence or a string.

Upvotes: 2

Related Questions