You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@cocoon.apache.org by Charles Yates <ce...@pacbell.net> on 2000/06/02 21:52:08 UTC

Steep on the XSL/XSP learning curve

Hello,

  I have a xml file of the form:

<diary>
  <entry id=1>
     blah
  </entry>
.....
  <entry id=n>
    blah blah blah
  </entry>
</diary>

1) I'd like my web server to serve up one entry at a time
based on a parameter in the url.

2) I'd like to keep content, logic and presentation separate.

3) I've been learning a lot about XSP and XSL in tackling this
problem but am not very successful in solving it so I thought
I'd ask for help.

4)  Don't need hand holding, just need to be pointed in the right
direction.

-thanks, Charles



Re: Steep on the XSL/XSP learning curve

Posted by Mike Engelhart <me...@earthtrip.com>.
on 6/2/00 11:23 PM, Charles Yates at ceyates@pacbell.net wrote:

> 
> Thanks Mike, that did the trick.  I was pulling my hair out trying to do it
> without
> putting any logic in the source file.  Now that I've got the thing working I
> can work
> on that.
> 
> thanks again, Charles
No problem.

Once you get the semantics of how the pages need to be structured it gets
much easier ;-)

Mike


Re: Steep on the XSL/XSP learning curve

Posted by Charles Yates <ce...@pacbell.net>.
Mike Engelhart wrote:

> Hey Charles,
>
> Here is an extremely simple XSP and XSL stylesheet so you can see how this
> all works.  Copy the XSP stuff into a file called "diary.xml" and stick in
> on your server  <snip>

Thanks Mike, that did the trick.  I was pulling my hair out trying to do it without
putting any logic in the source file.  Now that I've got the thing working I can work
on that.

thanks again, Charles


Re: Steep on the XSL/XSP learning curve

Posted by Mike Engelhart <me...@earthtrip.com>.
on 6/2/00 2:52 PM, Charles Yates at ceyates@pacbell.net wrote:

> Hello,
> 
> I have a xml file of the form:
> 
> <diary>
> <entry id=1>
> blah
> </entry>
> .....
> <entry id=n>
> blah blah blah
> </entry>
> </diary>
> 
> 1) I'd like my web server to serve up one entry at a time
> based on a parameter in the url.
> 
> 2) I'd like to keep content, logic and presentation separate.
> 
<snip>
> -thanks, Charles
> 

Hey Charles,

