>  기사  >  백엔드 개발  >  javascript xml xsl을 통한 값 획득 및 데이터 수정에 대한 1/2 페이지의 예제에 대한 자세한 설명

javascript xml xsl을 통한 값 획득 및 데이터 수정에 대한 1/2 페이지의 예제에 대한 자세한 설명

Y2J
Y2J원래의
2017-04-21 10:41:301770검색

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=&#39;btn1_mouseover&#39;" onmouseout="this.className=&#39;btn1_mouseout&#39;" 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[.=&#39;false&#39;]"> 
                    <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 = &#39;1&#39;"> 
                            <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=".=&#39;0&#39;"> 
                                            <option value="0" selected="selected">请选择 </option> 
                                            <option value="1">符合</option> 
                                            <option value="2">基本符合</option> 
                                            <option value="3">不符合</option> 
                                        </xsl:when> 
                                        <xsl:when test=".=&#39;1&#39;"> 
                                            <option value="0">请选择 </option> 
                                            <option value="1" selected="selected">符合</option> 
                                            <option value="2">基本符合</option> 
                                            <option value="3">不符合</option> 
                                        </xsl:when> 
                                        <xsl:when test=".=&#39;2&#39;"> 
                                            <option value="0">请选择 </option> 
                                            <option value="1">符合</option> 
                                            <option value="2" selected="selected">基本符合</option> 
                                            <option value="3">不符合</option> 
                                        </xsl:when> 
                                        <xsl:when test=".=&#39;3&#39;"> 
                                            <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 = &#39;2&#39;"> 
                            <td width="15%"> 
                                <xsl:element name="select"> 
                                <xsl:attribute name="name">re_<xsl:value-of select="../@id"/></xsl:attribute> 
                                    <xsl:choose> 
                                        <xsl:when test=".=&#39;0&#39;"> 
                                            <option value="0" selected="selected">请选择 </option> 
                                            <option value="1">是</option> 
                                            <option value="2">否</option> 
                                        </xsl:when> 
                                        <xsl:when test=".=&#39;1&#39;"> 
                                            <option value="0">请选择 </option> 
                                            <option value="1" selected="selected">是</option> 
                                            <option value="2">否</option> 
                                        </xsl:when> 
                                        <xsl:when test=".=&#39;3&#39;"> 
                                            <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 = &#39;3&#39;"> 
                            <td width="15%"> 
                                <xsl:element name="select"> 
                                <xsl:attribute name="name">re_<xsl:value-of select="../@id"/></xsl:attribute> 
                                    <xsl:choose> 
                                        <xsl:when test=".=&#39;0&#39;"> 
                                            <option value="0" selected="selected">请选择 </option> 
                                            <option value="1">有</option> 
                                            <option value="2">无</option> 
                                        </xsl:when> 
                                        <xsl:when test=".=&#39;1&#39;"> 
                                            <option value="0">请选择 </option> 
                                            <option value="1" selected="selected">有</option> 
                                            <option value="2">无</option> 
                                        </xsl:when> 
                                        <xsl:when test=".=&#39;3&#39;"> 
                                            <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 중국어 웹사이트의 기타 관련 기사를 참조하세요!

성명:
본 글의 내용은 네티즌들의 자발적인 기여로 작성되었으며, 저작권은 원저작자에게 있습니다. 본 사이트는 이에 상응하는 법적 책임을 지지 않습니다. 표절이나 침해가 의심되는 콘텐츠를 발견한 경우 admin@php.cn으로 문의하세요.