当前位置: 首页 > 网络学院 > XML相关教程 > XSL/XSLT > XSLT <xsl:for-each> 元素

XSL/XSLT
XSL 语言
XSLT 介绍
XSLT 浏览器
XSLT 转换
<xsl:template>
<xsl:value-of>
<xsl:for-each>
<xsl:sort>
<xsl:if>
<xsl:choose>
<xsl:apply-templates>
XSLT - 客户端
XSLT - 服务器端
XSLT - 编辑XML
XSLT 摘要
XSLT 元素参考
XSLT 函数
XSL 编辑器

XSL/XSLT 中的 XSLT <xsl:for-each> 元素


出处:互联网   整理: 软晨网(RuanChen.com)   发布: 2009-03-04   浏览: 285 ::
收藏到网摘: n/a

Definition and Usage
定义和用法

The <xsl:for-each> element loops through each node in a specified node set.
<xsl:for-each>元素的作用是:在指定的节点组中循环操作每个节点。


Syntax
语法

<xsl:for-each
select="expression">
 <!-- Content:(xsl:sort*,template) -->
</xsl:for-each>

Attributes
属性

属性 描述
select expression Required. The node set to be processed
必要参数。指定需要处理的节点组

Example 1
案例1

Loop through each "cd "element and use <xsl:value-of> to write each title and artist to the output:
循环操作每个“cd”元素,并且使用<xsl:value-of>元素书写每个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> <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>

查看XML 文件XSL 文件以及结果

Example 2
案例2

Loop through each "cd "element and use <xsl:value-of> to write each title and artist to the output (sorted by artist):
循环操作每个“cd”元素,并且使用<xsl:value-of>元素书写每个title[标题]和artist[艺术家],然后输出(按照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> <h2>My CD Collection</h2> <table border="1"> <tr bgcolor="#9acd32"> <th>Title</th> <th>Artist</th> </tr> <xsl:for-each select="catalog/cd"> <xsl:sort select="artist"/> <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>

查看XML 文件XSL 文件以及结果

评论 (0) All

登陆 | 还没注册?