xsl:template

  1. template_1-input.xml

  2. <?xml version="1.0"?>
  3. <products>
  4.   <product id="p1">
  5.     <name>Delta</name>
  6.     <stock>4</stock>
  7.   </product>
  8. </products>
  1. template_1-stylesheet.xsl

  2. <?xml version="1.0"?>
  3. <xsl:stylesheet version="2.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
  4.   <xsl:output indent="yes"/>
  5.   <xsl:template match="/">
  6.   <xsl:comment>Transformation: <xsl:call-template name="dateTime"/></xsl:comment>
  7.     <catalog>
  8.       <xsl:copy-of select="products/product"/>
  9.     </catalog>    
  10.   </xsl:template>
  11.   <xsl:template name="dateTime">
  12.     <xsl:value-of select="current-dateTime()"/>
  13.   </xsl:template>
  14. </xsl:stylesheet>
  1. template_1-output.xml

  2. <?xml version="1.0" encoding="UTF-8"?>
  3. <!--Transformation: 2009-02-17T12:36:46+01:00-->
  4. <catalog>
  5.   <product id="p1">
  6.     <name>Delta</name>
  7.     <stock>4</stock>
  8.   </product>
  9. </catalog>

Comment

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