使用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子元素,
<?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子元素,
相关文章推荐
- 使用mobile jQuery 动态给select下拉添加数据,选中项默认不显示的解决方法。
- 选择数据selectdate的使用
- 使用bootstrap-select 动态加载数据不显示的问题
- 显示刚刚添加的最后一条数据,access,选择语句,select
- REPEATER控件显示数据,交替项显示;分页类的使用,Repeater控件分页;使用DataList控件绑定数据;使用DataList控件的选择模板
- XML入门指南(9)使用XSL来显示XML数据
- Android中的使用ListView控件显示List集合中的数据,并对Item响应选择事件(方法二)
- 选择指定条件的数据,并显示出来(select)
- Android中的使用ListView控件显示List集合中的数据,并对Item响应选择事件(方法一)
- 选择模式:xml通过同目录下的xsl显示数据
- XML入门指南(9)使用XSL来显示XML数据
- mysql导入导出数据中文乱码解决方法小结(1、navicat导入问题已解决,创建连接后修改连接属性,选择高级->将使用Mysql字符集复选框去掉,下拉框选择GBK->导入sql文件OK;2、phpmyadmin显示乱码的问题也解决,两步:1.将sql文件以utf8的字符集编码另存,2.将文件中sql语句中的字段字符集编码改成utf8,导入OK)
- XML基础知识学习八(使用XSL来显示XML数据)
- Android---Spinner的使用01(选择下拉框Toast显示选择的数据)
- ember.js:使用笔记1-数组数据统一显示
- Android上使用OpenGLES2.0显示YUV数据
- excel使用数据字典显示数据——宏
- js实现内容显示并使用json传输数据
- [原创]使用DataList显示数据
- jsp jquery 页面中select显示加载后的数据默认选中项