caucho
 xsl:apply-templates


Most stylesheet templates generate HTML elements with content. The previous Hello, World example just replaced an empty tag <hello> with some text. Any content of the <hello> tag was ignored. XSL uses <xsl:apply-templates> to evaluate the children of an element.

The following stylesheet creates a <note> tag whose content is evaluated using the normal XSL processing. In the example, every <note> tag is replaced with "Note: " and emphasizes the contents of the tag.

default.xsl
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform">

<xsl:template match="note">
  <xsl:text>Note: </xsl:text>
  <em>
    <xsl:apply-templates/>
  </em>
</xsl:template>

<xsl:template match="hello">
  <xsl:text>Hello, World!</xsl:text>
</xsl:template>

</xsl:stylesheet>

Since the XSL engine will evaluate the contents of the <note>, it will replace the <hello> from the previous example with the "Hello, World" text. By creating tags like <note>, you can change the look of a page or an entire site by changing the stylesheet. All the <note> instances will be automatically reformatted. With Serif, you can modify the stylesheet and immediately browse the site to see how it looks. The feedback is immediate.

hello.xtp
This is a plain, old description.

<note>The first example is <hello/></note>

This is a plain, old description.

Note: <em>The first example is Hello, world!</em>

StyleScript equivalent

The StyleScript equivalent is $apply-templates();. The function notation, $foo() expands to an xsl:foo element. The ';' tells StyleScript that the tag is empty. For a tag with contents, use <<...>>.

default.xsl
$template(note) <<
Note: <em>$apply-templates();</em>
>>

$template(hello) <<Hello, World!>>

Summary

  • xsl:apply-templates processes the current node's children.
  • You can add tags, like <em>, directly to the stylesheet.
  • $apply-templates(); expands to <xsl:apply-templates/>

Copyright © 1998-2002 Caucho Technology, Inc. All rights reserved.
Resin® is a registered trademark, and HardCoretm and Quercustm are trademarks of Caucho Technology, Inc.