Here is an extremely simple XSP and XSL stylesheet so you can see how this
all works.  Copy the XSP stuff into a file called "diary.xml" and stick in
on your server (assuming all is well with Cocoon - refer to the
documentation if you haven't set up cocoon yet).  Then put the XSL page into
a file called "diary.xsl" and put this in the same directory.   You can call
this by something like (using your own path of course)

http://localhost/cocoon/diary.xml?id=2

There are probably a million ways to do this but this is probably the
easiest to grasp.  Hope this helps.  There's definitely a big learning curve
(I'm still in it...) but it's well worth it...




/***** XSP PAGE - diary.xml *****/
<?xml version="1.0"?>

<?cocoon-process type="xsp"?>
<?cocoon-process type="xslt"?>

<?xml-stylesheet href="diary.xsl" type="text/xsl"?>

<xsp:page language="java" xmlns:xsp="http://www.apache.org/1999/XSP/Core">
    <page>
        <xsp:logic>
            String selectedEntry = request.getParameter("id");
            if (selectedEntry == null)
                selectedEntry = "1";
        </xsp:logic>
        <diary>
            <xsp:attribute
name="selection"><xsp:expr>selectedEntry</xsp:expr></xsp:attribute>
            <entry id="1">
                Entry number 1
            </entry>
            <entry id="2">
                Entry number 2
            </entry>
            <entry id="3">
                Entry number 3
            </entry>
        </diary>
    </page>
</xsp:page>

/***** XSL PAGE - diary.xsl *****/
<?xml version="1.0"?>
<xsl:stylesheet 
    xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
    version="1.0">
    
    <xsl:template match="page">
        <html>
            <head>
                <title>Diary Entry</title>
            </head>
            <body>
                <h1>
                    <xsl:apply-templates select="diary"/>
                </h1>
            </body>
        </html>
    </xsl:template>
    
    <xsl:template match="diary">
        <xsl:for-each select="entry">
            <xsl:if test="@id=../@selection">
                <xsl:value-of select="."/>
            </xsl:if>
        </xsl:for-each>
    </xsl:template>
    
</xsl:stylesheet>


Mike


Re: Steep on the XSL/XSP learning curve

Posted by Donald Ball <ba...@webslingerZ.com>.
On Mon, 5 Jun 2000, Jeremy Quinn wrote:

> At 16:11 -0400 04/06/00, Donald Ball wrote:
> >I just checked in a workaround for this - I added the HTTP method to the
> >Utils.encode method so that HEAD and GET (and POST) methods are cached
> >independently. See if that helps out. I don't _think_ this will break
> >anything since I didn't see anything in the code that relies on the
> >encoded string having a particular format, but I could be wrong.
> 
> Hi Donald,
> 
> Do you think it would be feasable to handle the difference between HEAD and
> GET methods in my XSP?
> 
> ie. return a custom set of HTTP Headers only, for the HEAD request and the
> full content for a GET request.
> 
> Do I have control over the HTTP Headers from XSP?

I dunno. I'm the wrong person to ask about such matters... sorry!

- donald


Re: Steep on the XSL/XSP learning curve

Posted by Jeremy Quinn <je...@media.demon.co.uk>.
At 16:11 -0400 04/06/00, Donald Ball wrote:
>I just checked in a workaround for this - I added the HTTP method to the
>Utils.encode method so that HEAD and GET (and POST) methods are cached
>independently. See if that helps out. I don't _think_ this will break
>anything since I didn't see anything in the code that relies on the
>encoded string having a particular format, but I could be wrong.

Hi Donald,

Do you think it would be feasable to handle the difference between HEAD and
GET methods in my XSP?

ie. return a custom set of HTTP Headers only, for the HEAD request and the
full content for a GET request.

Do I have control over the HTTP Headers from XSP?


thanks

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: Steep on the XSL/XSP learning curve

Posted by Jeremy Quinn <je...@media.demon.co.uk>.
At 10:34 -0500 05/06/00, Mike Engelhart wrote:
>
>If you're using CodeWarrior for Java, it comes with Java2 libraries.  you
>can' really run things with it but it's fine for compiling against.

thanks 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: Steep on the XSL/XSP learning curve

Posted by Mike Engelhart <me...@earthtrip.com>.
on 6/5/00 4:28 AM, Jeremy Quinn at jeremy@media.demon.co.uk wrote:

> Has anyone out there managed to compile Cocoon under MacOS?
> 
> The build seems to require tools.jar, which is Java 1.2 right?
Yeah, I've built it under MacOS (only Cocon 1.x  though)

If you're using CodeWarrior for Java, it comes with Java2 libraries.  you
can' really run things with it but it's fine for compiling against.

Mike


Re: Steep on the XSL/XSP learning curve

Posted by Jeremy Quinn <je...@media.demon.co.uk>.
At 16:11 -0400 04/06/00, Donald Ball wrote:
>On Sun, 4 Jun 2000, Jeremy Quinn wrote:
>
>> Except when your browser checks the page first with a HEAD request, then
>> does a GET request. The parameter is not available for some reason when
>> responding to a HEAD request. See HEAD/GET Bug, Cocoon-Dev.
>>
>> Still trying to find a work around and a reason for this :(
>
>I just checked in a workaround for this - I added the HTTP method to the
>Utils.encode method so that HEAD and GET (and POST) methods are cached
>independently.

Excellent, it will certainly help

>See if that helps out. I don't _think_ this will break
>anything since I didn't see anything in the code that relies on the
>encoded string having a particular format, but I could be wrong.

I have never compiled Cocoon before =(
Can I do it without Java 1.2?

Has anyone out there managed to compile Cocoon under MacOS?

The build seems to require tools.jar, which is Java 1.2 right?

>Now as to why the querystring parameters aren't getting parsed when a HEAD
>request is received - I dunno. Seems like a problem with the servlet
>engine, honestly.

That is what I was beginning to think.

ie. request.getNamedParameters() failing during a HEAD request.

If this is the case, I am surprised no one found it before !?

thanks Donald

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: Steep on the XSL/XSP learning curve

Posted by Donald Ball <ba...@webslingerZ.com>.
On Sun, 4 Jun 2000, Jeremy Quinn wrote:

> Except when your browser checks the page first with a HEAD request, then
> does a GET request. The parameter is not available for some reason when
> responding to a HEAD request. See HEAD/GET Bug, Cocoon-Dev.
> 
> Still trying to find a work around and a reason for this :(

I just checked in a workaround for this - I added the HTTP method to the
Utils.encode method so that HEAD and GET (and POST) methods are cached
independently. See if that helps out. I don't _think_ this will break
anything since I didn't see anything in the code that relies on the
encoded string having a particular format, but I could be wrong.

Now as to why the querystring parameters aren't getting parsed when a HEAD
request is received - I dunno. Seems like a problem with the servlet
engine, honestly.

- donald


Re: Steep on the XSL/XSP learning curve

Posted by Jeremy Quinn <je...@media.demon.co.uk>.
At 02:15 -0400 04/06/00, Donald Ball wrote:
>> 1) I'd like my web server to serve up one entry at a time
>> based on a parameter in the url.
>
><?xml version="1.0"?>
><xsl:stylesheet xmlns=...>
> <xsl:param name="entry">defaultnumber</xsl:param>
> <xsl:template match="entry[@id=$entry]">
>  ... style ...
> </xsl:template>
></xsl:stylesheet>
>
>foo.xml?entry=1
>
>> 3) I've been learning a lot about XSP and XSL in tackling this
>> problem but am not very successful in solving it so I thought
>> I'd ask for help.
>
>XSP isn't necessary for something this simple.

Except when your browser checks the page first with a HEAD request, then
does a GET request. The parameter is not available for some reason when
responding to a HEAD request. See HEAD/GET Bug, Cocoon-Dev.

Still trying to find a work around and a reason for this :(


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: Steep on the XSL/XSP learning curve

Posted by "S. Champ" <s-...@postoffice.pacbell.net>.
> Donald Ball wrote:
> 
> > XSP isn't necessary for something this simple.

...how kind it seems for you to say that... .


Charles Yates wrote:
> 
> Thanks Donald, that worked really well.
> 
> Anyone interested in seeing the results of my
> efforts and a very simple implementation of
> cocoon  (including a view of the source and
> stylesheet files) can follow the link below and
> click on "A Trip to Alaska".  I have a dynamic IP
> address so my server may not be up when you try.
> 
> -Charles
> 
> Donald Ball wrote:
> 
> > XSP isn't necessary for something this simple.
> >
> > - donald
> 
> --
> http://home.pacbell.net/ceyates
> 
>   --------------------------------------------------------------------- To
> unsubscribe, e-mail: cocoon-users-unsubscribe@xml.apache.org For additional
> commands, e-mail: cocoon-users-help@xml.apache.org

Re: Steep on the XSL/XSP learning curve

Posted by Donald Ball <ba...@webslingerZ.com>.
On Fri, 2 Jun 2000, Charles Yates wrote:

> Hello,
> 
>   I have a xml file of the form:
> 
> <diary>
>   <entry id=1>
>      blah
>   </entry>
> .....
>   <entry id=n>
>     blah blah blah
>   </entry>
> </diary>
> 
> 1) I'd like my web server to serve up one entry at a time
> based on a parameter in the url.

<?xml version="1.0"?>
<xsl:stylesheet xmlns=...>
 <xsl:param name="entry">defaultnumber</xsl:param>
 <xsl:template match="entry[@id=$entry]">
  ... style ...
 </xsl:template>
</xsl:stylesheet>

foo.xml?entry=1

> 3) I've been learning a lot about XSP and XSL in tackling this
> problem but am not very successful in solving it so I thought
> I'd ask for help.

XSP isn't necessary for something this simple.

- donald