xml是标准扩展语言,是未来web编程的标准,asp是现在广为流传的web编程语言之一,能不能让他们两个联合起来发挥作用呢?豆腐在这里给大家提供一个很简单的例子关于xml和xsl限于篇幅和知识水平豆腐
xml 是标准扩展语言,是未来web编程的标准,asp 是现在广为流传的web编程语言之一,能不能让他们两个联合起来发挥作用呢?豆腐在这里给大家提供一个很简单的例子关于xml和xsl限于篇幅和知识水平豆腐就不在这里献丑了下面首先来说说几个需要用到的文件的内容
testxsl.xsl:
<?xml version='1.0'?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/tr/wd-xsl">
<xsl:template match="/">
<html>
<body>
<xsl:for-each select="personnel/person">
<xsl:choose>
<xsl:when match=".[fg='boy']">
<input type="text">
<xsl:attribute name="value">
<xsl:value-of select="name"/>
</xsl:attribute>
</input>
<br/>
</xsl:when>
<xsl:otherwise match=".[fg='girl']">
<font color="red"><li><xsl:value-of select="name"/></li></font>
<br/>
</xsl:otherwise>
<xsl:otherwise>
<font color="blue"><xsl:value-of select="name"/></font>
</xsl:otherwise>
</xsl:choose>
</xsl:for-each>
</body>
</html>
</xsl:template>
</xsl:stylesheet>
testxml.xml:
<?xml version="1.0" encoding="gb2312" ?>
<personnel>
<person>
<name>男性</name>
<fg>boy</fg>
</person>
<person>
<name>女性</name>
<fg>girl</fg>
</person>
<person>
<name>呵呵,这个可不好说</name>
<fg>donot know</fg>
</person>
</personnel>
testxml.asp
<%
set xml = server.createobject("microsoft.xmldom")
xml.async = false
xml.load(server.mappath("testxml.xml"))
set xsl = server.createobject("microsoft.xmldom")
xsl.async = false
xsl.load(server.mappath("testxsl.xsl"))
response.write(xml.transformnode(xsl))
%>
对照这个例子,我们主要来讲一下 testxml.asp 文件
set xml = server.createobject("microsoft.xmldom")
set xsl = server.createobject("microsoft.xmldom")
用来分别创建一个xml和xsl的实例,其中xml.load(server.mappath("testxml.xml"))用来加载
包含数据的xml文件,xsl.load(server.mappath("testxsl.xsl"))用来加载包含数据规则的xsl
文件,最终利用xml.transformnode(xsl)将前面的规则使用在xml文件中
版权声明:本文内容由互联网用户贡献,该文观点仅代表作者本人。本站仅提供信息存储服务,不拥有所有权,不承担相关法律责任。
如发现本站有涉嫌抄袭侵权/违法违规的内容, 请发送邮件至 2386932994@qq.com 举报,一经查实将立刻删除。
发表评论