XSLT <template> Element Last Updated : 28 Apr, 2025 Comments Improve Suggest changes Like Article Like Report XSLT <template> element is a basic building block in XSLT and it provides a way to define rules for transforming specific elements into a source XML document. It is an instruction that tells a browser how to transform XML into something else. It looks for specific things in the XML called patterns and decides what the changed part should look like in the end. It must be placed inside <xsl:stylesheet> or <xsl:transform>. Attributes:Attribute Description match It specifies the pattern that an element in the source XML document must match for this template to be applied name You can assign a name to the template allowing it to be referenced elsewhere in the stylesheet priority You can specify the priority of the template. Templates with higher priorities are applied first. mode It defines the processing mode in which this template should be applied. Syntax:<xsl:template match = "pattern" name = "name" priority = "number" mode = "name"> <!-- Content --></xsl:template>Example 1:In this example we have a XML data bookstore which have a one book data with title and author value and we are accessing this data by using a match attribute in <xsl:template> and then we are accessing the value of title and author by using <xsl:value-of select="key"/> Tag. XML <bookstore> <book> <title>XSLT "template" element</title> <author>Geeks For Geeks</author> </book> </bookstore> XML <xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0"> <!-- It matches 'book' element --> <xsl:template match="book"> <!-- It output HTML H3 element with value of title --> <h3> Title: <xsl:value-of select="title" /></h3> <!-- It output HTML H4 element with value of author --> <h4> Author: <xsl:value-of select="author" /></h4> </xsl:template> </xsl:stylesheet> Output: Example 2:In this example we have a two product XML data with their name and price and we are using <xsl:choose> block to choose a one value based on a condition provide in a <xsl:when test="condition"> and if the condition is not satisfy then a <xsl:otherwise> part will be executed. XML <products> <product> <name>Car</name> <price>1000000</price> </product> <product> <name>Smartphone</name> <price>5000</price> </product> </products> XML <xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0"> <!-- It matches 'product' element --> <xsl:template match="product"> <h3> Product Information </h3> <p> <strong>Name: </strong> <xsl:value-of select="name" /> <br /> <strong>Price: </strong> <xsl:value-of select="price" /><br /> <strong>Affordable/Expensive: </strong> <!-- choose block to determine it is Affordable or Expensive: --> <xsl:choose> <!-- if the price is less than 20000 --> <xsl:when test="price < 20000"> <span>Affordable</span> </xsl:when> <!-- otherwise (else part) --> <xsl:otherwise> <span>Expensive</span> </xsl:otherwise> </xsl:choose> </p> </xsl:template> </xsl:stylesheet> Output Comment More infoAdvertise with us Next Article XSLT Element J jaimin78 Follow Improve Article Tags : TechTips Web technologies-HTML and XML Geeks Premier League 2023 Similar Reads XSLT <apply-template> Element The XSLT Apply Template tag is used to apply the appropriate templates in the context of the selected node. This tag is used to direct the processor to apply templates on node elements of XML. Syntax: <xsl:apply-template select = Expression mode = Name> // Other content</xsl:apply-template 3 min read XSLT <message> Element In XSLT (eXtensible Stylesheet Language Transformations), the '<xsl: message>' element outputs messages during the transformation process. It's a way to communicate information or provide feedback during the transformation. This element contains all the other XSL elements such as <xsl: text 1 min read XSLT <if> Element XSLT <if> Element is used to check the condition of the content of XML. The test is used to check the condition if it satisfies the condition then inside if is executed. Syntax: <xsl:if test=EXPRESSION> // Some output if the expression is true </xsl:if>Parameters: test: It is the c 3 min read XSLT <value-of> Element XSLT <value-of> Element is used to extract value from a node selected through name or expression. It is used to get value from XML and then display or output it. In this tutorial, we will learn to implement it. XSLT is a programming language used to convert XML documents into other forms such 2 min read XSLT <key> Element XSLT <key> Element is used to declare the key which is later used to identify the node with the help of the key function. The <xsl: key> tag assigns a specific key to an XML element And the key() function used to access this element of XML Syntax: <xsl:key name = "name" match = "patte 3 min read XSLT <import> Element XSLT <xsl:import> element is used to include the content of one stylesheet within another. When you import a stylesheet, it allows you to incorporate the templates, definitions, and other components from the imported stylesheet into the importing stylesheet. Syntax: <xsl: import href=URI 3 min read Like