XSLT <xsl:message> 元素

定義和用法
<xsl:message> 元素向輸出寫一條消息。該元素主要用於報告錯誤。
該元素能夠包含幾乎任何其他的 XSL 元素(<xsl:text> 、<xsl:value-of> 等等)。
terminate 屬性允許您選擇在錯誤發生時,是退出處理還是繼續處理。
語法
<xsl:message terminate="yes|no">
<!-- Content:template -->
</xsl:message>
<!-- 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>
<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>
