You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@cocoon.apache.org by "Kjell M. Myksvoll" <kj...@telenor.com> on 2000/07/12 11:14:56 UTC

Order of execution of different namespace tags when using xsp?

Hello,

I have made myself a small taglib called "ls" for accessing a corba
service. This taglib is used by the following complete xml-page:

  <?xml version="1.0" encoding="ISO-8859-1"?>

  <?cocoon-process type="xsp"?>
  <?cocoon-process type="xslt"?>
  <?xml-stylesheet href="test-ls-html.xsl" type="text/xsl"?>

  <xsp:page
    language="java"
    xmlns:xsp="http://www.apache.org/1999/XSP/Core"
    xmlns:request="http://www.apache.org/1999/XSP/Request"
    xmlns:ls="http://fou.telenor.com/ls"
  >

  <page>
   <ls:setTerminalId><request:get-query-string /></ls:setTerminalId>

   <terminal>Terminal = <ls:getTerminalId /></terminal>
   <location>
    Cell ID   = <ls:getCellId   />
    UTM North = <ls:getUTMNorth />
    UTM East  = <ls:getUTMEast  />
    UTM Zone  = <ls:getUTMZone  />
   </location>
  </page>

  </xsp:page>

The problem is that I have to set a value before accessing the corba
service (via the taglib). This is what I tried to do with the
expression

  <ls:setTerminalId><request:get-query-string /></ls:setTerminalId>

above. Unfortunatly this does not works, as the "request" part are
replaced with space (or rather nothing), leading to error in the
resulting java code.

Substituting the expression above with the following one makes it work
as intended.

   <xsp:logic>
    terminal = request.getQueryString();
   </xsp:logic>

Thats okay, but I don't quite like the idea of having to put java code
directly into the xml page in this case. It would be better if the
first expression or something similar worked. Is there any way of
achieving this? Perhaps some way of forcing all the "request" tags to
be executed before the other xsp tags?

best regards,
kmm

Re: Order of execution of different namespace tags when using xsp?

Posted by Hugues Marilleau <hu...@xenon.medisite.net>.
On Wed, Jul 12, 2000 at 02:49:12PM -0400, Donald Ball wrote :
> honestly, this is the only thing that really worries me about XSP - some
> things that you would think would be really simple are in fact subtly
> tricky - never impossible, mind, just nonintuitive. i guess that's where
> we need more and better docs. hey, someone was working on an XSP tutorial
> but it never got linked off of cocoon's site. can the party responsible
> repost the link and i'll add it to the web site myself? merci.
> 

The URL is : http://www.suranyami.com/XSPtutorial/index.html


Re: Order of execution of different namespace tags when using xsp?

Posted by Donald Ball <ba...@webslingerZ.com>.
On Thu, 13 Jul 2000, Jeremy Quinn wrote:

> At 14:49 -0400 12/07/00, Donald Ball wrote:
> 
> >i just struggled through this issue for a site of mine. it's not
> >immediately intuitive,
> 
> I kept asking myself, why are they doing it like this ..... ?
> Gradually it became clear ...
> 
> >but after a while you'll grok it.
> 
> This is the key statement !
> 
> I don't think I would have fully understood an explanation of what is going
> on with XSP, it took making a TagLib myself to really appreciated the
> remarkable but twisted logic of Richardo Rocha :)
> 
> >honestly, this is the only thing that really worries me about XSP - some
> >things that you would think would be really simple are in fact subtly
> >tricky - never impossible, mind, just nonintuitive.
> 
> And some of it is rather difficult to explain, why it does not work
> like so ...

I think the key to understanding is thus - the XSLT logicsheet
transformations occur before compile-time. all of the magic namespace
elements (request, sql, etc.) will be eventually be replaced by xsp
elements, which will then be transformed into java code, which is compiled
and executed. the trickiest bit is the xsp to java transformation - and
that's hard because java isn't an XML language (though it is, in some
sense, a tree).

