XSLT <xsl:apply-templates> 元素
<xsl:apply-templates> 元素將模板規則應用於當前元素或當前元素的子節點。
<xsl:apply-templates> 元素
<xsl:apply-templates> 元素將模板應用於當前元素或當前元素的子節點。
如果我們向 <xsl:apply-templates> 元素新增 "select" 屬性,它將只處理與該屬性值匹配的子元素。我們可以使用 "select" 屬性來指定處理子節點的順序。
請看下面的 XSL 樣式表
示例
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:template match="/">
<html>
<body>
<h2>我的 CD 收藏</h2>
<xsl:apply-templates/>
</body>
</html>
</xsl:template>
<xsl:template match="cd">
<p>
<xsl:apply-templates select="title"/>
<xsl:apply-templates select="artist"/>
</p>
</xsl:template>
<xsl:template match="title">
標題:<span style="color:#ff0000">
<xsl:value-of select="."/></span>
<br />
</xsl:template>
<xsl:template match="artist">
藝術家:<span style="color:#00ff00">
<xsl:value-of select="."/></span>
<br />
</xsl:template>
</xsl:stylesheet>
自己動手試一試 »