caucho
 


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

<xsl:template match="example">
  <table>
    <xsl:attribute name="class">
      <xsl:if test="@class">
        <value-of select="@class"/>
      </xsl:if>
      <xsl:if test="not(@class)">example</xsl:if>
    </xsl:attribute>
    <tr>
      <td>
        <xsl:apply-templates/>
      </td>
    </tr>
  </table>
</xsl:template>

</xsl:stylesheet>
hello.xtp

<example class="special-example">
This is an example.
</example>

<table class="special-example">
<tr>
  <td>This is an example</td>
</tr>
</table>

default.xsl
$template(example) <<
<table>
  $attribute("class") <<$(if(@class,@class,"example"))>>
<tr>
  <td>
    $apply-templates();
  </td>
</tr>
</table>
>>
  • Tags in stylesheets are parsed, not raw text. So you can add attributes to elements.
  • $attribute(my-name) adds an attribute to an element.
  • $attribute(my-name) expands to xsl:attribute name="my-name".
  • The XPath pattern if(test,if-true,if-false) selects a value based on a boolean.
  • if(test,if-true,if-false) is a Resin extension.
  • xsl:if evaluates conditionally.

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