2016
10-20

XSLT Apply

清華大佬耗費(fèi)三個(gè)月吐血整理的幾百G的資源,免費(fèi)分享!....>>>

XSLT <xsl:apply-templates> 元素


<xsl:apply-templates> 元素可把一個(gè)模板應(yīng)用于當(dāng)前的元素或者當(dāng)前元素的子節(jié)點(diǎn)。


<xsl:apply-templates> 元素

<xsl:apply-templates> 元素可把一個(gè)模板應(yīng)用于當(dāng)前的元素或者當(dāng)前元素的子節(jié)點(diǎn)。

假如我們向 <xsl:apply-templates> 元素添加一個(gè) select 屬性,此元素就會(huì)僅僅處理與屬性值匹配的子元素。我們可以使用 select 屬性來規(guī)定子節(jié)點(diǎn)被處理的順序。

請(qǐng)看下面的 XSL 樣式表:

實(shí)例

<?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>
<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">
Title: <span style="color:#ff0000">
<xsl:value-of select="."/></span>
<br />
</xsl:template>

<xsl:template match="artist">
Artist: <span style="color:#00ff00">
<xsl:value-of select="."/></span>
<br />
</xsl:template>

</xsl:stylesheet>

掃碼二維碼 獲取免費(fèi)視頻學(xué)習(xí)資料

編程學(xué)習(xí)