caucho
Resin
FAQ
Reference Guide
Demo
Tutorial

JSP page
Config
URLs
Database Forms
XTP Copy
Hello Tag
Vary Filter
HardCore
Mailing Forms
Beans
Cache
XSL Filter
run-at

Formatting
XTP Page
JSP Tag Libraries with XTP
JSP Tag Libraries with StyleScript
 Link Rewriting

Formatting
XTP Copy
JSP Tag Libraries with XTP

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

stylesheet.xsl
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
                version="1.0">

  <!-- make sure '<' is not printed as '&lt;' -->
  <xsl:output disable-output-escaping='true'/>

  <!-- copy input to output -->
  <xsl:template match='*|@*'>
    <xsl:copy>
      <xsl:apply-templates select='node()|@*'/>
    </xsl:copy>
  </xsl:template>

  <!-- rewrite <a href> -->
  <xsl:template match="a[@href]">
    <a href='<%= response.encodeURL("{@href}") %>'>
      <xsl:apply-templates select="node()|@*[name(.)!="href"]"/>
    </a>
  </xsl:template>
</xsl:stylesheet>

Your XTP page may look something like:

test.xtp
<?xml-stylesheet href='stylesheet.xsl'?>
<h1>My test</h1>

Adding: 2 + 2 = <%= 2 + 2 %>

<p>New? <%= session.isNew() %>

<p>And <a href='test.xtp'>linking</a>

The transformed file will look like:

<?xml-stylesheet href='stylesheet.xsl'?>
<h1>My test</h1>

Adding: 2 + 2 = <%= 2 + 2 %>

<p>New? <%= session.isNew() %>

<p>And <a href='<%= response.encodeURL("test.xtp") %>'>linking</a>


Formatting
XTP Copy
JSP Tag Libraries with XTP
Copyright © 1998-2002 Caucho Technology, Inc. All rights reserved.
Resin® is a registered trademark, and HardCoretm and Quercustm are trademarks of Caucho Technology, Inc.