XSLT <xsl:value-of> 元素
定義和用法
<xsl:value-of> 元素可提取選定節(jié)點(diǎn)的值。
<xsl:value-of> 元素可用于選取某個(gè) XML 元素的值,并把它輸出。
注釋:select 屬性(必選)的值是一個(gè) XPath 表達(dá)式。它的工作原理類似對(duì)文件系統(tǒng)的定位,比如用一個(gè)斜杠來(lái)選擇子目錄。
語(yǔ)法
<xsl:value-of select="expression" disable-output-escaping="yes|no"/>
屬性
屬性 | 值 | 描述 |
---|---|---|
select | expression | 必需。XPath 表達(dá)式,規(guī)定了從哪個(gè)節(jié)點(diǎn)/屬性來(lái)提取值。 |
disable-output-escaping |
|
默認(rèn)值為 "no"。如果值為 "yes",通過(guò)實(shí)例化 <xsl:text> 元素生成的文本節(jié)點(diǎn)在輸出時(shí)將不進(jìn)行任何轉(zhuǎn)義。 比如如果設(shè)置為 "yes",則 "<" 將不進(jìn)行轉(zhuǎn)換。如果設(shè)置為 "no",則被輸出為 "<"。 |
實(shí)例
例子 1
<?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> <h2>My CD Collection</h2> <table border="1"> <tr bgcolor="#9acd32"> <th>Title</th> <th>Artist</th> </tr> <tr> <td><xsl:value-of select="catalog/cd/title"/></td> <td><xsl:value-of select="catalog/cd/artist"/></td> </tr> </table> </body> </html> </xsl:template> </xsl:stylesheet>
查看 XML 文件,查看 XSL 文件,查看結(jié)果。
例子 2
<?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> <h2>My CD Collection</h2> <table border="1"> <tr bgcolor="#9acd32"> <th>Title</th> <th>Artist</th> </tr> <xsl:for-each select="catalog/cd"> <tr> <td><xsl:value-of select="title"/></td> <td><xsl:value-of select="artist"/></td> </tr> </xsl:for-each> </table> </body> </html> </xsl:template> </xsl:stylesheet>