per-page conditionals can be evaluated in XSLT. per-request conditionals
must be evaluated in java. if that makes any sense.

- donald


Re: Order of execution of different namespace tags when using xsp?

Posted by Jeremy Quinn <je...@media.demon.co.uk>.
At 14:49 -0400 12/07/00, Donald Ball wrote:

>i just struggled through this issue for a site of mine. it's not
>immediately intuitive,

I kept asking myself, why are they doing it like this ..... ?
Gradually it became clear ...

>but after a while you'll grok it.

This is the key statement !

I don't think I would have fully understood an explanation of what is going
on with XSP, it took making a TagLib myself to really appreciated the
remarkable but twisted logic of Richardo Rocha :)

>honestly, this is the only thing that really worries me about XSP - some
>things that you would think would be really simple are in fact subtly
>tricky - never impossible, mind, just nonintuitive.

And some of it is rather difficult to explain, why it does not work like so ...

>i guess that's where
>we need more and better docs. hey, someone was working on an XSP tutorial
>but it never got linked off of cocoon's site. can the party responsible
>repost the link and i'll add it to the web site myself? merci.

I am too busy to write any myself, though I would be happy to comment on,
contribute to, whatever, someone else's dox, if that would be useful.

regards Jeremy
-- 
   ___________________________________________________________________

   Jeremy Quinn                                           Karma Divers
                                                       webSpace Design
                                            HyperMedia Research Centre

   <ma...@mac.com>     		 <http://www.media.demon.co.uk>
    <phone:+44.[0].20.7737.6831>        <pa...@sms.genie.co.uk>

Re: Order of execution of different namespace tags when using xsp?

Posted by "Kjell M. Myksvoll" <kj...@telenor.com>.
* Donald Ball
> my suggestion is to use the get-nested-string template i wrote you
> last time like this:

Ahem! I read your previous post and thought that I understood it and
could not (then) see how it could solve my problem, so I never really
got around to actually try it. Obviously I didn't understood it at
all.

Now I have tried your solution and it works! Thanks! I'm still not
sure of that I understand all that is going on there yet but I'm
working on it....

> - donald

best regards,
kmm

Re: Order of execution of different namespace tags when using xsp?

Posted by Donald Ball <ba...@webslingerZ.com>.
On 13 Jul 2000, Kjell M. Myksvoll wrote:

> * Donald Ball
> > what you want to do in your logicsheet is something like this:
> 
> Thanks for your reply! It gave a very informative description of how I
> can solve an another problem that I've had with applying xsp. The
> problem that I described in my previous mail is still there though...
> 
> Some more description:
> 
>  Using an explicit value works
> 
>    <ls:set-terminal-id>935235235</ls:set-terminal-id>
> 
>  The 935235235 value above are captured fine by the following
>  xsl statement
> 
>  <xsl:template match="ls:set-terminal-id">
>   <xsp:expr>_set_terminal_id("<xsl:value-of select="." />")</xsp:expr>
>  </xsl:template>
> 
>  But when using the following
> 
>    <ls:set-terminal-id><request:get-query-string /></ls:set-terminal-id>
> 
>  the xsl statment does not captures anything.

right - because you're calling value-of on this:

<ls:set-terminal-id><request:get-query-string /></ls:set-terminal-id>

which evaluates to the empty string. you need to apply-templates on the
request:get-query-string element so that it can be transformed by the
request logicsheet into this:

<xsp:expr>request.getQueryString()</xsp:expr>

my suggestion is to use the get-nested-string template i wrote you last
time like this:

<xsl:template match="ls:set-terminal-id">
 <xsl:variable name="arg">
  <xsl:call-template name="get-nested-string">
   <xsl:with-param name="content" select="."/>
  </xsl:call-template>
 </xsl:variable>
 <xsp:expr>_set_terminal_id(<xsl:copy-of select="$arg"/>)</xsp:expr>
</xsl:template>

that's a little overkill for what you're trying to do, but it should give
you the idea on how to generalize this to other situations.

