?
This document uses PHP Chinese website manual Release
<xsl:message> 元素向輸出寫一條消息。該元素主要用于報(bào)告錯(cuò)誤。
該元素能夠包含幾乎任何其他的 XSL 元素(<xsl:text> 、<xsl:value-of> 等等)。
terminate 屬性允許您選擇在錯(cuò)誤發(fā)生時(shí),是退出處理還是繼續(xù)處理。
<xsl:message terminate="yes|no"> <!-- Content:template --> </xsl:message>
屬性 | 值 | 描述 |
---|---|---|
terminate | yes no | 可選。"yes":在消息寫入輸出后,終止處理。"no":在消息寫入輸出后,繼續(xù)進(jìn)行處理。默認(rèn)是 "no"。 |
檢測 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>