cocoon-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Mike Engelhart <mengelh...@earthtrip.com>
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 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


Mime
View raw message