Welcome toVigges Developer Community-Open, Learning,Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
954 views
in Technique[技术] by (71.8m points)

xslt - 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?

question from:https://stackoverflow.com/questions/65926515/dealing-with-empty-sequence-returned-by-xslevaluate

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

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


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to Vigges Developer Community for programmer and developer-Open, Learning and Share

2.1m questions

2.1m answers

63 comments

56.6k users

...