zoukankan      html  css  js  c++  java
  • 08、xsl中操作子节点带循环输出

    一、show.xml文件如下:

    <?xml version="1.0" encoding="GB2312"?>
    <?xml-stylesheet type="text/xsl" href="style.xsl"?>
    <label_out>
        <!--    三条数据    -->
        <label_people>
            <name>张三</name>
            <age>22</age>
            <country>中国</country>
        </label_people>
        <label_people>
            <name>李四</name>
            <age>19</age>
            <country>日本</country>
        </label_people>
        <label_people>
            <name>王五</name>
            <age>20</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>
                    <td>
                        <xsl:value-of select="age"/>
                    </td>
                    <td>
                        <xsl:value-of select="country"/>
                    </td>
                </tr>
            </xsl:for-each>
    
        </xsl:template>
    
    </xsl:stylesheet>

    三、输出效果如下:

  • 相关阅读:
    2021.2.6 日记
    P2168 荷马史诗
    2021寒假集训——数论初步
    2021.2.5 日记
    2021.2.4 日记
    2021.2.3 日记
    堆——学习笔记
    树状数组——学习笔记
    Easy | LeetCode 350. 两个数组的交集 II | 哈希 | 排序+双指针
    Easy | LeetCode 66. 加一 | 模拟
  • 原文地址:https://www.cnblogs.com/tianpan2019/p/15001094.html
Copyright © 2011-2022 走看看