加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 百科 > 正文

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

发布时间:2020-12-16 06:35:26 所属栏目:百科 来源:网络整理
导读:/** Xml 与 xsl 的综合应用,对符合条件的数据进行换值和换颜色的显示。主要的函数调用是: 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:whe

/**

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>

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读