通过javascript xml xsl取值及数据修改第1/2页的实例详解
1.example.xml--主要数据文件
<?xml version="1.0" encoding="UTF-8"?> <?xml:stylesheet type="text/xsl" href="example.xsl"?> <projects id="1"> <project title="一级标题1" index="1"> <items isTrunk="false" title="二级标题1.1" id="items_1"> <result type="2">1</result> <officer><![CDATA[]]></officer> <classified>1</classified> <eligibility>0</eligibility> <remark></remark> </items> <items isTrunk="false" title="二级标题1.2" id="items_2"> <result type="2">3</result> <officer><![CDATA[]]></officer> <classified>1</classified> <eligibility>0</eligibility> </items> </project> <project title="一级标题2" index="2"> <items isTrunk="false" title="二级标题2.1" id="items_3"> <result type="3">3</result> <officer><![CDATA[]]></officer> <classified>1</classified> <eligibility>0</eligibility> </items> <items isTrunk="true" title="二级标题2.2"> <item title="三级标题2.2.1" id="item_1"> <result type="1">2</result> <officer><![CDATA[居然是乱码]]></officer> <classified>1</classified> <eligibility>0</eligibility> </item> <item title="三级标题2.2.2" id="item_2"> <result type="1">3</result> <officer><![CDATA[<><>]]></officer> <classified>1</classified> <eligibility>0</eligibility> </item> </items> <items isTrunk="true" title="二级标题2.3"> <item title="三级标题2.3.1" id="item_3"> <result type="2">1</result> <officer><![CDATA[]]></officer> <classified>1</classified> <eligibility>0</eligibility> </item> <item title="三级标题2.3.2" id="item_4"> <result type="2">1</result> <officer><![CDATA[]]></officer> <classified>1</classified> <eligibility>0</eligibility> </item> </items> </project> <project title="一级标题3" index="3"> <items isTrunk="false" title="二级标题3.1" id="items_4"> <result type="4" units="元">25345</result> <officer><![CDATA[sinoly]]></officer> <classified>1</classified> <eligibility>0</eligibility> </items> <items isTrunk="false" title="二级标题3.2" id="items_5"> <result type="4" units="元">9865764</result> <officer><![CDATA[]]></officer> <classified>1</classified> <eligibility>0</eligibility> </items> <items isTrunk="false" title="二级标题3.3" id="items_6"> <result type="2">0</result> <officer><![CDATA[]]></officer> <classified>1</classified> <eligibility>0</eligibility> </items> <items isTrunk="true" title="二级标题3.4"> <item title="三级标题3.4.1" id="item_5"> <result type="1">0</result> <officer><![CDATA[]]></officer> <classified>1</classified> <eligibility>0</eligibility> </item> <item title="三级标题3.4.2" id="item_6"> <result type="1">0</result> <officer><![CDATA[]]></officer> <classified>1</classified> <eligibility>0</eligibility> </item> <item title="三级标题3.4.3" id="item_7"> <result type="1">0</result> <officer><![CDATA[]]></officer> <classified>1</classified> <eligibility>0</eligibility> </item> </items> </project> </projects>
2.example.xsl--样式文件,很方便的取到xml数据
<?xml version="1.0" encoding="gb2312"?> <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"> <!--根模板--> <xsl:output method="xml"/> <xsl:template match="/"> <xsl:apply-templates select="projects/project"/> <h6> <button type="submit" class="btn1_mouseout" onmouseover="this.className='btn1_mouseover'" onmouseout="this.className='btn1_mouseout'" title="提交"> 下一步</button> </h6> </xsl:template> <!--主题模板--> <xsl:template match="project"> <TABLE border="0" cellspacing="0" cellpadding="0" class="table"> <tr> <td colspan="5" align="center" class="tright"> <h2> <xsl:number value="position()" format="一、"/><xsl:value-of select="@title"/> </h2> </td> </tr> <xsl:apply-templates select="items"/> </TABLE> <BR/> </xsl:template> <!--一级题干模板--> <xsl:template match="items"> <tr> <td colspan="2" class="tright"> <xsl:number value="position()" format="1."/><xsl:value-of select="@title"/> </td> <xsl:choose> <xsl:when test="@isTrunk[.='false']"> <xsl:apply-templates select="result"/> <xsl:apply-templates select="officer"/> </xsl:when> <xsl:otherwise> <td colspan="3" class="tright" style="color:blue;font-weight:bolder"> 注意以下几点 </td> <xsl:apply-templates select="item"/> </xsl:otherwise> </xsl:choose> </tr> </xsl:template> <!--二级题干模板--> <xsl:template match="item"> <tr> <td class="tright" style="padding-left:20px" colspan="2"> <h4><xsl:number value="position()" format="(a)."/><xsl:value-of select="@title"/></h4> </td> <xsl:apply-templates select="result"/> <xsl:apply-templates select="officer"/> </tr> </xsl:template> <!--选择框模板--> <xsl:template match="result"> <xsl:choose> <xsl:when test="@type = '1'"> <td width="15%"> <xsl:element name="select"> <xsl:attribute name="name">re_<xsl:value-of select="../@id"/></xsl:attribute> <!--<select name="select">--> <xsl:choose> <xsl:when test=".='0'"> <option value="0" selected="selected">请选择 </option> <option value="1">符合</option> <option value="2">基本符合</option> <option value="3">不符合</option> </xsl:when> <xsl:when test=".='1'"> <option value="0">请选择 </option> <option value="1" selected="selected">符合</option> <option value="2">基本符合</option> <option value="3">不符合</option> </xsl:when> <xsl:when test=".='2'"> <option value="0">请选择 </option> <option value="1">符合</option> <option value="2" selected="selected">基本符合</option> <option value="3">不符合</option> </xsl:when> <xsl:when test=".='3'"> <option value="0">请选择 </option> <option value="1">符合</option> <option value="2">基本符合</option> <option value="3" selected="selected">不符合</option> </xsl:when> </xsl:choose> <!--</select>--> </xsl:element> </td> </xsl:when> <xsl:when test="@type = '2'"> <td width="15%"> <xsl:element name="select"> <xsl:attribute name="name">re_<xsl:value-of select="../@id"/></xsl:attribute> <xsl:choose> <xsl:when test=".='0'"> <option value="0" selected="selected">请选择 </option> <option value="1">是</option> <option value="2">否</option> </xsl:when> <xsl:when test=".='1'"> <option value="0">请选择 </option> <option value="1" selected="selected">是</option> <option value="2">否</option> </xsl:when> <xsl:when test=".='3'"> <option value="0">请选择 </option> <option value="1">是</option> <option value="2" selected="selected">否</option> </xsl:when> </xsl:choose> </xsl:element> </td> </xsl:when> <xsl:when test="@type = '3'"> <td width="15%"> <xsl:element name="select"> <xsl:attribute name="name">re_<xsl:value-of select="../@id"/></xsl:attribute> <xsl:choose> <xsl:when test=".='0'"> <option value="0" selected="selected">请选择 </option> <option value="1">有</option> <option value="2">无</option> </xsl:when> <xsl:when test=".='1'"> <option value="0">请选择 </option> <option value="1" selected="selected">有</option> <option value="2">无</option> </xsl:when> <xsl:when test=".='3'"> <option value="0">请选择 </option> <option value="1">有</option> <option value="2" selected="selected">无</option> </xsl:when> </xsl:choose> </xsl:element> </td> </xsl:when> <xsl:otherwise> <td width="15%"> <xsl:element name="textarea"> <xsl:attribute name="name">re_<xsl:value-of select="../@id"/></xsl:attribute><xsl:value-of select="."/> </xsl:element> <xsl:value-of select="@units"/> </td> </xsl:otherwise> </xsl:choose> </xsl:template> <!--责任人模板--> <xsl:template match="officer"> <td width="9%" class="tright">责任人</td> <td width="11%"> <xsl:element name="textarea"> <xsl:attribute name="name">of_<xsl:value-of select="../@id"/></xsl:attribute> <xsl:value-of select="."/> </xsl:element> </td> </xsl:template> </xsl:stylesheet>
当前1/2页 12下一页阅读全文
以上是通过javascript xml xsl取值及数据修改第1/2页的实例详解的详细内容。更多信息请关注PHP中文网其他相关文章!

