处理 xsl:evaluate 返回的空序列
Dealing with empty sequence returned by xsl:evaluate
我正在使用 xsl:evaluate 获取 XPath 指向的值。
示例代码:
<xsl:variable name="input" as="xs:string">
<xsl:evaluate xpath="$someXPath" context-item="."/>
</xsl:variable>
它工作正常,但是如果我传递给 xsl:evaluate 的 XPath 是错误的并且没有指向任何东西,当它试图将空值分配给 $input 变量时我得到这个错误:
XTTE0570 An empty sequence is not allowed as the value of variable
$input
我也试过这种方法(将 as="xs:string" 添加到 xsl:evaluate)
<xsl:variable name="input" as="xs:string">
<xsl:evaluate xpath="$Variable[@type=$EXnn]/@element" context-item="$Attribut" as="xs:string"/>
</xsl:variable>
但我得到了相同类型的错误:
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
我应该如何处理 XPath 没有 return 任何东西的情况?
如果您将变量键入 as="xs:string?"
,它应该可以存储空序列或字符串。
我正在使用 xsl:evaluate 获取 XPath 指向的值。
示例代码:
<xsl:variable name="input" as="xs:string">
<xsl:evaluate xpath="$someXPath" context-item="."/>
</xsl:variable>
它工作正常,但是如果我传递给 xsl:evaluate 的 XPath 是错误的并且没有指向任何东西,当它试图将空值分配给 $input 变量时我得到这个错误:
XTTE0570 An empty sequence is not allowed as the value of variable $input
我也试过这种方法(将 as="xs:string" 添加到 xsl:evaluate)
<xsl:variable name="input" as="xs:string">
<xsl:evaluate xpath="$Variable[@type=$EXnn]/@element" context-item="$Attribut" as="xs:string"/>
</xsl:variable>
但我得到了相同类型的错误:
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
我应该如何处理 XPath 没有 return 任何东西的情况?
如果您将变量键入 as="xs:string?"
,它应该可以存储空序列或字符串。