我正在查看一个旧的xsl文件,并试图了解为什么原作者已将<xsl:template>
元素的数量定义为包含match
属性的自关闭标记。在下面我的问题的例子是在问候<xsl:template match="title" />
:自动关闭xsl:模板标签?
XML
<?xml version="1.0" encoding="UTF-8"?>
<catalog>
<cd>
<title>Empire Burlesque</title>
<artist>Bob Dylan</artist>
<country>USA</country>
<company>Columbia</company>
<price>10.90</price>
<year>1985</year>
</cd>
</catalog>
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>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" />
<xsl:template match="artist">
Artist: <span style="color:#00ff00">
<xsl:value-of select="."/></span>
<br />
</xsl:template>
</xsl:stylesheet>
由于标签是自闭,但显然没有内容在<xsl:template \>
。这样做的意义何在?这是一种通过匹配属性“隐藏”与template
关联的XML数据的技术吗?