?
This document uses PHP Chinese website manual Release
<xsl:for-each> 元素可循環(huán)遍歷指定的節(jié)點(diǎn)集中的每個(gè)節(jié)點(diǎn)。
<xsl:for-each select="expression"> <!-- Content --> </xsl:for-each>
屬性 | 值 | 描述 |
---|---|---|
select | expression | 必需。一個(gè) XPath 表達(dá)式,規(guī)定被處理的節(jié)點(diǎn)集。 |
下面的實(shí)例循環(huán)遍歷每個(gè) cd 元素,并把每個(gè) cd 寫到輸出中:
<?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="/"> <div> <xsl:for-each select="catalog/cd"> <p><xsl:value-of select="title" /></p> </xsl:for-each> </div> </xsl:template> </xsl:stylesheet>
下面的實(shí)例循環(huán)遍歷每個(gè) cd 元素,并創(chuàng)建一個(gè)表格顯示每個(gè) 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>