caucho
 


'StyleScript' adds some syntactic sugar to XSLT to make stylesheets more readable. It lets authors cut down on XSL's verbosity, without losing any of the power. Stylesheets are also freed from the constraints of XML, like entity references ('&').

StyleScript can treat unknown elements as text, like JSP. Setting the xsl:stylesheet attribute parsed-content to false will treat elements as text. By default, StyleScript uses XSLT behaviour. StyleScript templates can create the HTML '<br>', even though it's illegal XML. It doesn't expand entities in templates. '&lt;' produces 4 characters.

StyleScript doesn't expand entities in templates. '&lt;' produces 4 characters. To escape in StyleScript, use the backslash as in JSP.

Index
$(expression)
<# scriptlet #>The scriptlet is any statement list in the language, e
<#! declaration #>
<#= expression #>
<#@ cache attributes #>Caching for XSL is more complicated than for JSP because only some templates may be used in a page
<#@ page attributes #>
pattern <# scriptlet #>
pattern <#= expression #>
pattern << xsl-content >>

<#@ 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
Equivalent to:

<xtp:directive.page attributes/>

<#@ cache attributes #>

Caches the generated JSP file by default.

Caching for XSL is more complicated than for JSP because only some templates may be used in a page. Caching is based on the generated page, not simply on the stylesheet.

A page that just uses static templates is automatically cached. Pages that use scripts just for simple calculation can also be cached. But pages that use scripts based on the request cannot be cached.

namemeaning
filethe JSP file depends on file.
no-cachedo not cache the generated JSP.
Equivalent to:

<xtp:directive.cache attributes/>
The following example caches by default, but disables caching when using the counter:

<#@ cache #>

ct:counter <<
<#@ cache no-cache #>
<#= out.page.application.attribute.counter++ #>
>>
Or programmatically:

<#@ cache #>

ct:counter <#
out.setNotCacheable();
out.write(out.page.application.attribute.counter++)
#>

pattern << xsl-content >>

Short form of xsl:template. xsl-content is any normal xsl content including text and the StyleScript actions.

The short template syntax is equivalent to:

<xsl:template match='pattern'>
xsl-content
</xsl:template>

pattern <#= expression #>

Templates which just print an expression. expression is a Java or JavaScript expression.

The syntax is equivalent to:

<xsl:template match='pattern'>
<xtp:expression>
  expression
</xtp:expression>
</xsl:template>

pattern <# scriptlet #>

Templates which are generated by JavaScript or Java.

The syntax is equivalent to:

<xsl:template match='pattern'>
<xtp:scriptlet>
  scriptlet
</xtp:scriptlet>
</xsl:template>

$(expression)

Prints the value of the XSL expression. This syntax is a short cut for the xsl:value-of tag.

The value-of syntax is equivalent to:

<xsl:value-of select="expression"/>

<#= expression #>

Prints the value of expression using the page's language.

The expression syntax is equivalent to:

<xtp:expression>
expression
</xtp:expression>
For example, to print the request URL using JavaScript:

ct:url <<
url: <#= out.page.request.requestURL #>
>>

url: /test/url.xtp

<# scriptlet #>

Executes the statements in scriptlet using the page's language.

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

The scriptlet syntax is equivalent to

<xtp:scriptlet>
scriptlet
</xtp:scriptlet>
For example, to print all headers:

ct:headers <<
Headers: <# 
  for (var header in out.page.request.header) {
    out.println(header, ":", out.page.request.header[header]);
  }
#>
>>

<#! declaration #>

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

The declaration syntax is equivalent to:

<xtp:declaration>
declaration
</xtp: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


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