<title section="Resin : JSP Tutorial : XTP : ">Link Rewriting</title>

<p/>Rewriting links to encode sessions is a tedious and error-prone task.
If you use URL-encoded sessions, every &lt;a> link and every &lt;form> action
needs a rewritten link using <var/response.encodeURL()/>.  XTP can rewrite
those for you automatically.

<example title="stylesheet.xsl">
&lt;!-- make sure '&lt;' is not printed as '&amp;lt;' -->
$output(disable-output-escaping=>true);

&lt;!-- copy input to output -->
*|@* &lt;&lt;
  $copy() &lt;&lt;
    $apply-templates(node()|@*);
  >>
>>

&lt;!-- rewrite &lt;a href> -->
a[@href] &lt;&lt;
  &lt;a href='&lt;%= response.encodeURL("{@href}") %>'>
    $apply-templates(node()|@*[name(.)!="href"]);
  &lt;/a>
>>
</example>

<p/>Your XTP page may look something like:

<ct:example title='test.xtp'>
&lt;?xml-stylesheet href='stylesheet.xsl'?>
&lt;h1>My test&lt;/h1>

Adding: 2 + 2 = &lt;%= 2 + 2 %>

&lt;p>New? &lt;%= session.isNew() %>

&lt;p>And &lt;a href='test.xtp'>linking&lt;/a>
</ct:example>

<p/>The transformed file will look like:

<ct:results>
&lt;?xml-stylesheet href='stylesheet.xsl'?>
&lt;h1>My test&lt;/h1>

Adding: 2 + 2 = &lt;%= 2 + 2 %>

&lt;p>New? &lt;%= session.isNew() %>

&lt;p>And &lt;a href='&lt;%= response.encodeURL("test.xtp") %>'>linking&lt;/a>
</ct:results>
