XSLT <xsl:message>
❮ Complete XSLT Element Reference
定义和用法
The <xsl:message> 元素向输出写入一条消息。该元素主要用于报告错误。
此元素几乎可以包含其他任何 XSL 元素(<xsl:text>、<xsl:value-of> 等)。
terminate 属性使您可以在发生错误时选择是中止还是继续处理。
语法
<xsl:message terminate="yes|no">
<!-- Content:template -->
</xsl:message>
属性
Attribute | 值 | 描述 |
---|---|---|
terminate | 是 no |
可选。“yes”在消息写入输出后终止处理。“no”在消息写入输出后继续处理。默认为“no”。 |
示例 1
检查 artist 是否为空字符串。如果是,则退出 XSL 处理器并显示一条消息
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:template match="/">
<html>
<body>
<xsl:for-each select="catalog/cd">
<p>Title: <xsl:value-of select="title"/><br />
Artist
<xsl:if test="artist=''">
<xsl:message terminate="yes">
Error: Artist is an empty string!
</xsl:message>
</xsl:if>
<xsl:value-of select="artist"/>
</p>
</xsl:for-each>
</body>
</html>
</xsl:template>
</xsl:stylesheet>
❮ Complete XSLT Element Reference