Latest web development tutorials

XSLT <xsl:message> 元素

XSLT 元素參考手冊 完整的XSLT元素參考手冊

定義和用法

<xsl:message> 元素向輸出寫一條消息。 該元素主要用於報告錯誤。

該元素能夠包含幾乎任何其他的XSL 元素(<xsl:text> 、<xsl:value-of> 等等)。

terminate 屬性允許您選擇在錯誤發生時,是退出處理還是繼續處理。


語法

<xsl:message terminate="yes|no">

<!-- Content:template -->

</xsl:message>

屬性

属性 描述
terminate yes
no
可选。"yes":在消息写入输出后,终止处理。"no":在消息写入输出后,继续进行处理。默认是 "no"。

實例1

檢測artist 是否是空字符串。 如果是,則退出XSL 處理器,並顯示一條消息:

<?xml version="1.0" encoding="ISO-8859-1"?>
<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>


XSLT 元素參考手冊 完整的XSLT元素參考手冊