Latest web development tutorials

XSLT <XSL: สำหรับแต่ละ> องค์ประกอบ

คู่มือการใช้งาน XSLT องค์ประกอบอ้างอิง คู่มือการใช้งาน XSLT องค์ประกอบอ้างอิง

ความหมายและการใช้งาน

<xsl: สำหรับแต่ละ> องค์ประกอบที่สามารถผ่านรอบโหนดของโหนดที่ระบุไว้ในแต่ละกลุ่ม


ไวยากรณ์

<xsl:for-each select="expression">
<!-- Content -->
</xsl:for-each>

คุณสมบัติ

属性 描述
select expression 必需。一个 XPath 表达式,规定被处理的节点集。


ตัวอย่าง

ตัวอย่างต่อไปนี้ loops ผ่านแต่ละองค์ประกอบซีดี, และการส่งออกของแต่ละแผ่นซีดีเขียน:

ตัวอย่าง

<?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>

ลอง»

ตัวอย่างต่อไปนี้ loops ผ่านแต่ละองค์ประกอบซีดีและสร้างตารางแสดงชื่อของแต่ละซีดีและศิลปิน:

ตัวอย่าง

<?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>

ลอง»


คู่มือการใช้งาน XSLT องค์ประกอบอ้างอิง คู่มือการใช้งาน XSLT องค์ประกอบอ้างอิง