如何在 XSLT 2.0 或 3.0 的 `xsl:message` 中填充当前错误消息? [英] How to populate current error message in `xsl:message` in XSLT 2.0 or 3.0?
问题描述
我正在尝试在此处打印运行时错误消息,我可以使用任何版本的 XSLT 2.0 或 3.0:
I am trying to print run time error message here is input i can use any version of XSLT 2.0 or 3.0:
<transaction>
<actual_premium>3200000000</actual_premium>
<actual_premium>3200000000</actual_premium>
</transaction>
XSLT 我正在尝试:
XSLT i am trying:
<xsl:template match="/">
<xsl:variable name="Premium" select="/transaction/actual_premium"/>
<root>
<xsl:try>
<xsl:value-of select="format-number($Premium, '###,###,###')"/>
<xsl:catch>
<!-- Here i want to print error message A sequence of more than one item is not allowed as the first argument of fn:format-number() -->
<xsl:message select="current()"/>
</xsl:catch>
</xsl:try>
</root>
</xsl:template>
错误消息不允许有多个项目的序列作为 fn:format-number() 的第一个参数
应填充.
推荐答案
XSLT 2 没有 try/catch
,至于 XSLT 3,见 https://www.w3.org/TR/xslt-30/#try-catch-examples如何在名称空间 xmlns:err="http://www.w3.org/2005 中使用
$err:code
和/或 $err:description
/xqt-错误"
XSLT 2 has no try/catch
, as for XSLT 3, see https://www.w3.org/TR/xslt-30/#try-catch-examples on how to use $err:code
and/or $err:description
in the namespace xmlns:err="http://www.w3.org/2005/xqt-errors"
<xsl:try>
<xsl:value-of select="format-number($Premium, '###,###,###')"/>
<xsl:catch>
<xsl:message>
Error code: <xsl:value-of select="$err:code"/>
Reason: <xsl:value-of select="$err:description"/>
</xsl:message>
</xsl:catch>
</xsl:try>
当然还有 https://www.w3 中的完整描述.org/TR/xslt-30/#try-catch 包含 xsl:catch
中可用的所有变量.
and of course the full description in https://www.w3.org/TR/xslt-30/#try-catch of all the variables available within xsl:catch
.
这篇关于如何在 XSLT 2.0 或 3.0 的 `xsl:message` 中填充当前错误消息?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!