您的位置:首页 > 其它

使用XSL的select 有选择的显示数据

2006-05-29 23:23 381 查看
1.XML文档

<?xml version="1.0" encoding="GB2312"?>
<?xml-stylesheet type="text/xsl" href="book2.xsl"?>
<BookLib>
<Book>
<Title>Windows程序设计</Title>
<Author>
<name>好孩子</name>
<Email>haohaizi@163.com</Email>
</Author>
<Press>
<PressDate>2000年5月1日</PressDate>
<PressCompany>南京出版社</PressCompany>
</Press>
<Price>49.00元</Price>
</Book>
<Book>
<Title>深入潜出XML</Title>
<Author>
<name>老虎工作室</name>
<Email>laohu@163.com</Email>
</Author>
<Press>
<PressDate>2006年5月12日</PressDate>
<PressCompany>北京出版社</PressCompany>
</Press>
<Price>28.00元</Price>
</Book>
<Book>
<Title>人工智能技术导论</Title>
<Author>
<name>廉师友</name>
<Email>laolian@163.com</Email>
</Author>
<Press>
<PressDate>2006年7月12日</PressDate>
<PressCompany>上海出版社</PressCompany>
</Press>
<Price>18.00元</Price>
</Book>
</BookLib>

上面的XML文档定义了根元素为BookLib,三个子元素为Book的树,

其中Book元素又有Title,Author,Press,Price 四个元素,其中Author元素又有name和Email两个子元素,

Press元素又有PressDate和PressCompany元素,

2.XSL文档的内容

<?xml version="1.0" encoding="GB2312"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/TR/WD-xsl">
<xsl:template match="/">
<html>
<xsl:apply-templates/>
</html>
</xsl:template>
<xsl:template match="BookLib">
<body>
<xsl:apply-templates/>
</body>
</xsl:template>
<xsl:template match="Book">
<xsl:apply-templates />
</xsl:template>
<xsl:template match="Title">
<Font size="3" color="#0000FF">
<BR/>
<xsl:value-of select="."/>
</Font>
</xsl:template>
<xsl:template match="Author">
<Font size="3" color="#FF0000">
<BR/>
<xsl:value-of select="name"/>
</Font>
</xsl:template>
<xsl:template match="Press">
<Font size="3" color="#FF00FF">
<BR/>
<xsl:value-of select="."/>
</Font>
</xsl:template>
<xsl:template match="Price">
<Font size="3" color="#999999">
<BR/>
<xsl:value-of select="."/>
</Font>
</xsl:template>
</xsl:stylesheet>

其中

xsl:value-of select="name" 这行表示我们显示的是Author元素的name子元素,
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: 
相关文章推荐