热AI工具

Undresser.AI Undress
人工智能驱动的应用程序,用于创建逼真的裸体照片

AI Clothes Remover
用于从照片中去除衣服的在线人工智能工具。

Undress AI Tool
免费脱衣服图片

Clothoff.io
AI脱衣机

Video Face Swap
使用我们完全免费的人工智能换脸工具轻松在任何视频中换脸!

热门文章

热工具

记事本++7.3.1
好用且免费的代码编辑器

SublimeText3汉化版
中文版,非常好用

禅工作室 13.0.1
功能强大的PHP集成开发环境

Dreamweaver CS6
视觉化网页开发工具

SublimeText3 Mac版
神级代码编辑软件(SublimeText3)

热门话题

XML文件可以用PPT打开吗?XML,即可扩展标记语言(ExtensibleMarkupLanguage),是一种被广泛应用于数据交换和数据存储的通用标记语言。与HTML相比,XML更加灵活,能够定义自己的标签和数据结构,使得数据的存储和交换更加方便和统一。而PPT,即PowerPoint,是微软公司开发的一种用于创建演示文稿的软件。它提供了图文并茂的方

如何使用WebSocket和JavaScript实现在线语音识别系统引言:随着科技的不断发展,语音识别技术已经成为了人工智能领域的重要组成部分。而基于WebSocket和JavaScript实现的在线语音识别系统,具备了低延迟、实时性和跨平台的特点,成为了一种被广泛应用的解决方案。本文将介绍如何使用WebSocket和JavaScript来实现在线语音识别系

