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 |
$declaration | Adds 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 |
$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.
attribute | meaning
|
select | An XPath select pattern selecting the nodes to
evaluate next. (optional)
|
mode | only 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>
|
Adds an attribute to the element. The name can be computed
using an attribute value template.
Attribute | Meaning
|
name | Name of the new attribute.
|
$template(a) <<
<c>
$attribute (b{@id}) <<
$value-of(c{@id});
>>
</c>
>>
|
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());
>>
>>
|
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"/>
|
Controls the output printing.
Attribute | Meaning
|
method | xml or html or text. Select printing method
|
version | XML version
|
encoding | character set to print the results
|
omit-xml-declaration | skip the XML or HTML declaration
|
indent | pretty-print or not
|
media-type | mime-type
|
disable-output-escaping | '<' gets printed as '<', not '<'
|
$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.
attribute | meaning
|
match | the XPath match pattern (required)
|
mode | string grouping templates into a special mode
|
name | Name for later use by call-template
|
priority | conflict-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>
|
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>
>>
|
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.
Attribute | Meaning
|
name | Name 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.
Attribute | Meaning
|
name | template name to call
|
mode | template mode
|
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.
Attribute | Meaning
|
test | XPath expression evaluating to a boolean.
|
$template(a) <<
$choose() <<
$when(@color="red") <<stop>>
$when(@color="green") <<go>>
$otherwise() <<yield>>
>>
>>
|
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. -->
|
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.
attribute | meaning
|
select | An XPath expression to be copied.
|
Creates a new element. The name can be computed using
an attribute value template.
Attribute | Meaning
|
name | Name of the new element.
|
$template(a) <<
$element(b{@id}) <<
<c/>
>>
>>
|
$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>
>>
|
Imports a stylesheet. $import lets stylesheets
borrow from each other.
Attribute | Meaning
|
href | Path to the imported stylesheet
|
Declares an XSL parameter. $param's
select parameter as a default. If the variable has been
assigned, it uses the old value.
Attribute | Meaning
|
name | variable name
|
select | variable value
|
$template(name=>fun) <<
$param(foo, select=>15);
$value-of($foo);
>>
$template(a) <<
$call-template(fun) <<
$with-param(foo, select=>1+2);
>>
>>
|
$processing-instruction(name) <<...>> | |
Creates a new processing instruction.
Attribute | Meaning
|
name | Processing instruction name.
|
$template(a) <<
$processing-instruction(foo) << Text for the PI. >>
>>
|
Sorts nodes in $apply-templates or
$for-each.
Attribute | Meaning
|
select | value to sort on (default = '.')
|
order | ascending or descending (default = ascending)
|
data-type | text or number (default = text)
|
Note: case-order is not implemented
Writes the contents to the output. $text is
useful when you need to force spacing or special text. Usually,
StyleScript will produce the text you expect. $text is there
for the strange cases when you need full control.
Assignes an XSL variable. Variables can be retrieved using
the XPath variable syntax.
Attribute | Meaning
|
name | variable name
|
select | variable value
|
$variable(foo, select=>1+1);
$template(a) <<
$value-of($foo);
>>
|
$expr(expr);
Prints the value of the Java expression, expr.
Stylesheets can use any Java expression. The following
variables are pre-defined in stylesheets.
Variable | Meaning
|
node | The current org.w3c.dom.Node.
|
out | The 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 >>
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'/>
|
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.
name | meaning
|
language | script language, default Java
|
session | use sessions, default false
|
errorPage | page to display for errors
|
errorPage | page to display for errors
|
import | imports Java packages
|
contentType | content-type of the generated page
|
$value-of shortcut prints the value of the XPath expression.
The value-of syntax is equivalent to:
$expression shortcut prints the value of expression using
the page's scripting language.
The expression syntax is equivalent to:
$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 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'/>
|
Copyright © 1998-2002 Caucho Technology, Inc. All rights reserved.
Resin® is a registered trademark,
and HardCoretm and Quercustm are trademarks of Caucho Technology, Inc. | |
|