XSLT-lite
Resin 3.0

Features
Installation
Configuration
Web Applications
IOC/AOP
Resources
JSP
Servlets and Filters
Portlets
Databases
Admin (JMX)
CMP
EJB
Amber
EJB 3.0
Security
XML and XSLT
XTP
JMS
Performance
Protocols
Third-party
Troubleshooting/FAQ

Introduction
JAXP
User's Guide
Reference
FAQ
Scrapbook

XSLT
XSLT-lite Syntax
XPath Functions
XSLT
Reference
XPath Functions

  1. Index
  2. XSLT-lite Core
    1. XSLT-lite Elements
      1. Resin extensions
        1. Abbreviations

          Index
          $(expr)$value-of shortcut prints the value of the XPath expression
          $apply-imports();Like Java's super, calls the overridden template
          $apply-templates(select);Evaluates the children of the current node
          $attribute(name) <<...>>Adds an attribute to the element
          $attribute-set(name) <<...>>Defines a named attribute set
          $call-template(name) <<...>>Calls a named template with the current node
          $choose(test) <<...>>Implements a select block
          $comment() <<...>>Creates a new comment
          $copy() <<...>>Copies the current node, but not children or attributes, to the output
          $copy-of(select);Copies a sub-tree into the output
          $declarationAdds declaration code, i
          $directive.page(attributes);Sets page directives
          $element(name) <<...>>Creates a new element
          $expr(expr);Prints the value of the Java expression, expr
          $for-each(select) << ... >>Loops over child select patterns
          $if (test) <<... >>Executes the template if test is true
          $import(href);Imports a stylesheet
          $output(...);Controls the output printing
          $param(name);Declares an XSL parameter
          $processing-instruction(name) <<...>>Creates a new processing instruction
          $scriptlet() << statement_list >>Executes the statement_list scriptlet
          $sort(...) <<...>>Sorts nodes in $apply-templates or $for-each
          $template(match) << ... >>Establishes a pattern and replacement text
          $text() <<...>>Writes the contents to the output
          $value-of(select);Writes a calculated value output
          $variable(name);Assignes an XSL variable
          <# statement-list #>$scriptlet shortcut executes the statements using the page's scripting language
          <#! declaration #>$declaration shortcut defines functions and variables
          <#= expression #>$expression shortcut prints the value of expression using the page's scripting language

          XSLT-lite Core

          $apply-templates(select);

          Evaluates the children of the current node. $apply-templates recursively processes the children. If a template has no $apply-templates(), then the children are ignored.

          attributemeaning
          selectAn XPath select pattern selecting the nodes to evaluate next. (optional)
          modeonly selects templates with the given mode

          The following example writes the 'a' nodes followed by the 'b' nodes and ignores everything else.

          $template(double) <<
            $apply-templates(a);
            $apply-templates(b);
          >>
          

          <double>
            <b>b1</b>
            <a>a1</a>
            <b>b2</b>
            <a>a2</a>
          </double>
          

          a1
          a2
          b1
          b2
          

          $attribute(name) <<...>>

          Adds an attribute to the element. The name can be computed using an attribute value template.

          AttributeMeaning
          nameName of the new attribute.

          $template(a) <<
            <c>
              $attribute (b{@id}) <<
                $value-of(c{@id});
              >>
            </c>
          >>
          

          <c b3='c3'/>
          

          $copy() <<...>>

          Copies the current node, but not children or attributes, to the output.

          To copy an element, a stylesheet must copy the attributes as well.

          The following example is the identity stylesheet. It copies input to the output including the attributes.

          $template(@*|node()) <<
            $copy() <<
              $apply-templates(@*|node());
            >>
          >>
          

          $if (test) <<... >>

          Executes the template if test is true.

          $template(signal) <<
            $if (@color="red") <<stop>>
            $else if (@color="green") <<go>>
            $else <<yield>>
          >>
          

          <signal color="green"/>
          <signal color="ultramaroon"/>
          <signal color="red"/>
          

          go
          yield
          stop
          

          $output(...);

          Controls the output printing.

          AttributeMeaning
          methodxml or html or text. Select printing method
          versionXML version
          encodingcharacter set to print the results
          omit-xml-declarationskip the XML or HTML declaration
          indentpretty-print or not
          media-typemime-type
          disable-output-escaping'<' gets printed as '<', not '&lt;'

          $template(match) << ... >>

          Establishes a pattern and replacement text. $template registers its pattern with the XSL processing engine. When a node matches the pattern, XSL will process the contents of the template.

          Pure XSL processes the contents slightly differently than XTP. XSL expects all tags to be valid XML. XTP is more forgiving. If the tag is not one of those defined by XSL, it will treat the tag as raw text.

          attributemeaning
          matchthe XPath match pattern (required)
          modestring grouping templates into a special mode
          nameName for later use by call-template
          priorityconflict-resolving priority, an integer

          In the following example, the template matches any 'box' tag. The contents of the box are placed in a centered table 80% of the current width.

          $template(box) <<
            <center>
            <table width='80%'>
            <tr><td>
              $apply-templates();
            </td></tr>
            </table>
            </center>
          >>
          

          <p>Here's a boxed quote,</p>
          
          <box>
          To be or not to be...
          </box>
          

          <p>Here's a boxed quote,</p>
          
          <center>
          <table width='80%'>
          <tr><td>
            To be or not to be...
          </td></tr>
          </table>
          </center>
          

          $value-of(select);

          Writes a calculated value output.

          value-of is particularly useful for extracting attribute values. The following example creates a JSP tag which adds two numbers.

          $template(ct:sum) <<
          <jsp:expression>
          $value-of(@a); + $value-of(@b);
          </jsp:expression>
          >>
          

          XSLT-lite Elements

          $apply-imports();

          Like Java's super, calls the overridden template.

          $attribute-set(name) <<...>>

          Defines a named attribute set. The attributes in the set are defined by xsl:attribute elements.

          AttributeMeaning
          nameName of the attribute set.

          $attribute-set(font) <<
            $attribute(font-size) <<12pt>>
            $attribute(font-weight) <<bold>>
          >>
          
          $template(a) <<
            <c xsl:use-attribute-sets='font'/>
          >>
          

          <c font-size='12pt' font-weight='bold'/>
          

          $call-template(name) <<...>>

          Calls a named template with the current node. $call-template lets stylesheets reuse common code, like functions. It works like $apply-templates(.); except that it calls based on a template name.

          AttributeMeaning
          nametemplate name to call
          modetemplate mode

          $choose(test) <<...>>

          Implements a select block. The $when statements are tested in order. The first matching one is executed. If none match, the $otherwise block is executed.

          AttributeMeaning
          testXPath expression evaluating to a boolean.

          $template(a) <<
            $choose() <<
              $when(@color="red") <<stop>>
              $when(@color="green") <<go>>
              $otherwise() <<yield>>
            >>
          >>
          

          $comment() <<...>>

          Creates a new comment. The contents of the $comment() element become the contents of the comment.

          $template(a) <<
            $comment() << Text for the comment. >>
          >>
          

          <!-- Text for the comment. -->
          

          $copy-of(select);

          Copies a sub-tree into the output. $copy-of resembles $value-of. value-of always converts the value to a string. copy-of will copy subtrees.

          attributemeaning
          selectAn XPath expression to be copied.

          $element(name) <<...>>

          Creates a new element. The name can be computed using an attribute value template.

          AttributeMeaning
          nameName of the new element.

          $template(a) <<
            $element(b{@id}) <<
              <c/>
            >>
          >>
          

          <a id="3"/>
          

          <b3><c/></b3>
          

          $for-each(select) << ... >>

          Loops over child select patterns. $for-each() gives stylesheets complete control over the actions for child nodes.

          Usually, stylesheets will want to use the full pattern matching capability given by XSL. Sometimes the specific structure is known, like sections in a chapter. When generating a table of contents, it may be easier to scan over the sections.

          $template(contents) <<
            <ol>
            $for-each(section) <<
              <li>$value-of(@title);</li>
            >>
            </ol>
          >>
          

          $import(href);

          Imports a stylesheet. $import lets stylesheets borrow from each other.

          AttributeMeaning
          hrefPath to the imported stylesheet

          $param(name);

          Declares an XSL parameter. $param's select parameter as a default. If the variable has been assigned, it uses the old value.

          AttributeMeaning
          namevariable name
          selectvariable value

          $template(name=>fun) <<
            $param(foo, select=>15);
            $value-of($foo);
          >>
          
          $template(a) <<
            $call-template(fun) <<
              $with-param(foo, select=>1+2);
            >>
          >>
          
          

          3
          

          $processing-instruction(name) <<...>>

          Creates a new processing instruction.

          AttributeMeaning
          nameProcessing instruction name.

          $template(a) <<
            $processing-instruction(foo) << Text for the PI. >>
          >>
          

          <?foo Text for the PI?>
          

          $sort(...) <<...>>

          Sorts nodes in $apply-templates or $for-each.

          AttributeMeaning
          selectvalue to sort on (default = '.')
          orderascending or descending (default = ascending)
          data-typetext or number (default = text)

          Note: case-order is not implemented

          $text() <<...>>

          Writes the contents to the output. $text is useful when you need to force spacing or special text. Usually, XSLT-lite will produce the text you expect. $text is there for the strange cases when you need full control.

          $variable(name);

          Assignes an XSL variable. Variables can be retrieved using the XPath variable syntax.

          AttributeMeaning
          namevariable name
          selectvariable value

          $variable(foo, select=>1+1);
          
          $template(a) <<
            $value-of($foo);
          >>
          

          2
          

          Resin extensions

          $expr(expr);

          Resin 1.2

          Prints the value of the Java expression, expr. Stylesheets can use any Java expression. The following variables are pre-defined in stylesheets.

          VariableMeaning
          nodeThe current org.w3c.dom.Node.
          outThe com.caucho.xsl.XslWriter.

          In addition, the out variable gives access to the servlet PageContext with the page property.

          $template(welcome-user) <<
            $text() <<Welcome back, >>
            $scriptlet() <<
              String user = "Harry";
            >>
            $expr(user);
          >>
          

          $scriptlet() << statement_list >>

          Resin 1.2

          Executes the statement_list scriptlet. The JavaScript code can be any statement list. The same implicit variables are allowed in scriptlets as in expressions.

          The following example creates a number of stars:

          $template(ct:stars) <<
            $scriptlet() <<
              int count = Integer.parseInt(node.getAttribute("count"));
              for (int i = 0; i < count; i++)
                out.print('*');
            >>
          >>
          

          1 = <ct:stars count='1'/>
          9 = <ct:stars count='9'/>
          

          1 = *
          9 = *********
          

          $declaration

          Adds declaration code, i.e. code outside of any function.

          $declaration <<
          double dist(double x1, double y1, double x2, double y2)
          {
            return Math.sqrt((x1 - x2) * (x1 - x2) +
                             (y1 - y2) * (y1 - y2));
          }
          >>
          
          

          $directive.page(attributes);

          Sets page directives.

          namemeaning
          languagescript language, default Java
          sessionuse sessions, default false
          errorPagepage to display for errors
          errorPagepage to display for errors
          importimports Java packages
          contentTypecontent-type of the generated page

          Abbreviations

          $(expr)

          $value-of shortcut prints the value of the XPath expression.

          The value-of syntax is equivalent to:

          $value-of(expr);
          

          <#= expression #>

          $expression shortcut prints the value of expression using the page's scripting language.

          The expression syntax is equivalent to:

          $expr(expression);
          

          <# statement-list #>

          $scriptlet shortcut executes the statements using the page's scripting language.

          The scriptlet is any statement list in the language, e.g. Java.

          The scriptlet syntax is equivalent to

          $scriptlet() <<
          scriptlet
          >>
          

          <#! declaration #>

          $declaration shortcut defines functions and variables.

          The declaration syntax is equivalent to:

          $declaration() <<
          declaration
          >>
          

          <#!
          function dist(x1, y1, x2, y2)
          {
            return Math.sqrt((x1 - x2) * (x1 - x2) +
                             (y1 - y2) * (y1 - y2));
          }
          #>
          
          ct:dist <<
          ($(@x1),$(@y1)) to ($(@x2),$(@y2)) = <#=
          dist(node.attribute.x1, node.attribute.y1,
               node.attribute.x2, node.attribute.y2)
          #>
          
          >>
          

          <ct:dist x1='0' y1='0' x2='5' y2='12'/>
          

          (0,0) to (5,12) = 13
          


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