文章详情页
让Asp与XML交互
导读:小编很懒,空空如也...
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文件中
标签:
XML/RSS
相关文章:
1. CSS3实例分享之多重背景的实现(Multiple backgrounds)2. intellij idea中spring boot properties文件不能自动提示问题解决3. Android自定义Dialog框样式4. 使用Canal实现PHP应用程序与MySQL数据库的实时数据同步5. 一篇文章带你了解JavaScript-语句6. 详解IDEA搭建springBoot方式一(推荐)7. asp.net core服务限制堆内存大小的操作方法8. intellij idea写Python教程9. Android Studio导入jar包过程详解10. IntelliJ IDEAx导出安卓(Android)apk文件图文教程
排行榜