- donald

ps - here's a possibly later revision of get-nested-string:

<xsl:template name="get-nested-string">
 <xsl:param name="content"/>
 ""
 <xsl:for-each select="$content/node()">
  <xsl:choose>
   <xsl:when test="name(.)">
    + <xsl:apply-templates select="."/>
   </xsl:when>
   <xsl:otherwise>
    + "<xsl:value-of select="."/>"
   </xsl:otherwise>
  </xsl:choose>
 </xsl:for-each>
</xsl:template>

also look in the sql.xsl logicsheet to see ricardo's get-nested-content
and get-nested-string methods


Re: Order of execution of different namespace tags when using xsp?

Posted by "Kjell M. Myksvoll" <kj...@telenor.com>.
* Donald Ball
> what you want to do in your logicsheet is something like this:

Thanks for your reply! It gave a very informative description of how I
can solve an another problem that I've had with applying xsp. The
problem that I described in my previous mail is still there though...

Some more description:

 Using an explicit value works

   <ls:set-terminal-id>935235235</ls:set-terminal-id>

 The 935235235 value above are captured fine by the following
 xsl statement

 <xsl:template match="ls:set-terminal-id">
  <xsp:expr>_set_terminal_id("<xsl:value-of select="." />")</xsp:expr>
 </xsl:template>

 But when using the following

   <ls:set-terminal-id><request:get-query-string /></ls:set-terminal-id>

 the xsl statment does not captures anything.

I have reduced the problem to an minimum(?) test case and included the
files at the end here. The files are:

 test-query.xml
 test-query.xsp.xsl
 test-query-html.xsl

Split the files where indicated and save them to a directroy somewhere
and add a line to the xsp file in cocoon.properties like this

 processor.xsp.logicsheet.ls.java = file:///<path>/test-query.xsp.xsl

restart apache and see whats happening. When I run this I get

  Terminal id = 935235235

using an explicit value and

  Terminal id =

when using the request statement ("?<some number>" was added to the
url of course).

Perhaps I'm not doing this in the right way somehow?

> - donald

best regards,
kmm





--- test-query.xml --- cut --- cut ---

<?xml version="1.0" encoding="ISO-8859-1"?>

<?cocoon-process type="xsp"?>
<?cocoon-process type="xslt"?>
<?xml-stylesheet href="test-query-html.xsl" type="text/xsl"?>

<xsp:page
  language="java"
  xmlns:xsp="http://www.apache.org/1999/XSP/Core"
  xmlns:request="http://www.apache.org/1999/XSP/Request"
  xmlns:ls="http://fou.telenor.com/ls"
>
<page>

 <ls:set-terminal-id><request:get-query-string /></ls:set-terminal-id>
<!--
 <ls:set-terminal-id>935235235</ls:set-terminal-id>
-->

 Terminal id = <ls:get-terminal-id />
</page>
</xsp:page>

--- test-query.xsp.xsl --- cut --- cut ---

<?xml version="1.0"?>

<xsl:stylesheet version="1.0"
  xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
  xmlns:xsp="http://www.apache.org/1999/XSP/Core"
  xmlns:ls="http://fou.telenor.com/ls"
>

 <xsl:template match="xsp:page">
  <xsp:page>
   <xsl:copy>
    <xsl:apply-templates select="@*" />
   </xsl:copy>

   <xsp:logic>
    private String _terminal = "-1";
    private String _get_terminal_id() {
        return _terminal;
    }
    private String _set_terminal_id(String id) {
        _terminal = id;
        return "";
    }
   </xsp:logic>

   <xsl:apply-templates />
  </xsp:page>
 </xsl:template>

 <xsl:template match="ls:set-terminal-id">
  <xsp:expr>_set_terminal_id("<xsl:value-of select="." />")</xsp:expr>
 </xsl:template>

 <xsl:template match="ls:get-terminal-id">
  <xsp:expr>_get_terminal_id()</xsp:expr>
 </xsl:template>

 <xsl:template match="@*|*|text()|processing-instruction()">
  <xsl:copy>
   <xsl:apply-templates select="@*|*|text()|processing-instruction()" />
  </xsl:copy>
 </xsl:template>

