Quackit Logo
FREE Hosting!
With every domain you register with ZappyHost you get FREE hosting.
Create free Flash websites

XSLT <template> Element

Print Version

XSLT is all about being able to select one or more nodes from your XML document and transforming or replacing its content with something else. A node could be any of the following: elements, attributes, text, namespaces, processing-instructions, and comments.

The <xsl:template> element is what you use to select a node from your XML document and transform its contents.

To select an element, you use the match attribute. To transform its contents, you simply place the new content between the opening (<xsl:template>) and closing (</xsl:template>) tags.

Example

In this case, I'm selecting the root node (i.e. tutorials). By selecting this node, the template element tells the XSLT processor how to transform the output. What I'm doing here is telling the processor to replace the root node (i.e. the whole XML document) with what I've written between the <xsl:template> tags.

In this case, I have written the contents of an HTML document inside the <xsl:template> tags. When a user views any XML document that uses this XSL document, they will simply see the line "New content..." and the browser's title bar will read "My XSLT Example".

<xsl:template match="tutorials">
  <html>
    <head>
      <title>My XSLT Example</title>
    </head>
    <body>
      <p>New content...</p>
    </body>
  </html>
</xsl:template>

Selecting the Root Node

In the example above, we selected the "tutorials" node which happens to be the root node of our XML document. Another way of selecting the root node is to use a forward slash in place of the node's name. The following example results in the same output as the above example.

Example:

<xsl:template match="/">
  <html>
    <head>
      <title>My XSLT Example</title>
    </head>
    <body>
      <p>New content...</p>
    </body>
  </html>
</xsl:template>

Enjoy this website?

  1. Add this page to your Favorites
  2. Link to this page (copy/paste into your own website or blog):
  3. Help support Quackit by making a donation

Oh, and thank you for supporting Quackit!

Need Website Content?
Get unique, quality digital content for your website.
  • 270+ Website Templates
  • 800+ Flash Templates
  • 25,000+ Images, Logos
  • 30,000+ e-Books
  • 15,000+ Scripts
  • 27,000+ Animated GIFs
  • 21,000+ Ringtones
  • ...and much more!
Get your content now!
$1.99 .info domain names!
© Copyright 2000 - 2010 Quackit.com