• 當前位置:首頁 > IT技術 > 移動平臺 > 正文

    11、xsl中apply-templates用法
    2021-08-10 17:40:07

    一、show.xml文件如下:

    <?xml version="1.0" encoding="GB2312"?>
    <?xml-stylesheet type="text/xsl" href="style.xsl"?>
    <label_out>
        <!--    三條數據    -->
        <label_people>
            <name>張1三</name>
            <age>
                <aa>22</aa>
            </age>
            <country>中國</country>
        </label_people>
        <label_people>
            <name>李四</name>
            <age >
                <aa >19</aa>
            </age>
            <country>日本</country>
        </label_people>
        <label_people>
            <name>王五</name>
            <age>
                <aa>20</aa>
            </age>
            <country>朝鮮</country>
        </label_people>
    </label_out>

    ?

    二、style.xsl文件如下:

    <?xml version="1.0" encoding="GB2312"?>
    <xsl:stylesheet version="1.0"
                    xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
    
        <xsl:template match="/">
            <html>
                <body>
                    <h2>抬頭內容</h2>
                    <table border="1">
                        <tr bgcolor="#9acd32">
                            <th>姓名</th>
                            <th>年級</th>
                            <th>國家</th>
                        </tr>
                        <xsl:apply-templates/>
                    </table>
                </body>
            </html>
        </xsl:template>
    
        <!--    對label_out標簽進行處理-->
        <xsl:template match="label_out">
            <xsl:for-each select="label_people">
                <tr>
                    <td>
                        <xsl:value-of select="name"/>
                    </td>
    <!--                運用到子層級-->
                    <xsl:apply-templates select="age" />
                    <td>
                        <xsl:value-of select="country"/>
                    </td>
                </tr>
            </xsl:for-each>
        </xsl:template>
    
        <xsl:template match="age">
            <td bgcolor="#999999">
                <xsl:value-of select="aa" />
            </td>
        </xsl:template>
    
    </xsl:stylesheet>

    ?

    三、輸出效果如下:

    11、xsl中apply-templates用法_html

    ?

    ?
    ?
    ?
    ?

    本文摘自 :https://blog.51cto.com/u

    開通會員,享受整站包年服務
    国产呦精品一区二区三区网站|久久www免费人咸|精品无码人妻一区二区|久99久热只有精品国产15|中文字幕亚洲无线码