XSLT <xsl:message> 元素
定義和用法
<xsl:message> 元素可向輸出寫(xiě)一條消息。該元素主要用于報(bào)告錯(cuò)誤。
該元素能夠包含幾乎任何其他的 XSL 元素(<xsl:text> 、<xsl:value-of> 等等)。
terminate 屬性允許您選擇在錯(cuò)誤發(fā)生時(shí),是否應(yīng)終止轉(zhuǎn)換。
語(yǔ)法
<xsl:message terminate="yes|no"> <!-- Content:template --> </xsl:message>
屬性
屬性 | 值 | 描述 |
---|---|---|
terminate |
|
可選。"yes":在消息寫(xiě)入輸出后,終止處理。"no":在消息寫(xiě)入輸出后,繼續(xù)進(jìn)行處理。默認(rèn)是 "no"。 |
實(shí)例
例子 1
檢測(cè) 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>