cocoon-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Mike Engelhart <>
Subject Re: Steep on the XSL/XSP learning curve
Date Sat, 03 Jun 2000 03:54:41 GMT
on 6/2/00 2:52 PM, Charles Yates at 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.
> -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)


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="">
            String selectedEntry = request.getParameter("id");
            if (selectedEntry == null)
                selectedEntry = "1";
            <entry id="1">
                Entry number 1
            <entry id="2">
                Entry number 2
            <entry id="3">
                Entry number 3

/***** XSL PAGE - diary.xsl *****/
<?xml version="1.0"?>
    <xsl:template match="page">
                <title>Diary Entry</title>
                    <xsl:apply-templates select="diary"/>
    <xsl:template match="diary">
        <xsl:for-each select="entry">
            <xsl:if test="@id=../@selection">
                <xsl:value-of select="."/>


View raw message