XSLT xsl:apply-templates 元素

來源:互聯網
上載者:User
文章目錄
  • 屬性
  • 例子 1
  • 例子 2
  • 例子 3
定義和用法

<xsl:apply-templates> 元素可向當前元素或當前元素的子項目應用模板。

如果我們向 <xsl:apply-templates> 元素添加 select
屬性,那麼它僅會處理匹配該屬性的值的子項目。我們可使用 select 屬性來規定處理子介點的順序。

文法
<xsl:apply-templates select="expression" mode="name">

<!-- Content:(xsl:sort|xsl:with-param)* -->

</xsl:apply-templates>
屬性
屬性 值 描述
select 運算式 可選。規定要處理的節點。星號選取整個節點集。如果省略該屬性,則將選取當前節點的所有子節點。
mode 名稱 可選。如果存在為相同元素定義的多個處理方法,那麼用 mode 可以區分它們。
執行個體例子 1

用 h1 元素包圍文檔中每個 title 元素:

<?xml version="1.0" encoding="ISO-8859-1"?>

<xsl:stylesheet version="1.0"

xmlns:xsl="http://www.w3.org/1999/XSL/Transform">



<xsl:template match="title">

<h1><xsl:apply-templates/>
</h1>

</xsl:template>



</xsl:stylesheet>
例子 2

用 h1 元素包圍文檔中所有屬於 message 的子項目的 title 元素:

<?xml version="1.0" encoding="ISO-8859-1"?>

<xsl:stylesheet version="1.0"

xmlns:xsl="http://www.w3.org/1999/XSL/Transform">



<xsl:template match="message">

<h1><xsl:apply-templates select="title"/>
</h1>

</xsl:template>



</xsl:stylesheet>
例子 3

用 h1 元素包圍文檔中 mode 屬性設定為 "big" 的 message 所有子節點:

<?xml version="1.0" encoding="ISO-8859-1"?>

<xsl:stylesheet version="1.0"

xmlns:xsl="http://www.w3.org/1999/XSL/Transform">



<xsl:template match="message">

<h1><xsl:apply-templates select="*" mode="big"/>
</h1>

</xsl:template>



</xsl:stylesheet>

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.