xml - 从 XSLT 中抛出异常

标签 xml xslt railo

当外部文档不可用时,我需要 XSLT 停止处理并出现错误。据我所知, 标记似乎是正确的方法,但到目前为止它不起作用。这是我尝试过的:

<xsl:if test="not(document('some_external_doc.xml')//myxpath)">
    <xsl:message terminate="yes">ERROR: Missing element!</xsl:message>
    <h1>Error detected!</h1>
</xsl:if>

检测到丢失的文档/xpath,

将被显示,但由于某些原因, 的终止属性被忽略。转换是在 Railo 中完成的,因此 XSLT 处理器的使用应该是 Java 默认值,但我无法找到有关 Railo 正在使用的处理器的确切信息。

最佳答案

你的想法是对的,但是......

如果您的 XSLT 处理器实现了 XSLT 1.0,从技术上讲它不必终止。注意在 spec for xsl:message 中使用了应该而不是必须 :

If the terminate attribute has the value yes, then the XSLT processor should terminate processing after sending the message. The default value is no.

有趣的是,XSLT 2.0 changes应该必须:

If the effective value of the terminate attribute is yes, then the processor must terminate processing after sending the message.

另请注意,xsl:message 语句的执行顺序取决于处理器;在日志中查找 xsl:message 输出时请记住这一点。

最后,您在 XSLT 2.0(error() 函数)和 XSLT 3.0(xsl:try and xsl:catch)下有一些额外的异常处理选项。

关于xml - 从 XSLT 中抛出异常,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25644704/

相关文章:

xml - 使用xslt基于xml标签动态插入查询

base64 - 2 台不同机器上 CFML 中 toBase64() 的不同输出

xml - Groovy xml 请求解析

C#:使用 XmlTextWriter 清理 XML 文本值?

xml - 使用 XSLT 将子节点移动到父属性中

xslt - xsl :import conventions about general stylesheet's properties

xslt - 有没有办法在 XSL-FO 中使用相当于 'rowspan' 的值?

coldfusion - Lucee - Coldfusion 新关键字不起作用

tomcat - Coldfusion CGI.HTTP_IF_MODIFIED_SINCE 似乎在 IE 中不起作用

c# - 将 XmlDocument 作为子节点添加到另一个 XmlDocument