XML实验报告计算机学院软件工程一、实验题目XML文件的两种显示方式二、实验目的1.理解CSS;2.学会使用CSS显示XML文件;3.理解XSL;4.学会使用XSL显示XML文件;5.对比CSS和XSL;三、实验代码1.用DTD文件生成的XML文件<?xml version="1.0" encoding="UTF-8"?><!--Sample XML file generated by XMLSpy v2007 ()--> <!DOCTYPE bookcase SYSTEM "课堂练习2(DTD文件).dtd"><?xml-stylesheet type="text/css" href="css.css"?><bookcase><book><b-name>书1</b-name><author><name>敖阳月</name><E-mail>邮箱1</E-mail></author><price>10</price><publishing-house><p-name>天津出版社</p-name><address>出版社地址1</address><zipcode>出版社编号1</zipcode><E-mail>出版社邮箱1</E-mail></publishing-house></book><book><b-name>书2</b-name><author><name>敖阳月</name><E-mail>邮箱2</E-mail></author><price>20</price><publishing-house><p-name>出版社名2</p-name><address>出版社地址2</address><zipcode>出版社编号2</zipcode><E-mail>出版社邮箱2</E-mail> </publishing-house></book><book><b-name>书3</b-name><author><name>作者3</name><E-mail>邮箱3</E-mail></author><price>30</price><publishing-house><p-name>天津出版社</p-name><address>出版社地址3</address><zipcode>出版社编号3</zipcode><E-mail>出版社邮箱3</E-mail> </publishing-house></book><book><b-name>书4</b-name><author><name>作者4</name><E-mail>邮箱4</E-mail></author><price>40</price><publishing-house><p-name>出版社名4</p-name><address>出版社地址4</address><zipcode>出版社编号4</zipcode><E-mail>出版社邮箱4</E-mail> </publishing-house></book><book><b-name>书5</b-name><author><name>敖阳月</name><E-mail>邮箱5</E-mail></author><price>50</price><publishing-house><p-name>出版社名5</p-name><address>出版社地址5</address><zipcode>出版社编号5</zipcode><E-mail>出版社邮箱5</E-mail></publishing-house></book><book><b-name>书6</b-name><author><name>作者6</name><E-mail>邮箱6</E-mail></author><price>60</price><publishing-house><p-name>出版社名6</p-name><address>出版社地址6</address><zipcode>出版社编号6</zipcode><E-mail>出版社邮箱6</E-mail> </publishing-house></book></bookcase>2.CSS文件bookcase{background-color: #FFFFCC;}book{border-style: double;border-color: #000080;display: block;margin-bottom: 20pt;padding: 10pt;text-align: center;}name,zipcode,p-name{font-family: 华a文?新?魏o;font-size: medium;font-weight: bold;padding-right:15pt;}b-name,address{font-family: 华a文?行D楷?;color: #008080;padding-right:15pt;display:inherit;}E-mail{font-family: 华a文?行D楷?;color: #888080;padding-right:15pt;display:inherit;}price{font-family: 华a文?彩¨º云?;color: #FF0000;padding-right:15pt;}3.实验截图4.用DTD文件生成的XML文件:<?xml version="1.0" encoding="UTF-8"?><!--Sample XML file generated by XMLSpy v2007 ()--> <!DOCTYPE bookcase SYSTEM "generateDTD.dtd"><?xml-stylesheet type="text/xsl" href="H:\XML\课堂练习5(xsl文件).xsl"?><bookcase><book><b-name>书1</b-name><author><name>敖阳月</name><E-mail>邮箱1</E-mail></author><price>10</price><publishing-house><p-name>出版社名1</p-name><address>出版社地址1</address><zipcode>出版社编号1</zipcode><E-mail>出版社邮箱1</E-mail></publishing-house></book><book><b-name>书2</b-name><author><name>敖阳月</name><E-mail>邮箱2</E-mail></author><price>20</price><publishing-house><p-name>出版社名2</p-name><address>出版社地址2</address><zipcode>出版社编号2</zipcode><E-mail>出版社邮箱2</E-mail></publishing-house></book><book><b-name>书3</b-name><author><name>作者3</name><E-mail>邮箱3</E-mail></author><price>30</price><publishing-house><p-name>出版社名3</p-name><address>出版社地址3</address><zipcode>出版社编号3</zipcode><E-mail>出版社邮箱3</E-mail> </publishing-house></book><book><b-name>书4</b-name><author><name>作者4</name><E-mail>邮箱4</E-mail></author><price>40</price><publishing-house><p-name>出版社名4</p-name><address>出版社地址4</address><zipcode>出版社编号4</zipcode><E-mail>出版社邮箱4</E-mail> </publishing-house></book><book><b-name>书5</b-name><author><name>敖阳月</name><E-mail>邮箱5</E-mail></author><price>50</price><publishing-house><p-name>出版社名5</p-name><address>出版社地址5</address><zipcode>出版社编号5</zipcode><E-mail>出版社邮箱5</E-mail> </publishing-house></book><book><b-name>书6</b-name><author><name>作者6</name><E-mail>邮箱6</E-mail></author><price>60</price><publishing-house><p-name>出版社名6</p-name><address>出版社地址6</address><zipcode>出版社编号6</zipcode><E-mail>出版社邮箱6</E-mail></publishing-house></book></bookcase>5.XSL文件<?xml version="1.0" encoding="UTF-8"?><xsl:stylesheet version="2.0" xmlns:xsl="/1999/XSL/Transform" xmlns:fo="/1999/XSL/Format"xmlns:xs="/2001/XMLSchema"xmlns:fn="/2005/xpath-functions"><xsl:template match="/"><html><head><title>图书信息</title></head><body><center><h2>图书列表</h2><table border="5" width="80%"><tr><th>书名</th><th>作者</th><th>价格</th><th>出版社</th></tr><xsl:for-each select="bookcase/book"><xsl:sort select="price" order="descending"/><tr><td><xsl:value-of select="b-name"/></td><td><xsl:if test="author/name='敖阳月'"><xsl:attributename="style">color:blue</xsl:attribute></xsl:if><xsl:value-of select="author/name"/></td><td><xsl:if test="price>=40"><xsl:attributename="style">color:red;font-size:large</xsl:attribute></xsl:if><xsl:value-of select="price"/></td><xsl:choose><xsl:when test="publishing-house/p-name='天津出版社'"><td style="background-color:gray"><xsl:value-ofselect="publishing-house/p-name"/></td></xsl:when><xsl:otherwise><td style="background-color:yellow"><xsl:value-ofselect="publishing-house/p-name"/></td></xsl:otherwise></xsl:choose></tr></xsl:for-each></table></center></body></html></xsl:template></xsl:stylesheet>6.实验截图四、实验步骤1.CSS显示XMLa)创建一个关于图书信息的DTD文件,通过该DTD文件自动生成有6本书的XML文件;b)新建一个CSS文件,在该文件中将选择器定义为XML文件中的各标签名,并设置各属性以达到不同的显示效果;c)在XML文件的序言后添加PI指令,导入外部CSS;2.XSL显示XMLa)创建一个关于图书信息的DTD文件,通过该DTD文件自动生成有6本书的XML文件;b)新建一个XSL文件,利用XSL语法定义模板元素、选取XML文档中的数据;c)在XML文件的序言后添加PI指令,导入XSL;五、实验心得通过老师介绍CSS禅意花园,并且自己也浏览了该网站,对CSS 产生了极大的兴趣,但下载了CSS文件并仔细浏览分析后发现CSS 真的是博大精深,需要下一定的功夫去研究学习。