<s1 title="StyleScript examples">

<summarylist/>

<s2 name=counter title="Counter">

<p>XTP pages can use the counter just by adding the tag:</p>

<example title='counter.xtp'>
<var>A counter example: </var>&lt;ct:counter id='test'/&gt;
</example>

<p>Here the patterns to do it.  For efficiency, we've added the 
<code/cache/> directive.  The cache directive tells XTP to execute the
stylesheet only once and cache the generated JSP file.

<example title='default.xsl'>
&lt;#@ cache #&gt;

counter[@id] &lt;&lt;
<var>&lt;%=
application.attribute["</var><{@id}><var>"]</var>
<var>%&gt;</var>
>>

counter &lt;&lt;
<var>&lt;%= application.attribute.counter++ %></var>
>>

</example>

</s2>
<s2 name=flow title="JSP flow control">

<ul>
<li>ct:get prints the value of a variable
<li>ct:if generates an if statement
<li>ct:iter loops
</ul>

<example title='definition of ct:get'>

ct:get &lt;&lt;
<var>&lt;%=</var> &lt;{@expr}><var> %></var>
>>
</example>

<example title='definition of ct:if'>
ct:if &lt;&lt;
<var>&lt;% if (</var>&lt;{@expr}><var>) { %></var>
  &lt;xsl:apply-templates/>
<var>&lt;% } %></var>
>>
</example>

<example title='definition of ct:iter'>
ct:iter[@index] &lt;&lt;
<var>&lt;% for (var </var>&lt{@index}> <var>in</var> &lt;{@expr}><var>) { %></var>
  &lt;xsl:apply-templates/>
<var>&lt;% } %></var>
>>

ct:iter &lt;&lt;
<var>&lt;% for (var i in </var>&lt;{@expr}><var>) { %></var>
  &lt;xsl:apply-templates/>
<var>&lt;% } %></var>
>>
</example>

</s2></s1>