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