【发布时间】:2017-08-24 18:44:38
【问题描述】:
我正在查看一个旧的 xsl 文件并试图了解为什么原作者将许多 <xsl:template> 元素定义为包含 match 属性的 自闭合标签。在下面的示例中,我的问题是关于<xsl:template match="title" />:
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 \> 中显然没有内容。这样做有什么意义?这是一种通过 match 属性“隐藏”与template 关联的 XML 数据的技术吗?
【问题讨论】: