zoukankan      html  css  js  c++  java
  • 11、xsl中apply-templates用法

    一、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>

    三、输出效果如下:

  • 相关阅读:
    CSS复合选择器
    模块之shutil模块模块详解
    模块之sys模块详解
    模块之os模块详解
    map遍历
    java完美处理表情符
    死磕设计模式—建造者模式
    Java String getChars()方法
    Java知识系统回顾整理01基础06数组05复制数组
    Java知识系统回顾整理01基础06数组04增强型for循环
  • 原文地址:https://www.cnblogs.com/tianpan2019/p/15001135.html
Copyright © 2011-2022 走看看