?
This document uses PHP Chinese website manual Release
<xsl:value-of> 元素可提取選定節(jié)點的值。
<xsl:value-of> 元素可用于選取某個 XML 元素的值,并把它輸出。
<xsl:value-of select="expression" disable-output-escaping="yes|no" />
屬性 | 值 | 描述 |
---|---|---|
select | expression | 必需。一個 XPath 表達式,規(guī)定了從哪個節(jié)點/屬性來提取值。它的工作原理與通過正斜杠(/)選擇子目錄的導航文件系統(tǒng)類似。 |
disable-output-escaping | yes no | 可選。如果值為 "yes",通過實例化 <xsl:text> 元素生成的文本節(jié)點在輸出時將不進行任何轉(zhuǎn)義。比如 "<" 將輸出為 "<"。如果值為 "no",則 "<" 將輸出為 "<"。默認是 "no"。 |
下面的實例獲取第一個 title 和 artist 元素的值,并放置在表格中:
<?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> <h1>Music Collection:</h1> <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>
下面的實例循環(huán)遍歷每個 cd 元素,并創(chuàng)建帶有每個 cd 元素的 title 和 artist 的值的表格行:
<?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> <h1>Music Collection:</h1> <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>