XSLT <xsl:apply-templates>
Referensi Elemen XSLT Lengkap
Definisi dan Penggunaan
Elemen <xsl:apply-templates> menerapkan template ke elemen saat ini atau ke node anak elemen saat ini.
Jika kita menambahkan atribut pilih ke elemen <xsl:apply-templates> itu hanya akan memproses elemen anak yang cocok dengan nilai atribut. Kita dapat menggunakan atribut pilih untuk menentukan urutan node anak yang akan diproses.
Sintaksis
<xsl:apply-templates select="expression" mode="name">
<!-- Content:(xsl:sort|xsl:with-param)* -->
</xsl:apply-templates>
Atribut
Attribute | Value | Description |
---|---|---|
select | expression | Optional. Specifies the nodes to be processed. An asterisk selects the entire node-set. If this attribute is omitted, all child nodes of the current node will be selected |
mode | name | Optional. If there are multiple ways of processing defined for the same element, distinguishes among them |
Contoh 1
Bungkus satu elemen h1 di sekitar setiap elemen judul dalam dokumen:
<?xml version="1.0" encoding="UTF-8"?>
<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>
Contoh 2
Bungkus satu elemen h1 di sekitar semua elemen judul yang merupakan anak-anak dari pesan:
<?xml version="1.0" encoding="UTF-8"?>
<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>
Contoh 3
Bungkus satu elemen h1 di sekitar semua simpul anak dari pesan yang memiliki atribut mode yang disetel ke "besar":
<?xml version="1.0" encoding="UTF-8"?>
<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>
Referensi Elemen XSLT Lengkap