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下一页阅读全文

(0)

相关推荐

  • 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&

  • javascript fckeditor编辑器取值与赋值实现代码

    获取编辑器中HTML内容 复制代码 代码如下: function getEditorHTMLContents(EditorName) { var oEditor = FCKeditorAPI.GetInstance(EditorName); return(oEditor.GetXHTML(true)); } 获取编辑器中文字内容 复制代码 代码如下: function getEditorTextContents(EditorName) { var oEditor = FCKeditorAPI.G

  • javascript学习笔记(六)数据类型和JSON格式

    什么是JSON JSON:JavaScript 对象表示法(JavaScript Object Notation). JSON的形式是用大括号"{}"包围起来的项目列表,每一个项目间用逗号(,)分隔,而项目就是用冒号(:)分隔的属性名和属性值.这是典型的字典表示形式,也再次表明javascript里的对象就是字典结构.不管多么复杂的对象,都可以用一句JSON代码来创建并赋值. JSON 结构 JSON有两种结构 json简单说就是javascript中的对象和数组,所以这两种结构就是对

  • 浅谈json取值(对象和数组)

    按对象取值: jQuery代码如下 (function ($) { $.getJSON('ajax/test.json', function (data) { var items = []; $.each(data.comments, function (key, val) { items.push('<li class="' + 'tag' + val.class + '">' + '<a href="#">' + val.content

  • java 实现读取txt文本数据并以数组形式一行一行取值

    首先来读取txt文本中的内容,输出在控制台,直接上代码: import java.io.BufferedReader; import java.io.File; import java.io.FileReader; public class ReadFiledata { public static String txt2String(File file){ StringBuilder result = new StringBuilder(); try{ BufferedReader br = n

  • Python中base64与xml取值结合问题

    Base64是一种用64个字符来表示任意二进制数据的方法. 用记事本打开exe.jpg.pdf这些文件时,我们都会看到一大堆乱码,因为二进制文件包含很多无法显示和打印的字符,所以,如果要让记事本这样的文本处理软件能处理二进制数据,就需要一个二进制到字符串的转换方法.Base64是一种最常见的二进制编码方法. 具体代码如下所述: import base64 from xml.dom import minidom # 打开xml文件 dom=minidom.parse("D:\\pythonp\\t

  • JavaScript学习笔记之取值函数getter与取值函数setter详解

    目录 取值函数getter和存值函数setter 使用get与set函数有两个好处 取值函数getter和存值函数setter get和set是两个关键字,用于对某个属性设置存值函数和取值函数,拦截该属性的存取行为. 那么,这两个东西要怎么用呢?而且他们和我们的平日里写的业务又是怎么练习起来的呢? 首先,我们先看一段恩简单的代码: var person={ myname:'' } person.myname='lsh' console.log(person.myname); 相信大家一眼就看出来

  • javascript中json对象json数组json字符串互转及取值方法

    今天用到了json数组和json对象和json类型字符串之间互转及取值,记录一下: 1.json类型的字符串转换为json对象及取值 var jsonString = '{"bar":"property","baz":3}'; var jsObject = JSON.parse(jsonString); //转换为json对象 alert(jsObject.bar); //取json中的值  2.json对象转为json类型的字符串 var js

  • php数据入库前清理 注意php intval与mysql的int取值范围不同

    php保存数据到mysql 打算在dao层进行数据入库前的清理,比如varchar进行trim,int进行intval. 有一天突然想起,php intval的取值范围与mysql的int类型一样吗? 查了一下,不一样-- http://php.net/manual/en/function.intval.phphttp://dev.mysql.com/doc/refman/5.1/zh/column-types.html#numeric-typesphp intval的取值范围:与操作系统相关,

  • 一个用javascript写的select支持上下键、首字母筛选以及回车取值的功能

    调用时可以这样: 1,tempStr=GetNewSelectStr(dataTable.value,"select"+rowIndex,true); 2,makeSelectBox("select"+rowIndex,tempStr,value,obj); tempStr-这个是返回的下拉列表值的框体 dataTable.value-这个是数据源(我这里是一张表) "select"+rowIndex-这个是ID号,也就是当前这个select的i

随机推荐