用于测试的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>
在tcode strans创建的xslt program:
<?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:stylesheet>
match = “/” 意为匹配整个xml document: 测试输出:
输出结果来自xslt里manual 指定的h2 tag 以及匹配的整个xml document中每个节点的value,但不包含节点名称本身。 如果把match = “/”替换成 match = “title”:
输出如下, 因此此时有两个匹配的title node。
match=“catalog”: 效果如/ match=“cd”: 效果如match = “title” match=“artist”: 找不到匹配的document,输出为空:
但如果先匹配整个document,再匹配artist node则可成功:
输出如下:
match="/catalog/cd": 输出同match=“cd” match="/catalog/cd/title": 输出同上 match="/catalog/cd/artist": 输出为空 match=“artist[parent::cd]”>: 输出为空 输入如下: [外链图片转存失败(img-U8zlk8Ac-1562210924325)(https://user-images.githubusercontent.com/5669954/27290940-0274646e-550f-11e7-9d3c-f2417d434d58.png)] 输出:
match="*": 每个节点都会生成一个h2 node: