XML作业合集 吉林大学

第三次作业

三、请用XML语言编写描述下面的学生成绩单的XML文档并给出其DTD。本题需要提交电子版,包括文档代码,及相关说明。

平均成绩应该在xsl里面计算,这里只让写xml和dtd所以不用写

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE scoresheet SYSTEM "score.dtd">
<scoresheet>
	<student>
		<name>张三</name>
		<course>
			<title>编译方法</title>
			<score>79</score>
		</course>
		<course>
			<title>C程序设计</title>
			<score>85</score>
		</course>
		<course>
			<title>数据结构</title>
			<score>93</score>
		</course>
	</student>
	<student>
		<name>李四</name>
		<course>
			<title>计算复杂性</title>
			<score>72</score>
		</course>
		<course>
			<title>偏微分方程</title>
			<score>86</score>
		</course>
		<course>
			<title>计算方法</title>
			<score>95</score>
		</course>
	</student>
	<student>
		<name>王五</name>
		<course>
			<title>分子轨道理论</title>
			<score>79</score>
		</course>
		<course>
			<title>有机化学</title>
			<score>80</score>
		</course>
		<course>
			<title>分子生物学</title>
			<score>88</score>
		</course>
		<course>
			<title>无机化学</title>
			<score>98</score>
		</course>
	</student>
