You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@cocoon.apache.org by Laurent Eskenazi <le...@mail.inforama.fr> on 2000/04/19 17:29:31 UTC

Sessions & Cookies

Hi!

I have a problem with cocoon when using sessions with cookies disabled
browsers.
Here is a simple example to understand the problem:

My XML:
<foo id="35">
bar
</foo>

Associated XSL:
<xsl:template match="foo">
  <a href="index.xml?id={@id}"/><xsl:apply-templates/></a>
</xsl:template>

Generated HTML:
<a href="index.xml?id=35>bar</a>

Everything is OK when I'm not using sessions with cookies disabled browsers.
But if I have to use sessions with cookies disabled browsers, I am supposed
to use the Java method response.encodeUrl() on every URL to add the session
reference in this URL. If I don't, I loose my session and every data in
it...

My problem is that I don't know how to use some Java code in my XSL. How do
people handle this problem ?

Thanks

Laurent



Re: Sessions & Cookies

Posted by tom stuart <to...@obsess.com>.
> OK. I know how to put some java in my XML pages...but how to put some
> in my XSL ?

XSL *is* XML. You can do any of the XSP stuff in your XSL pages too.

See Nicholas Hemley's earlier posting today about retrieving the request
parameters into an XSL file -

 http://xml-archive.webweaving.org/xml-archive-cocoon-users/2361.html

- for a good example that you should be able to build on.

And as for the anchor tag, you probably want to do it like this (once
you've retrieved the 'id' parameter and built your URL string elsewhere in
the XSP page):

	<a>
	<xsl:attribute name="href">
	<xsp:expr>response.encodeURL(myURL)</xsp:expr>
	</xsl:attribute>
	</a>

Hope this helps.

-Tom


Re: Sessions & Cookies

Posted by Laurent Eskenazi <le...@mail.inforama.fr>.
> That's what XSP is for. Like JSP (Java Server Pages) to some extent, XSP
> lets you use Java code in your XML and XSL. There's more information at:

OK. I know how to put some java in my XML pages...but how to put some in mys
XSL ?
How can I do something like:

<xsl:template match="foo">
  <a href=<xsp:expr>response.encodeURL("index.xml?id={@id}")</xsp:expr>
/><xsl:apply-templates/></a>
</xsl:template>

( I know the tag are nested in an incorrect way...)

Thanks for your help.

Laurent



Re: Sessions & Cookies

Posted by tom stuart <to...@obsess.com>.
On Wed, 19 Apr 2000, Laurent Eskenazi wrote:

> I am supposed to use the Java method response.encodeUrl() on every URL
> to add the session reference in this URL.
>
> My problem is that I don't know how to use some Java code in my XSL. How do
> people handle this problem ?

That's what XSP is for. Like JSP (Java Server Pages) to some extent, XSP
lets you use Java code in your XML and XSL. There's more information at:

	http://xml.apache.org/cocoon/xsp.html

To give you some idea of what it's all about, the example cited in the
documentation is:

---

<?xml version="1.0"?>
<?cocoon-process type="xsp"?>
<?cocoon-process type="xslt"?>
<?xml-stylesheet href="sample.xsl" type="text/xsl"?>

<xsp:page language="java" xmlns:xsp="http://www.apache.org/1999/XSP/Core">
  <page title="Time of Day">
  
    <xsp:logic>
      // Define a variable to hold the time of day
      Date now = new Date();
    </xsp:logic>
  
    <p>
      To the best of my knowledge, it's now
      <!-- Substitute time of day here -->
      <xsp:expr>now</xsp:expr>
    </p>
  </page>
</xsp:page

---

XSP should be able to do what you need.

-Tom