Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
1.1k 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 Reply

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.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...