template_1-input.xml
<?xml version="1.0"?>
<products>
<product
id="p1">
<name>Delta</name>
<stock>4</stock>
</product>
</products>
template_1-stylesheet.xsl
<?xml version="1.0"?>
<xsl:stylesheet
version="2.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output
indent="yes"/>
<xsl:template
match="/">
<xsl:comment>Transformation: <xsl:call-template
name="dateTime"/></xsl:comment>
<catalog>
<xsl:copy-of
select="products/product"/>
</catalog>
</xsl:template>
<xsl:template
name="dateTime">
<xsl:value-of
select="current-dateTime()"/>
</xsl:template>
</xsl:stylesheet>
template_1-output.xml
<?xml version="1.0" encoding="UTF-8"?>
<!--Transformation: 2009-02-17T12:36:46+01:00-->
<catalog>
<product
id="p1">
<name>Delta</name>
<stock>4</stock>
</product>
</catalog>
Templates can have a match attribute or a name attribute ot both (rarely used). Named templates acts like a user-defined function. In XSLT 2.0 xsl:function is often used instead.
Updated 2009-03-19