</scoresheet>
<?xml version = "1.0" encoding="GB2312"?>
<!ELEMENT scoresheet (student*)>
<!ELEMENT student (name, course*)>
<!ELEMENT name (#PCDATA)>
<!ELEMENT course (title, score)>
<!ELEMENT title (#PCDATA)>
<!ELEMENT score (#PCDATA)>

四、为班级通讯录编写DTD、XML文档,其中包含 5 名假想的联系人及相关信息。本题需要提交电子版,包括文档代码,及相关说明。

<?xml version="1.0" encoding="GB2312"?>
<!DOCTYPE contacts SYSTEM "contacts.dtd">
<contacts>
	<contact>
		<name>Ami</name>
		<address>UK</address>
		<phone>1234</phone>
	</contact>
	<contact>
		<name>Bob</name>
		<address>USA</address>
		<phone>2345</phone>
	</contact>
	<contact>
		<name>Clare</name>
		<address>Japan</address>
		<phone>3456</phone>
	</contact>
	<contact>
		<name>David</name>
		<address>China</address>
		<phone>4567</phone>
	</contact>
	<contact>
		<name>Elbert</name>
		<address>Italy</address>
		<phone>5678</phone>
	</contact>
</contacts>
<?xml version="1.0" encoding="GB2312"?>
<!ELEMENT contacts (contact*)>
<!ELEMENT contact (name, address, phone)>
<!ELEMENT name (#PCDATA)>
<!ELEMENT address (#PCDATA)>
<!ELEMENT phone (#PCDATA)>

第四次作业

一、结合数据文件 cdcatalog.xml,编写 xsl 文件以实现下面的显示效果,并且对 XML 数据做下述处理: 1. 仅显示年份大于 1980 年的 CD,并且按照年份递减进行排序; 2. 对不同价格区间的价格显示不同颜色,价格超过 10 设置表格单元背景为 红色,价格在 9~10 之间设置橙色背景,价格在 8~9 之间设置粉色背景, 价格低于 8 设置青色背景。

<?xml version="1.0" encoding="UTF-8"?>
<?xml-stylesheet href="cdcatalog.xsl" type="text/xsl"?>
<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>
	<cd>
		<title>Greatest Hits</title>
		<artist>Dolly Parton</artist>
		<country>USA</country>
		<company>RCA</company>
		<price>9.90</price>
		<year>1982</year>
	</cd>
	<cd>
		<title>Still got the blues</title>
		<artist>Gary Moore</artist>
		<country>UK</country>
		<company>Virgin records</company>
		<price>10.20</price>
		<year>1990</year>
	</cd>
	<cd>
		<title>Eros</title>
		<artist>Eros Ramazzotti</artist>
		<country>EU</country>
		<company>BMG</company>
		<price>9.90</price>
		<year>1997</year>
	</cd>
	<cd>
		<title>One night only</title>
		<artist>Bee Gees</artist>
		<country>UK</country>
		<company>Polydor</company>
		<price>10.90</price>
		<year>1998</year>
	</cd>
	<cd>
		<title>Sylvias Mother</title>
		<artist>Dr.Hook</artist>
		<country>UK</country>
		<company>CBS</company>
		<price>8.10</price>
		<year>1973</year>
	</cd>
	<cd>
		<title>Maggie May</title>
		<artist>Rod Stewart</artist>
		<country>UK</country>
		<company>Pickwick</company>
		<price>8.50</price>
		<year>1990</year>
	</cd>
	<cd>
		<title>Romanza</title>
		<artist>Andrea Bocelli</artist>
		<country>EU</country>
		<company>Polydor</company>
		<price>10.80</price>
		<year>1996</year>
	</cd>
	<cd>
		<title>When a man loves a woman</title>
		<artist>Percy Sledge</artist>
		<country>USA</country>
		<company>Atlantic</company>
		<price>8.70</price>
		<year>1987</year>
	</cd>
	<cd>
		<title>Black angel</title>
		<artist>Savage Rose</artist>
		<country>EU</country>
		<company>Mega</company>
		<price>10.90</price>
		<year>1995</year>
	</cd>
	<cd>
		<title>1999 Grammy Nominees</title>
		<artist>Many</artist>
		<country>USA</country>
		<company>Grammy</company>
		<price>10.20</price>
		<year>1999</year>
	</cd>
	<cd>
		<title>For the good times</title>
		<artist>Kenny Rogers</artist>
		<country>UK</country>
		<company>Mucik Master</company>
		<price>8.70</price>
		<year>1995</year>
	</cd>
	<cd>
		<title>Big Willie style</title>
		<artist>Will Smith</artist>
		<country>USA</country>
		<company>Columbia</company>
		<price>9.90</price>
		<year>1997</year>
	</cd>
	<cd>
		<title>Tupelo Honey</title>
		<artist>Van Morrison</artist>
		<country>UK</country>
		<company>Polydor</company>
		<price>8.20</price>
		<year>1971</year>
	</cd>
	<cd>
		<title>Soulsville</title>
		<artist>Jorn Hoel</artist>
		<country>Norway</country>
		<company>WEA</company>
		<price>7.90</price>
		<year>1996</year>
	</cd>
	<cd>
		<title>The very best of</title>
		<artist>Cat Stevens</artist>
		<country>UK</country>
		<company>Island</company>
		<price>8.90</price>
		<year>1990</year>
	</cd>
	<cd>
		<title>Stop</title>
		<artist>Sam Brown</artist>
		<country>UK</country>
		<company>A and M</company>
		<price>8.90</price>
		<year>1988</year>
	</cd>
	<cd>
		<title>Bridge of Spies</title>
		<artist>T`Pau</artist>
		<country>UK</country>
		<company>Siren</company>
		<price>7.90</price>
		<year>1987</year>
	</cd>
	<cd>
		<title>Private Dancer</title>
		<artist>Tina Turner</artist>
		<country>UK</country>
		<company>Capitol</company>
		<price>8.90</price>
		<year>1983</year>
	</cd>
	<cd>
		<title>Midt om natten</title>
		<artist>Kim Larsen</artist>
		<country>EU</country>
		<company>Medley</company>
		<price>7.80</price>
		<year>1983</year>
	</cd>
	<cd>
		<title>Pavarotti Gala Concert</title>
		<artist>Luciano Pavarotti</artist>
		<country>UK</country>
		<company>DECCA</company>
		<price>9.90</price>
		<year>1991</year>
	</cd>
	<cd>
		<title>The dock of the bay</title>
		<artist>Otis Redding</artist>
		<country>USA</country>
		<company>Atlantic</company>
		<price>7.90</price>
		<year>1987</year>
	</cd>
	<cd>
		<title>Picture book</title>
		<artist>Simply Red</artist>
		<country>EU</country>
		<company>Elektra</company>
		<price>7.20</price>
		<year>1985</year>
	</cd>
	<cd>
		<title>Red</title>
		<artist>The Communards</artist>
		<country>UK</country>
		<company>London</company>
		<price>7.80</price>
		<year>1987</year>
	</cd>
	<cd>
		<title>Unchain my heart</title>
		<artist>Joe Cocker</artist>
		<country>USA</country>
		<company>EMI</company>
		<price>8.20</price>
		<year>1987</year>
	</cd>
</catalog>
<?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>
				<table border="1">
					<tr bgcolor="YellowGreen">
						<th align="left">Title</th>
						<th align="left">Artist</th>
						<th align="left">Price</th>
						<th align="left">Year</th>
					</tr>
					<xsl:for-each select="catalog/cd[year &gt; 1980]">
					<xsl:sort select="year" order="descending" />
						<tr>
							<td>
								<xsl:value-of select="title" />
							</td>
							<td>
								<xsl:value-of select="artist" />
							</td>
							<xsl:choose>
								<xsl:when test="price &gt; 10">
									<td bgcolor="red">
										<xsl:value-of select="price" />
									</td>
								</xsl:when>
								<xsl:when test="price &lt; 10 and price &gt; 9">
									<td bgcolor="orange">
										<xsl:value-of select="price" />
									</td>
								</xsl:when>
								<xsl:when test="price &lt; 9 and price &gt; 8">
									<td bgcolor="pink">
										<xsl:value-of select="price" />
									</td>
								</xsl:when>
								<xsl:when test="price &lt; 8">
									<td bgcolor="aqua">
										<xsl:value-of select="price" />
									</td>
								</xsl:when>
								<xsl:otherwise>
									<td>no</td>
								</xsl:otherwise>
							</xsl:choose>
							<td>
								<xsl:value-of select="year" />
							</td>
						</tr>
					</xsl:for-each>
				</table>
			</body>
		</html>
	</xsl:template>
</xsl:stylesheet>

二、按照下面图片,编写学生成绩单的 XML 以及 XSL 文件,要求把平均成绩表 格的设置信息(如 rowspan)也写入XML 文件中

<?xml version="1.0" encoding="UTF-8"?>
<?xml-stylesheet href="score.xsl" type="text/xsl"?>
<scoresheet>
	<student>
		<name>张三</name>
		<course>
			<title>编译方法</title>
			<score>79</score>
			<time>2021/12/06</time>
		</course>
		<course>
			<title>C程序设计</title>
			<score>85</score>
			<time>2021/12/04</time>
		</course>
		<course>
			<title>数据结构</title>
			<score>93</score>
			<time>2021/12/10</time>
		</course>
		<rowspan>3</rowspan>
	</student>
	<student>
		<name>李四</name>
		<course>
			<title>计算复杂性</title>
			<score>72</score>
			<time>2021/12/03</time>
		</course>
		<course>
			<title>偏微分方程</title>
			<score>86</score>
			<time>2021/12/07</time>
		</course>
		<course>
			<title>计算方法</title>
			<score>95</score>
			<time>2021/12/04</time>
		</course>
		<rowspan>3</rowspan>
	</student>
	<student>
		<name>王五</name>
		<course>
			<title>分子轨道理论</title>
			<score>79</score>
			<time>2021/12/23</time>
		</course>
		<course>
			<title>有机化学</title>
			<score>80</score>
			<time>2021/12/09</time>
		</course>
		<course>
			<title>分子生物学</title>
			<score>88</score>
			<time>2021/11/27</time>
		</course>
		<course>
			<title>无机化学</title>
			<score>98</score>
			<time>2021/12/15</time>
		</course>
		<rowspan>4</rowspan>
	</student>
</scoresheet>
<?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>
				<table border="1">
					<caption>学生成绩表</caption>
					<tr>
						<td>姓名</td>
						<td>平均成绩</td>
						<td>课程名称</td>
						<td>单科成绩</td>
						<td>录入时间</td>
					</tr>
					<xsl:for-each select="//student">
						<xsl:for-each select="course">
							<xsl:sort select="score" />
							<tr>
								<xsl:if test="position()=1">
									<td>
										<xsl:attribute name="rowspan">
											<xsl:value-of select = "../rowspan"/>
										</xsl:attribute>
										<xsl:value-of select="../name" />
									</td>
									<td>
										<xsl:attribute name="rowspan">
											<xsl:value-of select = "../rowspan"/>
										</xsl:attribute>
										<xsl:value-of select="format-number(sum(../course/score) div count(../course),'##.00')" />
									</td>
								</xsl:if>
								<td>
									<xsl:value-of select="title" />
								</td>
								<td align="right">
									<xsl:value-of select="score" />
								</td>
								<td>
									<xsl:value-of select="time" />
								</td>
							</tr>
						</xsl:for-each>
					</xsl:for-each>
				</table>
			</body>
		</html>
	</xsl:template>
</xsl:stylesheet>

三、请给出描述下面通讯名录的格式良好的 XML 文档,给出其类型定义 DTD 文 档,以及转化 HTML 的样式 XSL 文档。

<?xml version="1.0" encoding="UTF-8"?>
<!ELEMENT contacts (contact*)>
<!ELEMENT contact (name, id, sex, address, phone*)>
<!ELEMENT name (#PCDATA)>
<!ELEMENT id (#PCDATA)>
<!ELEMENT sex (#PCDATA)>
<!ELEMENT address (#PCDATA)>
<!ELEMENT phone (number, type)>
<!ELEMENT number (#PCDATA)>
<!ELEMENT type (#PCDATA)>
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE contacts SYSTEM "contact.dtd">
<?xml-stylesheet href="contact.xsl" type="text/xsl"?>
<contacts>
	<contact>
		<name>李倩倩</name>
		<id>10191101</id>
		<sex>女</sex>
		<address>前卫胡同 126 号</address>
		<phone>
			<number>88662255</number>
			<type>住宅</type>
		</phone>
		<phone>
			<number>13012345678</number>
			<type>移动电话</type>
		</phone>
	</contact>
	<contact>
		<name>王晓明</name>
		<id>10191203</id>
		<sex>男</sex>
		<address>北京大街 103 号</address>
		<phone>
			<number>85943212</number>
			<type>办公</type>
		</phone>
	</contact>
</contacts>
<?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>
				<table border="1px" cellspacing="0">
					<tr>
						<td>姓名</td>
						<td>会员编号</td>
						<td>性别</td>
						<td>地址</td>
						<td>电话号码</td>
						<td>电话类型</td>
					</tr>
					<xsl:for-each select="//contact">
						<xsl:for-each select="phone">
							<tr>
								<xsl:if test="position()=1">
									<td>
										<xsl:attribute name="rowspan">
											<xsl:value-of select="count(../phone)" />
										</xsl:attribute>
										<xsl:value-of select="../name" />
									</td>
									<td>
										<xsl:attribute name="rowspan">
											<xsl:value-of select="count(../phone)" />
										</xsl:attribute>
										<xsl:value-of select="../id" />
									</td>
									<td>
										<xsl:attribute name="rowspan">
											<xsl:value-of select="count(../phone)" />
										</xsl:attribute>
										<xsl:value-of select="../sex" />
									</td>
									<td>
										<xsl:attribute name="rowspan">
											<xsl:value-of select="count(../phone)" />
										</xsl:attribute>
										<xsl:value-of select="../address" />
									</td>
								</xsl:if>
								<td>
									<xsl:value-of select="number" />
								</td>
								<td>
									<xsl:value-of select="type" />
								</td>
							</tr>
						</xsl:for-each>
					</xsl:for-each>
				</table>
			</body>
		</html>
	</xsl:template>
</xsl:stylesheet>

第五次作业

已知描述学生成绩的XML文档(students_exam_results.xml)请利用XMLDOM和XSLT编写如下的网页, 通过选择姓名来动态显示每个学生的成绩单。

var xmlDoc;
var xslDoc;
var maxLen = 0;
var idx = 0;
function init() {
	xmlDoc = loadXMLDoc("students_exam_results.xml"); 
	xslDoc = loadXMLDoc("show.xsl");
	nodes = xmlDoc.selectNodes("//student"); 
	maxLen = nodes.length - 1; 
	display();
}

function display(){
	if(maxLen>0){
		var node=nodes[idx];
		content.innerHTML=node.transformNode(xslDoc);
	}
}

function show(num) {
	idx=num-1;
	display();
}

function loadXMLDoc(dname) {
	var xmlDoc = null; try {//Internet Explorer 
		xmlDoc = new ActiveXObject("Microsoft.XMLDOM");
	} catch (e) {
		try {//Firefox, Mozilla, Opera, etc. 
			xmlDoc=document.implementation.createDocument("","",null)
		} catch (e) {
			alert(e.message)
		}
	} try {
		xmlDoc.async = false; xmlDoc.load(dname); return (xmlDoc);
	} catch (e) {
		alert(e.message)
	} return (xmlDoc);
}
<!DOCTYPE html>
<html lang="en">

<head>
	<meta charset="UTF-8">
	<title>学生成绩单</title>
	<script type="text/javascript" src="score.js"></script>
</head>

<body onload="init();">
	<p>学生成绩单</p>
	姓名:
	<select name="name" id="name">
		<option onclick="show(1)">张三</option>
		<option onclick="show(2)">李四</option>
		<option onclick="show(3)">王五</option>
	</select>
	<div id="content"></div>
</body>

</html>
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
	<xsl:template match="student">
		<html>
			<body>
				<span>
					学院:
					<xsl:value-of select="dept"></xsl:value-of>
				</span>
				<p></p>
				<table border="1">
					<tr>
						<th>课程名称</th>
						<th>考试日期</th>
						<th>成绩</th>
					</tr>
					<xsl:for-each select="course">
						<tr>
							<td>
								<xsl:value-of select="title" />
							</td>
							<td>
								<xsl:value-of select="date" />
							</td>
							<td>
								<xsl:value-of select="score" />
							</td>
						</tr>
					</xsl:for-each>
				</table>
			</body>
		</html>
	</xsl:template>
</xsl:stylesheet>
<?xml version="1.0" encoding="UTF-8"?>
<scoresheet>
	<student>
		<name>张三</name>
		<dept>计算机</dept>
		<course>
			<title>C程序设计</title>
			<date>2000/12/04</date>
			<score>85</score>
		</course>
		<course>
			<title>编译方法</title>
			<date>2000/12/06</date>
			<score>79</score>
		</course>
		<course>
			<title>数据结构</title>
			<date>2000/12/10</date>
			<score>93</score>
		</course>
	</student>
	<student>
		<name>李四</name>
		<dept>数学</dept>
		<course>
			<title>计算方法</title>
			<date>2000/12/04</date>
			<score>95</score>
		</course>
		<course>
			<title>偏微分方程</title>
			<date>2000/12/07</date>
			<score>86</score>
		</course>
		<course>
			<title>计算复杂性</title>
			<date>2000/12/03</date>
			<score>72</score>
		</course>
	</student>
	<student>
		<name>王五</name>
		<dept>化学</dept>
		<course>
			<title>有机化学</title>
			<date>2000/12/09</date>
			<score>80</score>
		</course>
		<course>
			<title>无机化学</title>
			<date>2000/12/15</date>
			<score>98</score>
		</course>
		<course>
			<title>分子轨道理论</title>
			<date>2000/12/23</date>
			<score>79</score>
		</course>
		<course>
			<title>分子生物学</title>
			<date>2000/11/27</date>
			<score>88</score>
		</course>
	</student>
	
</scoresheet>

第六次作业

编写XSLT 文档以及ASP/PHP 代码,显示下面的简历

<?xml version="1.0" encoding="utf-8" standalone="no"?>
<?xml-stylesheet type="text/xsl" href="resume.xsl"?>
<学生>
	<个人基本信息>
		<照片>miffy.jpg</照片>
		<姓名>米菲</姓名>
		<性别>女</性别>
		<民族>兔佳族</民族>
		<出生地>大荷兰</出生地>
		<通讯地址>
			<条目>130012</条目>
			<条目>吉林省长春市前进大街 2699 号</条目>
			<条目>吉林大学计算机科学与技术学院</条目>
		</通讯地址>
		<电子邮件>miffy@yahoo.com</电子邮件>
	</个人基本信息>
	<学历和工作简历>
		<条目>2003 年毕业于吉林大学附属小学</条目>
		<条目>2006 年毕业于吉林大学附属中学初中部</条目>
		<条目>2009 年毕业于吉林大学附属中学高中部</条目>
		<条目>2013 年毕业于吉林大学计算机学院</条目>
		<条目>2012.07 至 2012.09 在吉林大学就业指导中心实习</条目>
	</学历和工作简历>
	<已修课程>
		<条目>数据结构</条目>
		<条目>数据库原理</条目>
		<条目>C语言程序设计</条目>
		<条目>Java 语言程序设计</条目>
		<条目>Web 应用开发基础</条目>
		<条目>XML语言</条目>
	</已修课程>
	<已获奖励>
		<条目>2012 获中国大学生创新项目一等奖</条目>
		<条目>2013 获中国大学生软件竞赛一等奖</条目>
	</已获奖励>
	<已发表论文>
		<条目>人机对话中关键技术的探索,2011 年发表于《机器与人》创刊号第 1 页</条目>
		<条目>米菲家族祖先追踪,2012 年发表于《物种起源》卷 99999 第 8888 页</条目>
	</已发表论文>
</学生>
<?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 bgcolor="E0FFFF">
                <font face="STXinwei">
                <h3 align = "center">米菲的简历</h3>
                <table border="1" align = "center" cellpadding="10"><!--CCFFFF-->
                <tr>
                    <td bgcolor="#5F9EA0" width = "70" align = "center">姓名</td>
            <td bgcolor="#E0FFFF" width = "300"><xsl:value-of select="/学生/个人基本信息/姓名"/></td>
            <td rowspan="6">
                        <img>
                            <xsl:attribute name="src"><xsl:value-of select="/学生/个人基本信息/照片"/></xsl:attribute>
                        </img>
                    </td>
                </tr>
                <tr>
                    <td bgcolor="#5F9EA0" align = "center">性别</td>
                    <td bgcolor="#E0FFFF"><xsl:value-of select="/学生/个人基本信息/性别"/></td>
                </tr>
                <tr>
                    <td bgcolor="#5F9EA0" align = "center">民族</td>
                    <td bgcolor="#E0FFFF"><xsl:value-of select="/学生/个人基本信息/民族"/></td>
                </tr>
                <tr>
                    <td bgcolor="#5F9EA0" align = "center">出生地</td>
                    <td bgcolor="#E0FFFF"><xsl:value-of select="/学生/个人基本信息/出生地"/></td>
                </tr>
                <tr>
                    <td bgcolor="#5F9EA0" align = "center">通讯地址</td>
                    <td bgcolor="#E0FFFF">
                        <xsl:for-each select="/学生/个人基本信息/通讯地址/条目">
                            <ul>
                                <li><xsl:value-of select="."/></li>
                            </ul>
                        </xsl:for-each>
                    </td>
                </tr>
                <tr>
                    <td bgcolor="#5F9EA0" align = "center">电邮</td>
                    <td bgcolor="#E0FFFF"><xsl:value-of select="/学生/个人基本信息/电子邮件"/></td>
                </tr>
                <tr>
                    <td bgcolor="#5F9EA0" align = "center" colspan = "3">学历和工作简历</td>
                </tr>
                <tr>
                    <td bgcolor="#E0FFFF" colspan = "3">
                        <xsl:for-each select="/学生/学历和工作简历/条目">
                            <ul>
                                <li><xsl:value-of select="."/></li>
                            </ul>
                        </xsl:for-each>
                    </td>
                </tr>
                <tr>
                    <td bgcolor="#5F9EA0" align = "center" colspan = "3">已修课程</td>
                </tr>
                <tr>
                    <td bgcolor="#E0FFFF" colspan = "3">
                        <xsl:for-each select="/学生/已修课程/条目">
                            <ul>
                                <li><xsl:value-of select="."/></li>
                            </ul>
                        </xsl:for-each>
                    </td>
                </tr>
                <tr>
                    <td bgcolor="#5F9EA0" align = "center" colspan = "3">已获奖励</td>
                </tr>
                <tr>
                    <td bgcolor="#E0FFFF" colspan = "3">
                        <xsl:for-each select="/学生/已获奖励/条目">
                            <ol>
                                <li><xsl:value-of select="."/></li>
                            </ol>
                        </xsl:for-each>
                    </td>
                </tr>
                <tr>
                    <td bgcolor="#5F9EA0" align = "center" colspan = "3">已发表论文</td>
                </tr>
                <tr>
                    <td bgcolor="#E0FFFF" colspan = "3">
                        <xsl:for-each select="/学生/已发表论文/条目">
                            <ol>
                                <li><xsl:value-of select="."/></li>
                            </ol>
                        </xsl:for-each>
                    </td>
                </tr>
                </table>>
                </font>
            </body>
        </html>
    </xsl:template>
</xsl:stylesheet>
<%@ language=VBScript %>
<%
  '定义使用的变量
  dim xmldoc,xsldoc,result
  
  '创建DOMDocument对象实例xmldoc
  '将使用xmldoc来加载需要转换的XML文档
  set  xmldoc=Server.createObject("Microsoft.XMLDOM")
  
  '设置并不同步加载XML文档
  xmldoc.async=false
  
  '加载XML文档
  xmldoc.load(Server.MapPath("resume.xml"))
  
  '判断加载的XML文档是否有错,有则输出错误原因
  if (xmldoc.parseError.errorCode<>0) then
    Response.write("发生错误:"+xmldoc.parseError.reason)
	Response.End
  end if
 
  '创建DOMDocument对象实例xsldoc
  '将使用xsldoc来加载转换XML文档使用的样式单
  set xsldoc=Server.createObject("Microsoft.XMLDOM")
  xsldoc.async=false
  
  '加载样式单
  xsldoc.load(Server.MapPath("resume.xsl"))
  
  '判断样式单中是否有错,有则输出出错原因
  if(xsldoc.parseError.errorCode<>0) then
    Response.write("发生错误:"+xsldoc.parseError.reason)
	Response.End
  end if
  
  '使用样式单转换XML文档
  result=xmldoc.transformNode(xsldoc)
  
  '输出转换结果
  Response.write(result)
 %>

第七次作业(大作业)

每位同学设计并开发一组网页,其中包含 3 个部分:自我介绍+电影/书籍/兴趣 爱好介绍+景观介绍。
1.网页内容包括: (1)自我介绍部分请用表格或其他形式说明自己的学号、班级、姓名,以及对 自己做一个简介; (2)电影/书籍介绍自己读过的书籍,电影,以及兴趣爱好(一共 3 样),包含 书籍电影的内容简介、截图,自己对书籍电影的评价等等; (3)景观介绍包括至少 3 处景点,可以是家乡或者曾经去过的景点,每处大约 100 字左右的文字介绍,每处景点包含 2~5 张照片
2.要求数据和显示网页分离,使用 XML 保存数据,例如自己的学号、班级、姓 名,电影,书籍以及相关图片的信息,并结合 XSL,ASP,PHP 转换成HTML;
3.所开发的网页具有的一定的操作互动,例如通过按钮、下拉列表选择书籍、电 影及景点,等等。
4.可选功能:留言簿功能,用户可以发表评论
5.提交代码和网页运行效果截图,并且把代码、效果截图都写一个文档中,对网 页的设计、开发和测试做出说明,描述如何实现的数据与显示页面相互分离,如 何实现互动操作,等等。

<!DOCTYPE html>
<html>
<head lang="zh">
	<meta charset='utf-8'>
	<title>?</title>
	<meta name='viewport' content='width=device-width, initial-scale=1'>
</head>
<body>
	<table align = "center" border="0">
		<tr><td><p>学号:</p></td></tr>
		<tr><td><p>姓名:</p></td></tr>
		<tr><td><p>爱好:</p></td></tr>
		<tr><td>
			<form action="i.php" method="get">
				<span>
					请从右侧选择要查询的主题
					<select name="theme" id="theme">
						<option value="0" selected>书籍</option>
						<option value="1">电影</option>
						<option value="2">景点</option>
					</select>
					<input type="submit" value="查询">
				</span>
			</form>
		</td></tr>
	</table>
</body>
</html>
<?xml version="1.0" encoding="UTF-8"?>
<me>
	<books>
		<book>
			<btitle>Pride and Prejudice</btitle>
			<bintro>Pride and Prejudice is a full-length novel written by English novelist Jane Austen. &#x000A; The novel depicts the five daughters of the young squire Bennet, the main character is the second daughter Elizabeth. She meets Darcy at a ball, but he is heard to be arrogant and has been repulsed by him. After some twists and turns, Elizabeth is relieved of her prejudice against Darcy, and Darcy puts aside his arrogance.</bintro>
			<bpic>bpics/PP1.jpg</bpic>
			<bcomment>good</bcomment>
		</book>
		<book>
			<btitle>Sense and Sensibility</btitle>
			<bintro>Sense and Sensibility is a full-length novel written by English author Jane Austen. It tells the story of two sisters, Eleanor and Marianne, born in an English squire family, the sister is good at using reason to control emotions, but the sister's emotions are unrestrained, so when faced with love, they made different reactions.</bintro>
			<bpic>bpics/SS1.jpg</bpic>
			<bcomment>great</bcomment>
		</book>
	</books>
	<movies>
		<movie>
			<mtitle>Pride and Prejudice</mtitle>
			<mintro>Pride and Prejudice is a romance film based on Jane Austen's novel of the same name and distributed by Focus Features, directed by Joe White and co-starring Keira Knightley, Matthew McFayden and Donald Sutherland. The film was released in the UK on September 16, 2005. The film tells the story of the love and choice of spouses of the five Elizabeth Bennet sisters, the daughters of a country squire in early 19th century England.</mintro>
			<mpic>mpics/PP.jpg</mpic>
			<mcomment>good</mcomment>
		</movie>
		<movie>
			<mtitle>Sense and Sensibility</mtitle>
			<mintro>Sense and Sensibility" is a romantic film directed by Ang Lee, starring James Frett, Harriet Walter, Kate Winslet and Alan Rickman, based on the novel of the same name by English author Jane Austen. The film tells the story of an English estate owner who died, due to the inheritance law that the family property is only passed on to men but not women, his daughters are facing the fate of sweeping out of the house, married a good husband has become their urgent needs. The eldest daughter hides her personal feelings for her children for the sake of the family's happiness; the youngest daughter is willing to pay for the pursuit of love. In the end, both "reason" and "emotion" get true love.</mintro>
			<mpic>mpics/SS.jpg</mpic>
			<mcomment>great</mcomment>
		</movie>
	</movies>
	<attractions>
		<attraction>
			<aname>香榭丽舍大道(Avenue des Champs - Elysées)</aname>
			<aintro>法国巴黎的香榭丽舍大道位于卢浮宫与新凯旋门连心中轴线上,又被称为凯旋大道,是世界三大繁华中心大街之一,也被人们称作世界十大魅力步行街。她横贯首都巴黎的东西主干道,全长1800米,最宽处约120米,为双向八车道,东起协和广场,西至戴高乐广场(又称星形广场),东段以自然风光为主;两侧是平坦的英氏草坪,恬静安宁;西段是高级商业区,世界名牌、服装店、香水店都集中在这里,火树银花、雍容华贵。因此这里被称为“世界上美丽的大街”。每年七月十四号的法国国庆大阅兵都在这条大道上举行。</aintro>
			<apic><url>apics/xxls1.jpg</url></apic>
			<apic><url>apics/xxls2.jpg</url></apic>
		</attraction>
		<attraction>
			<aname>圣母百花大教堂(Basilica di Santa Maria del Fiore)</aname>
			<aintro>圣母百花大教堂(Basilica di Santa Maria del Fiore),又名花之圣母大教堂,佛罗伦萨大教堂,是世界五大教堂之一。佛罗伦萨在意大利语中意为花之都,大诗人徐志摩把它译作“翡冷翠”,这个译名远远比另一个译名“佛罗伦萨”来的更富诗意,更多色彩,也更符合古城的气质。教堂位于意大利佛罗伦萨历史中心城区,教堂建筑群由大教堂、钟塔与洗礼堂构成,1982年作为佛罗伦萨历史中心的一部分被列入世界文化遗产。</aintro>
			<apic><url>apics/smbh1.jpg</url></apic>
			<apic><url>apics/smbh2.jpg</url></apic>
			<apic><url>apics/smbh3.jpg</url></apic>
		</attraction>
		<attraction>
			<aname>鸣沙山</aname>
			<aintro>鸣沙山为鸣沙山月牙泉风景名胜区,为国家AAAAA级旅游景区。 &#x000A; 鸣沙山以沙动成响而得名。东汉称沙角山,俗名神沙山,晋代始称鸣沙山,其山东西长40余公里,南北宽约20公里,主峰海拔1715米。峰恋危峭,山脊如刃,经缩复初;人乘沙流,有鼓角之声,轻若丝竹,重若雷鸣,此即“沙岭晴鸣”。</aintro>
			<apic><url>apics/mss1.jpg</url></apic>
			<apic><url>apics/mss2.jpg</url></apic>
			<apic><url>apics/mss3.jpg</url></apic>
		</attraction>
	</attractions>
</me>
<?php
if($_GET["theme"]==0){
	$xslDoc = new DOMDocument(); 
	$xslDoc->load("book.xsl");
	$xmlDoc = new DOMDocument(); 
	$xmlDoc->load("i.xml");
	//进行XSL转换 
	$proc = new XSLTProcessor(); 
	$proc->importStylesheet($xslDoc); 
	echo $proc->transformToXML($xmlDoc);
}
elseif($_GET["theme"]==1){
	$xslDoc = new DOMDocument(); 
	$xslDoc->load("movie.xsl");
	$xmlDoc = new DOMDocument(); 
	$xmlDoc->load("i.xml");
	//进行XSL转换 
	$proc = new XSLTProcessor(); 
	$proc->importStylesheet($xslDoc); 
	echo $proc->transformToXML($xmlDoc);
}
else{
	$xslDoc = new DOMDocument(); 
	$xslDoc->load("attraction.xsl");
	$xmlDoc = new DOMDocument(); 
	$xmlDoc->load("i.xml");
	//进行XSL转换 
	$proc = new XSLTProcessor(); 
	$proc->importStylesheet($xslDoc); 
	echo $proc->transformToXML($xmlDoc);
}
?>
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
	<xsl:template match="me">
		<html>
			<body>
				<xsl:for-each select="books/book">
				<table align = "center" border="0" width="900px">
					<tr><td colspan="2" align="center"><h3><xsl:value-of select="btitle"></xsl:value-of></h3></td></tr>
						<tr>
							<td>
								<xsl:element name="img">
									<xsl:attribute name="src">
										<xsl:value-of select="bpic"></xsl:value-of>
									</xsl:attribute>
								</xsl:element>
							</td>
							<td>
								<xsl:value-of select="bintro"></xsl:value-of>
							</td>
						</tr>
						<tr>
							<td colspan="2">comment: <xsl:value-of select="bcomment"></xsl:value-of></td>
						</tr>
					</table>
				</xsl:for-each>
			</body>
		</html>
	</xsl:template>
</xsl:stylesheet>
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
	<xsl:template match="me">
		<html>
			<body>
				<xsl:for-each select="movies/movie">
				<table align = "center" border="0" width="900px">
					<tr><td colspan="2" align="center"><h3><xsl:value-of select="mtitle"></xsl:value-of></h3></td></tr>
						<tr>
							<td>
								<xsl:element name="img">
									<xsl:attribute name="src">
										<xsl:value-of select="mpic"></xsl:value-of>
									</xsl:attribute>
								</xsl:element>
							</td>
							<td>
								<xsl:value-of select="mintro"></xsl:value-of>
							</td>
						</tr>
						<tr>
							<td colspan="2">comment: <xsl:value-of select="mcomment"></xsl:value-of></td>
						</tr>
					</table>
				</xsl:for-each>
			</body>
		</html>
	</xsl:template>
</xsl:stylesheet>
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
	<xsl:template match="me">
		<html>
			<body>
				<xsl:for-each select="attractions/attraction">
				<table align = "center" border="0" width="900px">
					<tr><td align="center"><h3><xsl:value-of select="aname"></xsl:value-of></h3></td></tr>
					<tr><td><xsl:value-of select="aintro"></xsl:value-of></td></tr>
					<xsl:for-each select="apic">
						<tr>
							<td>
								<xsl:element name="img">
									<xsl:attribute name="src">
										<xsl:value-of select="url"></xsl:value-of>
									</xsl:attribute>
								</xsl:element>
							</td>
						</tr>
					</xsl:for-each>
				</table>
				</xsl:for-each>
			</body>
		</html>
	</xsl:template>
</xsl:stylesheet>
posted @ 2022-11-22 20:31  小橘A  阅读(364)  评论(1编辑  收藏  举报