您当前的位置: 首页 > 学无止境 > XML与XSLT 网站首页XML与XSLT
xslt的apply元素的使用(xml遍历子节点)
发布时间:2015-03-18 21:27:42编辑:雪饮阅读()
xml代码部分:
<?xml version="1.0" encoding="ISO-8859-1"?>
<!-- Edited with XML Spy v2007 (http://www.altova.com) -->
<?xml-stylesheet type="text/xsl" href="cdcatalog_apply.xsl"?>
<catalog>
<cd>
<title>1.Empire Burlesque</title>
<artist>Bob Dylan</artist>
<country>USA</country>
<company>Columbia</company>
<price>10.90</price>
<year>1985</year>
</cd>
<cd>
<title>2.Hide your heart</title>
<artist>Bonnie Tyler</artist>
<country>UK</country>
<company>CBS Records</company>
<price>9.90</price>
<year>1988</year>
</cd>
<cd>
<title>3.Greatest Hits</title>
<artist>Dolly Parton</artist>
<country>USA</country>
<company>RCA</company>
<price>9.90</price>
<year>1982</year>
</cd>
</catalog>
xsl代码部分:
<?xml version="1.0" encoding="ISO-8859-1"?>
<!-- Edited with XML Spy v2007 (http://www.altova.com) -->
<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:red">
<xsl:value-of select="."/>
</span>
<br />
</xsl:template>
<xsl:template match="artist">
Artist: <span style="color:pink">
<xsl:value-of select="."/></span>
<br />
</xsl:template>
</xsl:stylesheet>

关键字词:xml,xslt,个人博客
上一篇:xsl中的if条件语句