xsl与xml的综合应用-换色换值显示

/**

Xmlxsl的综合应用,对符合条件的数据进行换值和换颜色的显示。主要的函数调用是:

<xsl:if test=”.[value()$ge$40]”>

<xsl:attribute name=”style”>color:red</xsl:attribute>

</xsl:if>

<xsl:choose>

<xsl:when test=”.[value()$le$100]”>优秀</xsl:when>

<xsl:otherwise>不优秀</xsl:otherwise>

</xsl:choose>


*/

Document.xml

<?xml version="1.0" encoding="gb2312"?>

<?xml-stylesheet type="text/xsl" href="document.xsl"?>

<document>

<resume>

<name>大象</name>

<age>88</age>

<english>59</english>

<math>68</math>

<language>99</language>

</resume>

<resume>

<name>海龟</name>

<age>999</age>

<english>99</english>

<math>88</math>

<language>99</language>

</resume>

<resume>

<name>狮子</name>

<age>20</age>

<english>12</english>

<math>22</math>

<language>55</language>

</resume>

</document>

Document.xsl

<?xml version="1.0" encoding="gb2312"?>

<xsl:stylesheet xmlns:xsl="http://www.w3.org/TR/WD-xsl">

<xsl:template match="/">

<html>

<head>

<title>动物园成绩单</title>

</head>

<body>

<h3>动物园成绩单</h3>

<xsl:apply-templates select="document"/>

</body>

</html>

</xsl:template>

<xsl:template match="document">

<table border="1" cellspacing="0">

<tr><th>动物名</th><th>年龄</th><th>英语</th><th>数学</th><th>语文</th></tr>

<tr><xsl:apply-templates select="resume"/></tr>

</table>

</xsl:template>

<!--数据模板-->

<xsl:template match="resume">

<tr>

<td><xsl:value-of select="name"/></td>

<td><xsl:apply-templates select="age"/></td>

<td><xsl:apply-templates select="english"/></td>

<td><xsl:apply-templates select="math"/></td>

<td><xsl:apply-templates select="language"/></td>

</tr>

</xsl:template>

<!--年龄模板-->

<xsl:template match="age">

<xsl:if test=".[value()$le$100]">

<xsl:attribute name="style">color:red</xsl:attribute>

</xsl:if>

<xsl:value-of />

</xsl:template>

<!--各科成绩模板-->

<xsl:template match="english|math|language">

<xsl:choose>

<xsl:when test=".[value()$ge$90]">优秀(90-100)</xsl:when>

<xsl:when test=".[value()$ge$70]">一般(70-90)</xsl:when>

<xsl:otherwise>不合格</xsl:otherwise>

</xsl:choose>

</xsl:template>

</xsl:stylesheet>

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。

相关推荐


xml怎么加入图片路径
rss源错误怎么解决
文件后缀xml是什么意思
xml格式电子发票怎么获取
xml格式是什么意思
rss是什么意思啊
xml格式电子发票怎么打开
rss订阅源是什么意思
rss源是什么
xml注释怎么写
php输出xml格式字符串
J2ME Mobile 3D入门教程系列文章之一
XML轻松学习手册
XML入门的常见问题(一)
XML入门的常见问题(三)
XML轻松学习手册(2)XML概念
xml文件介绍及使用
xml编程(一)-xml语法
XML文件结构和基本语法
第2章 包装类