Created by Jerry Wang on Jun 30, 2014
用于测试的xml:
<catalog>
<cd>
<title>Empire Burlesque</title>
<artist>Bob Dylan</artist>
<country>USA</country>
<company>Columbia</company>
<price>10.90</price>
<year>1985</year>
</cd>
<cd>
<title>Hide your heart</title>
<artist>Bonnie Tyler</artist>
<country>UK</country>
<company>CBS Records</company>
<price>9.90</price>
<year>1988</year>
</cd>
</catalog>
下列xslt将只会输出h2的My CD Collection,因为sub template 匹配之后没有任何实现:
但是如果sub template未匹配成功,例如指定了一个错误的path:
添加copy keyword可以让匹配的node加入到输出中:
<xsl:template match="/catalog/cd">
<p>hel</p>
<xsl:copy>
<xsl:apply-templates/>
</xsl:copy>
</xsl:template>
</xsl:stylesheet>
输出:
删除copy keyword只保留apply-templates效果相同:
使用copy将每个cd node重复输出三次: