SoFunction
Updated on 2025-03-02

javascript xml xsl value and data modification page 1/2

--Main data files
<?xml version="1.0" encoding="UTF-8"?>

<?xml:stylesheet type="text/xsl" href=""?>

<projects >
<project title="First Title 1" index="1">
<items isTrunk="false" title="Second Title 1.1">
            <result type="2">1</result>
            <officer><![CDATA[]]></officer>
            <classified>1</classified>
            <eligibility>0</eligibility>
            <remark></remark>
        </items>
<items isTrunk="false" title="Second Title 1.2">
            <result type="2">3</result>
            <officer><![CDATA[]]></officer>
            <classified>1</classified>
            <eligibility>0</eligibility>
        </items>
    </project>
<project title="First Title 2" index="2">
<items isTrunk="false" title="Second Title 2.1">
            <result type="3">3</result>
            <officer><![CDATA[]]></officer>
            <classified>1</classified>
            <eligibility>0</eligibility>
        </items>
<items isTrunk="true" title="Second Title 2.2">
<item title="Level 3 Title 2.2.1">
                <result type="1">2</result>
<officer><![CDATA[It's actually garbled]]></officer>
                <classified>1</classified>
                <eligibility>0</eligibility>
            </item>
<item title="Level 3 Title 2.2.2">
                <result type="1">3</result>
                <officer><![CDATA[<><>]]></officer>
                <classified>1</classified>
                <eligibility>0</eligibility>
            </item>
        </items>            
<items isTrunk="true" title="Second Title 2.3">
<item title="Level 3 Title 2.3.1">
                <result type="2">1</result>
                <officer><![CDATA[]]></officer>
                <classified>1</classified>
                <eligibility>0</eligibility>
            </item>
<item title="Level 3 Title 2.3.2">
                <result type="2">1</result>
                <officer><![CDATA[]]></officer>
                <classified>1</classified>
                <eligibility>0</eligibility>
            </item>
        </items>            
    </project>
<project title="First Title 3" index="3">
<items isTrunk="false" title="Second Title 3.1">
<result type="4" units="yuan">25345</result>
            <officer><![CDATA[sinoly]]></officer>
            <classified>1</classified>
            <eligibility>0</eligibility>
        </items>
<items isTrunk="false" title="Second Title 3.2">
<result type="4" units="yuan">9865764</result>
            <officer><![CDATA[]]></officer>
            <classified>1</classified>
            <eligibility>0</eligibility>
        </items>
<items isTrunk="false" title="Second Title 3.3">
            <result type="2">0</result>
            <officer><![CDATA[]]></officer>
            <classified>1</classified>
            <eligibility>0</eligibility>
        </items>
<items isTrunk="true" title="Second Title 3.4">
<item title="Level 3.4.1">
                <result type="1">0</result>
                <officer><![CDATA[]]></officer>
                <classified>1</classified>
                <eligibility>0</eligibility>
            </item>
<item title="Level 3.4.2">
                <result type="1">0</result>
                <officer><![CDATA[]]></officer>
                <classified>1</classified>
                <eligibility>0</eligibility>
            </item>
<item title="Level 3.4.3">
                <result type="1">0</result>
                <officer><![CDATA[]]></officer>
                <classified>1</classified>
                <eligibility>0</eligibility>
            </item>
        </items>
    </project>
</projects>
--Style file, very convenient to retrieve xml data

<?xml version="1.0" encoding="gb2312"?>

<xsl:stylesheet version="1.0"   xmlns:xsl="http:///1999/XSL/Transform">

<!--Root Template-->
    <xsl:output method="xml"/>

    <xsl:template match="/">    
        <xsl:apply-templates select="projects/project"/>
        <h6>
<button type="submit" class="btn1_mouseout" onmouseover="='btn1_mouseover'" onmouseout="='btn1_mouseout'" title="Submit"> Next</button>
        </h6>
    </xsl:template>

<!--Theme 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="1."/><xsl:value-of select="@title"/>
                    </h2>
                </td>
            </tr>
            <xsl:apply-templates select="items"/>
        </TABLE>
        <BR/>
    </xsl:template>

<!--First-level question 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">
Pay attention to the following points
                    </td>
                    <xsl:apply-templates select="item"/>
                </xsl:otherwise>
            </xsl:choose>
        </tr>
    </xsl:template>

<!--Level 2 question 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>

<!--Select box 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">Please select </option>
<option value="1">Complied</option>
<option value="2">basically comply with</option>
<option value="3">not in compliance</option>
                                        </xsl:when>
                                        <xsl:when test=".='1'">
<option value="0">Please select </option>
<option value="1" selected="selected">compliant</option>
<option value="2">basically comply with</option>
<option value="3">not in compliance</option>
                                        </xsl:when>
                                        <xsl:when test=".='2'">
<option value="0">Please select </option>
<option value="1">Complied</option>
<option value="2" selected="selected">basically compliant</option>
<option value="3">not in compliance</option>
                                        </xsl:when>
                                        <xsl:when test=".='3'">
<option value="0">Please select </option>
<option value="1">Complied</option>
<option value="2">basically comply with</option>
<option value="3" selected="selected">not in compliance</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">Please select </option>
<option value="1">Yes</option>
<option value="2">No</option>
                                        </xsl:when>
                                        <xsl:when test=".='1'">
<option value="0">Please select </option>
<option value="1" selected="selected">yes</option>
<option value="2">No</option>
                                        </xsl:when>
                                        <xsl:when test=".='3'">
<option value="0">Please select </option>
<option value="1">Yes</option>
<option value="2" selected="selected">No</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">Please select </option>
<option value="1">has</option>
<option value="2">No</option>
                                        </xsl:when>
                                        <xsl:when test=".='1'">
<option value="0">Please select </option>
<option value="1" selected="selected">has</option>
<option value="2">No</option>
                                        </xsl:when>
                                        <xsl:when test=".='3'">
<option value="0">Please select </option>
<option value="1">has</option>
<option value="2" selected="selected">none</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>

<!--Responsible Person Template-->
    <xsl:template match="officer">
<td width="9%" class="right">Person in charge</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>
12Next pageRead the full text