Coding With Fun
Home Docker Django Node.js Articles Python pip guide FAQ Policy

XSLT <xsl:template> elements


May 28, 2021 XSL T


Table of contents


XSLT -lt;xsl:template> element

When matching nodes, you need to use some useful rules that are included in the XSLT's element of slt;xsl:template.gt.


XSLT <xsl:template> elements Complete XSLT element reference manual

Definitions and usages

The element contains rules to be applied when matching a specified node.

The match property is used to associate a template to an XML element. The match property can also be used to define templates for all branches of an XML document (for example, match"/" defines the entire document).

Note: the top-level element (top-level element) is the top-level element.


Grammar

<xsl:template
name="name"
match="pattern"
mode="mode"
priority="number">

<!-- Content:(<xsl:param>*,template) -->

</xsl:template>

Property

Attributes value describe
name name Optional.Define the name for the template.

Note: If this property is omitted, you must set the Match property.

match pattern Optional.Matching mode of the template.

Note: If this property is omitted, you must set the name property.

mode mode Optional.Template specified mode.
priority number Optional.A number of priority numbers representing the template.

Instance

<?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>

XSLT <xsl:template> elements Complete XSLT element reference manual

Related tutorials

XML tutorial