<title>StyleScript</title>
  
'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 ('&amp;amp;').

<p/>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 '&lt;br>', even though it's
illegal XML.  It doesn't expand entities in templates. '&amp;lt;'
produces 4 characters.  

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

<objsummary/>

<section name='directives' title='directives'>

<defun name=page title='&lt;#@ page attributes #>'>
<sum>Sets page directives</sum>
<deftable>
<tr><th>name<th>meaning
<tr><td>language<td>script language, default Java
<tr><td>session<td>use sessions, default false
<tr><td>errorPage<td>page to display for errors
<tr><td>errorPage<td>page to display for errors
<tr><td>import<td>imports Java packages 
<tr><td>contentType<td>content-type of the generated page
</deftable>

Equivalent to:
<def>
&lt;xtp:directive.page <var/attributes/>/>
</def>

</defun>

<defun name=cache title='&lt;#@ cache attributes #>'>

<sum>Caches the generated JSP file by default.</sum>

<p>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.

<p/>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.

<deftable>
<tr><th>name<th>meaning
<tr><td>file<td>the JSP file depends on <var/file/>.
<tr><td>no-cache<td>do not cache the generated JSP.
</deftable>

Equivalent to:
<def>
&lt;xtp:directive.cache <var/attributes/>/>
</def>

The following example caches by default, but disables caching when
using the counter:
<example>
&lt;#@ cache #>

ct:counter <<
&lt;#@ cache no-cache #>
&lt;#= out.page.application.attribute.counter++ #>
>>
</example>

Or programmatically:
<example>
&lt;#@ cache #>

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

</defun>

</section>

<section name='templates' title='templates'>

<defun name=short-content title='pattern &lt;&lt; xsl-content >>' index='template'>
<sum>Short form of xsl:template.</sum>  <var/xsl-content/> is any
normal xsl content including text and the StyleScript actions.

<p/>The short template syntax is equivalent to:
<def>
&lt;xsl:template match='<var/pattern/>'>
<var/xsl-content/>
&lt;/xsl:template>
</def>

</defun>

<defun name=temp-expr title='pattern &lt;#= expression #>'
index='template, expression'>
<sum>Templates which just print an expression.</sum>  <var/expression/> is
a Java or JavaScript expression.

<p/>The syntax is equivalent to:
<def>
&lt;xsl:template match='<var/pattern/>'>
&lt;xtp:expression>
  <var/expression/>
&lt;/xtp:expression>
&lt;/xsl:template>
</def>

</defun>

<defun name=temp-script title='pattern &lt;# scriptlet #>'
index='template, expression'>
<sum>Templates which are generated by JavaScript or Java.</sum>

<p/>The syntax is equivalent to:
<def>
&lt;xsl:template match='<var/pattern/>'>
&lt;xtp:scriptlet>
  <var/scriptlet/>
&lt;/xtp:scriptlet>
&lt;/xsl:template>
</def>

</defun>

</section>

<section name='actions' title='actions'>

<defun name=value-of title='$(expression)'
       index='value-of'>
<sum>Prints the value of the XSL <var/expression/>.</sum>  This syntax
is a short cut for the xsl:value-of tag.

<p/>The value-of syntax is equivalent to:
<def>
&lt;xsl:value-of select="<var/expression/>"/>
</def>

</defun>

<defun name=expression title='&lt;#= expression #&gt;'
       index='expression'>
<sum>Prints the value of <var/expression/> using the page's language.</sum>

<p/>The expression syntax is equivalent to:
<def>
&lt;xtp:expression>
<var/expression/>
&lt;/xtp:expression>
</def>

For example, to print the request URL using JavaScript:
<example>
<example>
ct:url &lt;&lt;
url: &lt;#= out.page.request.requestURL #&gt;
>>
</example>
<results>
url: /test/url.xtp
</results>
</example>

</defun>

<defun name=scriptlet title='&lt;# scriptlet #&gt;'
       index='scriptlets'>
<sum>Executes the statements in <var/scriptlet/> using the page's
<a href='jsp-directives.xtp#language'>language</a>.</sum>

<p>The <var/scriptlet/> is any statement list in the language,
e.g. Java.

<p/>The scriptlet syntax is equivalent to 
<def>
&lt;xtp:scriptlet>
<var/scriptlet/>
&lt;/xtp:scriptlet>
</def>

For example, to print all headers:
<example>
ct:headers &lt;&lt;
Headers: &lt;# 
  for (var header in out.page.request.header) {
    out.println(header, ":", out.page.request.header[header]);
  }
#>
>>
</example>

</defun>

<defun name=declaration title='&lt;#! declaration #&gt;'
       index='declaration'>
<sum>Adds declaration code, i.e. code outside of any function.</sum>

<p/>The declaration syntax is equivalent to:
<def>
&lt;xtp:declaration>
<var/declaration/>
&lt;/xtp:declaration>
</def>

<example>
<example>
&lt;#!
function dist(x1, y1, x2, y2)
{
  return Math.sqrt((x1 - x2) * (x1 - x2) +
                   (y1 - y2) * (y1 - y2));
}
#>

ct:dist &lt;&lt;
($(@x1),$(@y1)) to ($(@x2),$(@y2)) = &lt#=
dist(node.attribute.x1, node.attribute.y1,
     node.attribute.x2, node.attribute.y2)
#>

>>
</example>
<example>
&lt;ct:dist x1='0' y1='0' x2='5' y2='12'/>
</example>
<results>
(0,0) to (5,12) = 13
</results>
</example>

</defun>
</section>