</xsl:stylesheet>

--- test-query-html.xsl --- cut --- cut ---

<?xml version="1.0" encoding="ISO8859-1"?>

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

<xsl:template match="page">
<xsl:processing-instruction name="cocoon-format">
  type="text/html"
</xsl:processing-instruction>

<html>
 <head><title>TEST QUERY</title></head>
 <body bgcolor="#ffffff"><p><br /></p>

   <xsl:apply-templates/>

 </body>
</html>
</xsl:template>

</xsl:stylesheet>

Re: Order of execution of different namespace tags when using xsp?

Posted by Donald Ball <ba...@webslingerZ.com>.
On 12 Jul 2000, Kjell M. Myksvoll wrote:

> Hello,
> 
> I have made myself a small taglib called "ls" for accessing a corba
> service. This taglib is used by the following complete xml-page:
> 
>   <?xml version="1.0" encoding="ISO-8859-1"?>
> 
>   <?cocoon-process type="xsp"?>
>   <?cocoon-process type="xslt"?>
>   <?xml-stylesheet href="test-ls-html.xsl" type="text/xsl"?>
> 
>   <xsp:page
>     language="java"
>     xmlns:xsp="http://www.apache.org/1999/XSP/Core"
>     xmlns:request="http://www.apache.org/1999/XSP/Request"
>     xmlns:ls="http://fou.telenor.com/ls"
>   >
> 
>   <page>
>    <ls:setTerminalId><request:get-query-string /></ls:setTerminalId>
> 
>    <terminal>Terminal = <ls:getTerminalId /></terminal>
>    <location>
>     Cell ID   = <ls:getCellId   />
>     UTM North = <ls:getUTMNorth />
>     UTM East  = <ls:getUTMEast  />
>     UTM Zone  = <ls:getUTMZone  />
>    </location>
>   </page>
> 
>   </xsp:page>
> 
> The problem is that I have to set a value before accessing the corba
> service (via the taglib). This is what I tried to do with the
> expression
> 
>   <ls:setTerminalId><request:get-query-string /></ls:setTerminalId>
> 
> above. Unfortunatly this does not works, as the "request" part are
> replaced with space (or rather nothing), leading to error in the
> resulting java code.

what you want to do in your logicsheet is something like this:

<xsl:apply-templates select="ls:setTerminalId/*"/>

instead of

<xsl:apply-templates select="ls:setTerminalId"/>

If the element in question might have text, or might have elements from
other logicsheets, and you don't know which or what, you might try
something like this:

<xsl:call-template name="get-nested-string">
 <xsl:with-param name="content" select="ls:setTerminalId"/>
</xsl:call-template>

<xsl:template name="get-nested-string">
 <xsl:param name="content"/>
 ""
 <xsl:for-each select="$content/node()">
  <xsl:choose>
   <xsl:when test="name(.)">
    + <xsl:apply-templates select="."/>
   </xsl:when>
   <xsl:otherwise>
    + "<xsl:value-of select="."/>"
   </xsl:otherwise>
  </xsl:choose>
 </xsl:for-each>
</xsl:template>

(partially based on the get-nested-string method ricardo wrote for the sql
logicsheet, in turn based on the get-nested-content method ricardo wrote
for all of the other logicsheets)

i just struggled through this issue for a site of mine. it's not
immediately intuitive, but after a while you'll grok it.

honestly, this is the only thing that really worries me about XSP - some
things that you would think would be really simple are in fact subtly
tricky - never impossible, mind, just nonintuitive. i guess that's where
we need more and better docs. hey, someone was working on an XSP tutorial
but it never got linked off of cocoon's site. can the party responsible
repost the link and i'll add it to the web site myself? merci.

- donald