zoukankan      html  css  js  c++  java
  • xsl:apply-templates 模板的应用

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

    <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">

    <xsl:template match="/">

    <html>

    <head>

    <title>测试xsl:apply-templates元素</title>

    </head>

    <body>

    <table border="1" cellspacing="0" cellpadding="0">

    <tr>

    <th>姓名</th>

    <th>出身地</th>

    <th>武器</th>

    <th>战斗力</th>

    <th>战斗力数值</th>

    </tr>

    <xsl:apply-templates select="heros/hero"/>

    </table>

    </body>

    </html>

    </xsl:template>

    <xsl:template match="hero">

    <tr>

    <xsl:apply-templates select="name"/>

    <xsl:apply-templates select="address"/>

    <xsl:apply-templates select="weapon"/>

    <xsl:apply-templates select="fighting"/>

    <xsl:apply-templates select="fighting" mode="detail"/>

    </tr>

    </xsl:template>

    <xsl:template match="name">

    <td style="font-size:14px;font-family:serif;">

    <xsl:apply-templates/>

    </td>

    </xsl:template>

    <xsl:template match="address">

    <td>

    <xsl:apply-templates/>

    </td>

    </xsl:template>

    <xsl:template match="weapon">

    <td>

    <xsl:apply-templates/>

    </td>

    </xsl:template>

    <xsl:template match="fighting">

    <td>

    <xsl:apply-templates />

    </td>

    </xsl:template>

    <xsl:template match="fighting" mode="detail">

    <td>

    战斗力:<xsl:apply-templates />

    </td>

    </xsl:template>

    </xsl:stylesheet>

    注意:

    如果<xsl:apply-templates>元素没有添加select属性,xsl处理器会处理当前节点所有子集。

    而语句<xsl:apply-templates select="heros/hero"/>中,添加select属性(其属性值是XPath表达式),xsl处理器会处理匹配XPath表达式的子节点并在上下文找到适合应用的模板,同时,可以使用select属性规定xsl处理器处理子节点的顺序。

  • 相关阅读:
    ACM-ICPC 2018 南京赛区网络预赛
    我们
    2018 Multi-University Training Contest 7
    ACM International Collegiate Programming Contest, JUST Collegiate Programming Contest (2018)
    BZOJ1834 [ZJOI2010] network 网络扩容
    BZOJ4415 [SHOI2013] 发牌
    BZOJ1257 [CQOI2007] 余数之和sum
    BZOJ3110 [ZJOI2013] K大数查询(加强数据)
    BZOJ1406 [AHOI2007] 密码箱
    BZOJ3110 [ZJOI2013] K大数查询
  • 原文地址:https://www.cnblogs.com/threestars/p/10468818.html
Copyright © 2011-2022 走看看