WebSocket与JavaScript:实现实时监控系统的关键技术引言:随着互联网技术的快速发展,实时监控系统在各个领域中得到了广泛的应用。而实现实时监控的关键技术之一就是WebSocket与JavaScript的结合使用。本文将介绍WebSocket与JavaScript在实时监控系统中的应用,并给出代码示例,详细解释其实现原理。一、WebSocket技

如何利用JavaScript和WebSocket实现实时在线点餐系统介绍:随着互联网的普及和技术的进步,越来越多的餐厅开始提供在线点餐服务。为了实现实时在线点餐系统,我们可以利用JavaScript和WebSocket技术。WebSocket是一种基于TCP协议的全双工通信协议,可以实现客户端与服务器的实时双向通信。在实时在线点餐系统中,当用户选择菜品并下单

如何使用WebSocket和JavaScript实现在线预约系统在当今数字化的时代,越来越多的业务和服务都需要提供在线预约功能。而实现一个高效、实时的在线预约系统是至关重要的。本文将介绍如何使用WebSocket和JavaScript来实现一个在线预约系统,并提供具体的代码示例。一、什么是WebSocketWebSocket是一种在单个TCP连接上进行全双工

JavaScript和WebSocket:打造高效的实时天气预报系统引言:如今,天气预报的准确性对于日常生活以及决策制定具有重要意义。随着技术的发展,我们可以通过实时获取天气数据来提供更准确可靠的天气预报。在本文中,我们将学习如何使用JavaScript和WebSocket技术,来构建一个高效的实时天气预报系统。本文将通过具体的代码示例来展示实现的过程。We

JavaScript教程:如何获取HTTP状态码,需要具体代码示例前言:在Web开发中,经常会涉及到与服务器进行数据交互的场景。在与服务器进行通信时,我们经常需要获取返回的HTTP状态码来判断操作是否成功,根据不同的状态码来进行相应的处理。本篇文章将教你如何使用JavaScript获取HTTP状态码,并提供一些实用的代码示例。使用XMLHttpRequest

使用PHPXML函数处理XML数据:解析XML数据:simplexml_load_file()和simplexml_load_string()加载XML文件或字符串。访问XML数据:利用SimpleXML对象的属性和方法获取元素名称、属性值和子元素。修改XML数据:使用addChild()和addAttribute()方法添加新元素和属性。序列化XML数据:asXML()方法将SimpleXML对象转换为XML字符串。实战案例:解析产品馈送XML,提取产品信息,转换并将其存储到数据库中。
