javascript xml xsl取值及数据修改第1/2页_XML示例

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

时间: 2024-09-12 09:07:16

javascript xml xsl取值及数据修改第1/2页_XML示例的相关文章

关于C#XML文件取值

问题描述 <OTA_AirAvailRS><OriginDestinationInformation><DepartureDateTime>2015-05-05</DepartureDateTime><OriginLocationLocationCode="BJS"/><DestinationLocationLocationCode="SHA"/><OriginDestinationOpt

javascript fckeditor编辑器取值与赋值实现代码_网页编辑器

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

使用XSL将XML文档中的CDATA注释输出为HTML文本_XML示例

要利用DOM 来存取XML 文件,你必须将XML 文件连结到HTML 网页上. 示例代码 1. test.xml <?xml version="1.0" encoding="gb2312"?><?xml-stylesheet href="test.xsl" type="text/xsl"?><entry><title>entry with images</title>

javascript学习笔记(六)数据类型和JSON格式_基础知识

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

js从Cookies里面取值的简单实现_javascript技巧

工作过程中遇到一个Js从Cookies里面取值的需求,Js貌似没有现成的方法可以指定Key值获取Cookie里面对应的值,参阅网上的代码,简单实现如下: 1. 服务端代码,Page_Load里面Cookies写入几个值 using System; using System.Collections.Generic; using System.Web; using System.Web.UI; using System.Web.UI.WebControls; namespace WebApplica

如何实现XML+XSL+javascript数据排序

javascript|xml|排序|数据 如何实现XML+XSL+javascript数据排序 数据排序模版<?xml version="1.0" encoding="gb2312" ?><xsl:stylesheet version="1.1" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:fo="http://www.w3.org/

使用qt5操作xml文件,删除xml文件中的节点和修改xml文件节点的数据值

问题描述 使用qt5操作xml文件,删除xml文件中的节点和修改xml文件节点的数据值 使用qt5操作xml文件,删除xml文件中的节点和修改xml文件中节点的数据值. 那位大神知道,如果有代码就更好了. 谢谢 解决方案 QT XML文件 修改节点修改XML文件的节点属性值

解析的值-C#怎么解析以下xml,解析到的数据怎么取

问题描述 C#怎么解析以下xml,解析到的数据怎么取 <?xml version="1.0" encoding="gbk"?></ 解决方案 http://www.cnblogs.com/RiseSoft/archive/2012/03/17/2404007.html

JavaScript与XML XSL的综合使用

javascript|xml 1.当用xsl来显示xml内容时,要注意在借助xsl文档来定义样式时:     在html文档中有  <head>    <base href="http://127.0.0.1:7001/MagazineResearchStageWeb/"> 就意味着所引用的xsl等外部文档必须在href目录下.否则就不能引用到外部文档. 2.通过new String来处理xml字符串后, 即var XMLStr=new String(xmlIn