Elemen <xsl:template> XSLT
Definisi dan Penggunaan
Elemen <xsl:template> mengandung aturan yang akan diterapkan saat menyesuaikan node yang ditentukan.
Properti match digunakan untuk menghubungkan template ke elemen XML tertentu. Properti match juga dapat digunakan untuk mendefinisikan template untuk semua cabang dokument XML (misalnya, match="/" mendefinisikan seluruh dokumen).
Keterangan:<xsl:template> adalah elemen tingkat tinggi (top-level element).
Sintaks
<xsl:template name="name" match="pattern" mode="mode" priority="number"> <!-- Content:(<xsl:param>*,template) --> </xsl:template>
Properti
Properti | Nilai | Deskripsi |
---|---|---|
name | name |
Pilihan. Tentukan nama untuk template. Keterangan: Jika properti ini ditinggalkan, maka properti match harus diatur. |
match | pattern |
Pilihan. Model yang digunakan untuk template. Keterangan: Jika properti ini ditinggalkan, maka properti name harus diatur. |
mode | mode | Pilihan. Tentukan model untuk template. |
priority | number | Pilihan. Bilangan urutan template. |
Contoh
Contoh 1
<?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="/"> <html> <body> <h2>My CD Collection</h2> <xsl:apply-templates/> </body> </html> </xsl:template> <xsl:template match="cd"> <p> <xsl:apply-templates select="title"/> <xsl:apply-templates select="artist"/> </p> </xsl:template> <xsl:template match="title"> Title: <span style="color:#ff0000"> <xsl:value-of select="."/></span> <br /> </xsl:template> <xsl:template match="artist"> Artist: <span style="color:#00ff00"> <xsl:value-of select="."/></span> <br /> </xsl:template> </xsl:stylesheet>