You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@cocoon.apache.org by Ben Pope <no...@hotmail.com> on 2004/07/18 20:05:57 UTC
Request Parameters in XSLT (Cocoon 2.1.5)
Hi,
I've done my research and read this list for around a week, but it's not
having any of it. Request parameters don't seem to be passed into the XSLT.
I stripped down my code to the following noddy example and tried it, without
success:
Sitemap.xmap:
-------------
<?xml version="1.0"?>
<map:sitemap xmlns:map="http://apache.org/cocoon/sitemap/1.0">
<map:components>
<map:transformers>
<map:transformer name="xslt"
src="org.apache.cocoon.transformation.TraxTransformer">
<!-- THE FOLLOWING IS LINE WITH COMMENT 1 -->
<use-request-parameters>true</use-request-parameters>
</map:transformer>
</map:transformers>
</map:components>
<map:pipelines>
<map:pipeline>
<map:match pattern="output">
<map:generate src="input.xml" type="file"/>
<map:transform src="output.xsl" type="xslt">
<!-- THE FOLLOWING IS LINE WITH COMMENT 2 -->
<!-- <map:parameter
name="use-request-parameters" value="true"/> -->
<!-- THE FOLLOWING IS LINE WITH COMMENT 3 -->
<!-- <map:parameter name="sort"
value="date" /> -->
</map:transform>
<map:serialize/>
</map:match>
</map:pipeline>
</map:pipelines>
</map:sitemap>
input.xml:
----------
<?xml version="1.0" encoding="UTF-8"?>
<?xml-stylesheet type="text/xsl" href="output.xsl"?> <data>
<reports>
<report>
<number>1</number>
<date>03/08/01</date>
</report>
<report>
<number>2</number>
<date>03/07/01</date>
</report>
<report>
<number>3</number>
<date>22/10/01</date>
</report>
</reports>
</data>
output.xsl:
-----------
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:template match="/">
<!-- THE FOLLOWING IS LINE WITH COMMENT 4 --> <xsl:param name="sort"/>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html;
charset=iso-8859-1" />
<title>Report</title>
</head>
<body>
<!-- THE FOLLOWING IS LINE WITH COMMENT 5 -->
<p>Reports - sort order = <xsl:value-of select="$sort"/>.</p>
<p>
<table border="1">
<tr>
<th><a href="?sort=number">Number</a></th>
<th><a href="?sort=date">Date</a></th>
</tr>
<xsl:for-each select="data/reports/*">
<!-- THE FOLLOWING IS LINE WITH COMMENT 6 -->
<xsl:sort select="$sort"/>
<tr>
<td><xsl:value-of select="number"/></td>
<td><xsl:value-of select="date"/></td>
</tr>
</xsl:for-each>
</table>
</p>
</body>
</html>
</xsl:template>
</xsl:stylesheet>
Comments:
1. Specify use request parameters globally for transformer.
2. Specify use request parameters on a pipeline basis.
3. Create a parameter and pass it in "manually".
4. Declare parameter in XSLT.
5. Use parameter to write into HTML Body.
6. Use parameter to specify sort order.
When I make a request as such:
http://path/to/sitemap/output?sort=date
Using methods 1, 2 or 3 all result in 5 producing "" and 6 not working
(presumably the same result).
Now, I would suspect that methods 1, 2 OR 3 should all work, but the
parameter does not appear to be passed in.
The section of HTML I get back is:
<p>Reports - sort order = .</p>
But I would expect:
<p>Reports - sort order = date.</p>
If I put:
<xsl:sort select="date"/> instead of <xsl:sort select="$sort"/>
The report order is 2,1,3 as expected - hence I know it's processing the
pipeline, not sending input.xml and leaving the rendering all to IE!
Anybody got any ideas on what I've missed? This is driving me mad!
I've tried this from Jetty (shipped with Cocoon) and Tomcat 5.0.25 under
Windows 2000 SP4, everything is default, just extracted the source and did a
"build webapp" and dropped those files in suitable locations.
There wasn't a .war file created (as the documentation suggests) so I just
dumped the webapp directory as-is into the Tomcat directory. Cocoon appears
to work, apart from the request parameters. (all the samples seem to work
in both configs)
Any help is MUCH appreciated. Alternative methods that are more appropriate
are also welcomed.
Thank you for your time,
Ben
---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@cocoon.apache.org
For additional commands, e-mail: users-help@cocoon.apache.org
Re: Request Parameters in XSLT (Cocoon 2.1.5)
Posted by Ben Pope <be...@hotmail.com>.
Hi,
Thats excellent. I'll give that a try when I finish work.
..I'll get the hang of this eventually :-)
Cheers!
Ben
----- Original Message -----
From: "Adam Walsh" <aw...@contal.net.au>
To: <us...@cocoon.apache.org>
Sent: Monday, July 19, 2004 2:59 AM
Subject: Re: Request Parameters in XSLT (Cocoon 2.1.5)
> Hi Ben,
>
> yep the sort tag is wrong, because $sort is a string rather than a
> nodeset. You'll need to make your sort tag something like:
>
> <xsl:sort select="*[name(.) = $sort]"/>
>
>
> I think that should work.
>
> Adam
>
>
> Ben Pope wrote:
>
>>Hi Adam,
>>
>>Thanks for the reply.
>>
>>I changed the sitemap (That looks pretty close to another variation I
>>tried).
>>
>>My output.xsl Already had
>><xsl:param name="sort"/>
>>
>>But it still didn't work.
>>
>>Then I reordered some stuff to what you suggested (don't know if you meant
>>for me to re-order it)
>>
>><?xml version="1.0" encoding="UTF-8"?>
>><xsl:stylesheet version="1.0"
>>xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
>><xsl:template match="/">
>><xsl:param name="sort"/>
>>
>>Became
>>
>><?xml version="1.0" encoding="UTF-8"?>
>><xsl:stylesheet version="1.0"
>>xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
>><xsl:param name="sort"/>
>><xsl:template match="/">
>>
>>And it now says:
>>"Reports - sort order = date."
>>Or
>>"Reports - sort order = number."
>>
>>So <xsl:value-of select="$sort"/> works nicely.
>>
>>You star!
>>
>>So is it best to have use-request-parameters set to false and pass the
>>single parameter in (in terms of ability to cache the form)? I guess it
>>can
>>use the cached version if that one parameter remains constant, rather then
>>the whole set of parameters?
>>
>>One problem persists:
>>
>>It still doesn't actually sort the table.
>>
>><xsl:for-each select="data/reports/*">
>><xsl:sort select="$sort"/>
>><!-- blah -->
>></xsl:for-each>
>>
>>
>>Is my <xsl:sort /> tag correct? (I presume not).
>>
>>Thank you again, I am at least a lot closer.
>>
>>Ben.
>>
>>
>>
>>
>>-----Original Message-----
>>From: Adam Walsh [mailto:awalsh@contal.net.au] Sent: 19 July 2004 00:48
>>To: users@cocoon.apache.org
>>Subject: Re: Request Parameters in XSLT (Cocoon 2.1.5)
>>
>>Hi Ben,
>>
>>I'd suggest the following:
>>
>>Sitemap.xmap:
>>
>><map:match pattern="output">
>> <map:generate src="input.xml" type="file"/>
>> <map:transform src="output.xsl" type="xslt">
>> <map:parameter name="sort" value="{request-param:sort}" />
>> </map:transform>
>> <map:serialize/>
>></map:match>
>>
>>
>>and make sure in your output.xsl you have <xsl:param name="sort"/>, ie:
>>
>><?xml version="1.0" encoding="UTF-8"?>
>><xsl:stylesheet version="1.0"
>>xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
>>
>><xsl:param name="sort"/>
>>
>><xsl:template match="/">
>> ...
>></xsl:template>
>></xsl:stylesheet>
>>
>>
>>Hope that helps.
>>
>>Adam
>>
>>
>>
>>---------------------------------------------------------------------
>>To unsubscribe, e-mail: users-unsubscribe@cocoon.apache.org
>>For additional commands, e-mail: users-help@cocoon.apache.org
>>
>>
>>
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@cocoon.apache.org
> For additional commands, e-mail: users-help@cocoon.apache.org
>
>
---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@cocoon.apache.org
For additional commands, e-mail: users-help@cocoon.apache.org
RE: Request Parameters in XSLT (Cocoon 2.1.5)
Posted by Ben Pope <no...@hotmail.com>.
Outstanding work, Adam.
Problem now sorted.
Now onto the binding problem...
Thanks to all that helped.
Ben.
-----Original Message-----
From: Adam Walsh [mailto:awalsh@contal.net.au]
Sent: 19 July 2004 03:00
To: users@cocoon.apache.org
Subject: Re: Request Parameters in XSLT (Cocoon 2.1.5)
Hi Ben,
yep the sort tag is wrong, because $sort is a string rather than a nodeset.
You'll need to make your sort tag something like:
<xsl:sort select="*[name(.) = $sort]"/>
---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@cocoon.apache.org
For additional commands, e-mail: users-help@cocoon.apache.org
Re: Request Parameters in XSLT (Cocoon 2.1.5)
Posted by Adam Walsh <aw...@contal.net.au>.
Hi Ben,
yep the sort tag is wrong, because $sort is a string rather than a
nodeset. You'll need to make your sort tag something like:
<xsl:sort select="*[name(.) = $sort]"/>
I think that should work.
Adam
Ben Pope wrote:
>Hi Adam,
>
>Thanks for the reply.
>
>I changed the sitemap (That looks pretty close to another variation I
>tried).
>
>My output.xsl Already had
><xsl:param name="sort"/>
>
>But it still didn't work.
>
>Then I reordered some stuff to what you suggested (don't know if you meant
>for me to re-order it)
>
><?xml version="1.0" encoding="UTF-8"?>
><xsl:stylesheet version="1.0"
>xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
><xsl:template match="/">
><xsl:param name="sort"/>
>
>Became
>
><?xml version="1.0" encoding="UTF-8"?>
><xsl:stylesheet version="1.0"
>xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
><xsl:param name="sort"/>
><xsl:template match="/">
>
>And it now says:
>"Reports - sort order = date."
>Or
>"Reports - sort order = number."
>
>So <xsl:value-of select="$sort"/> works nicely.
>
>You star!
>
>So is it best to have use-request-parameters set to false and pass the
>single parameter in (in terms of ability to cache the form)? I guess it can
>use the cached version if that one parameter remains constant, rather then
>the whole set of parameters?
>
>One problem persists:
>
>It still doesn't actually sort the table.
>
><xsl:for-each select="data/reports/*">
><xsl:sort select="$sort"/>
><!-- blah -->
></xsl:for-each>
>
>
>Is my <xsl:sort /> tag correct? (I presume not).
>
>Thank you again, I am at least a lot closer.
>
>Ben.
>
>
>
>
>
>-----Original Message-----
>From: Adam Walsh [mailto:awalsh@contal.net.au]
>Sent: 19 July 2004 00:48
>To: users@cocoon.apache.org
>Subject: Re: Request Parameters in XSLT (Cocoon 2.1.5)
>
>Hi Ben,
>
>I'd suggest the following:
>
>Sitemap.xmap:
>
><map:match pattern="output">
> <map:generate src="input.xml" type="file"/>
> <map:transform src="output.xsl" type="xslt">
> <map:parameter name="sort" value="{request-param:sort}" />
> </map:transform>
> <map:serialize/>
></map:match>
>
>
>and make sure in your output.xsl you have <xsl:param name="sort"/>, ie:
>
><?xml version="1.0" encoding="UTF-8"?>
><xsl:stylesheet version="1.0"
>xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
>
><xsl:param name="sort"/>
>
><xsl:template match="/">
> ...
></xsl:template>
></xsl:stylesheet>
>
>
>Hope that helps.
>
>Adam
>
>
>
>---------------------------------------------------------------------
>To unsubscribe, e-mail: users-unsubscribe@cocoon.apache.org
>For additional commands, e-mail: users-help@cocoon.apache.org
>
>
>
>
---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@cocoon.apache.org
For additional commands, e-mail: users-help@cocoon.apache.org
Re: Request Parameters in XSLT (Cocoon 2.1.5)
Posted by Ben Pope <be...@hotmail.com>.
Hi,
I think I tried that and it didn't work... Will have another go later,
Cheers!
Ben
----- Original Message -----
From: "Ugo Cei" <ug...@apache.org>
To: <us...@cocoon.apache.org>
Sent: Monday, July 19, 2004 7:22 AM
Subject: Re: Request Parameters in XSLT (Cocoon 2.1.5)
> Il giorno 19/lug/04, alle 02:43, Ben Pope ha scritto:
>
>> <xsl:sort select="$sort"/>
>
> <xsl:sort select="{$sort}"/>
>
> --
> Ugo Cei - http://beblogging.com/
>
---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@cocoon.apache.org
For additional commands, e-mail: users-help@cocoon.apache.org
Re: Request Parameters in XSLT (Cocoon 2.1.5)
Posted by Ugo Cei <ug...@apache.org>.
Il giorno 19/lug/04, alle 02:43, Ben Pope ha scritto:
> <xsl:sort select="$sort"/>
<xsl:sort select="{$sort}"/>
--
Ugo Cei - http://beblogging.com/
RE: Request Parameters in XSLT (Cocoon 2.1.5)
Posted by Ben Pope <no...@hotmail.com>.
Hi Adam,
Thanks for the reply.
I changed the sitemap (That looks pretty close to another variation I
tried).
My output.xsl Already had
<xsl:param name="sort"/>
But it still didn't work.
Then I reordered some stuff to what you suggested (don't know if you meant
for me to re-order it)
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:template match="/">
<xsl:param name="sort"/>
Became
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:param name="sort"/>
<xsl:template match="/">
And it now says:
"Reports - sort order = date."
Or
"Reports - sort order = number."
So <xsl:value-of select="$sort"/> works nicely.
You star!
So is it best to have use-request-parameters set to false and pass the
single parameter in (in terms of ability to cache the form)? I guess it can
use the cached version if that one parameter remains constant, rather then
the whole set of parameters?
One problem persists:
It still doesn't actually sort the table.
<xsl:for-each select="data/reports/*">
<xsl:sort select="$sort"/>
<!-- blah -->
</xsl:for-each>
Is my <xsl:sort /> tag correct? (I presume not).
Thank you again, I am at least a lot closer.
Ben.
-----Original Message-----
From: Adam Walsh [mailto:awalsh@contal.net.au]
Sent: 19 July 2004 00:48
To: users@cocoon.apache.org
Subject: Re: Request Parameters in XSLT (Cocoon 2.1.5)
Hi Ben,
I'd suggest the following:
Sitemap.xmap:
<map:match pattern="output">
<map:generate src="input.xml" type="file"/>
<map:transform src="output.xsl" type="xslt">
<map:parameter name="sort" value="{request-param:sort}" />
</map:transform>
<map:serialize/>
</map:match>
and make sure in your output.xsl you have <xsl:param name="sort"/>, ie:
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:param name="sort"/>
<xsl:template match="/">
...
</xsl:template>
</xsl:stylesheet>
Hope that helps.
Adam
---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@cocoon.apache.org
For additional commands, e-mail: users-help@cocoon.apache.org
Re: Request Parameters in XSLT (Cocoon 2.1.5)
Posted by Adam Walsh <aw...@contal.net.au>.
Hi Ben,
I'd suggest the following:
Sitemap.xmap:
<map:match pattern="output">
<map:generate src="input.xml" type="file"/>
<map:transform src="output.xsl" type="xslt">
<map:parameter name="sort" value="{request-param:sort}" />
</map:transform>
<map:serialize/>
</map:match>
and make sure in your output.xsl you have <xsl:param name="sort"/>, ie:
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:param name="sort"/>
<xsl:template match="/">
...
</xsl:template>
</xsl:stylesheet>
Hope that helps.
Adam
Ben Pope wrote:
>Hi,
>
>I've done my research and read this list for around a week, but it's not
>having any of it. Request parameters don't seem to be passed into the XSLT.
>I stripped down my code to the following noddy example and tried it, without
>success:
>
>Sitemap.xmap:
>-------------
><?xml version="1.0"?>
><map:sitemap xmlns:map="http://apache.org/cocoon/sitemap/1.0">
> <map:components>
> <map:transformers>
> <map:transformer name="xslt"
>src="org.apache.cocoon.transformation.TraxTransformer">
>
><!-- THE FOLLOWING IS LINE WITH COMMENT 1 -->
>
><use-request-parameters>true</use-request-parameters>
> </map:transformer>
> </map:transformers>
> </map:components>
> <map:pipelines>
> <map:pipeline>
> <map:match pattern="output">
> <map:generate src="input.xml" type="file"/>
> <map:transform src="output.xsl" type="xslt">
>
><!-- THE FOLLOWING IS LINE WITH COMMENT 2 -->
><!-- <map:parameter
>name="use-request-parameters" value="true"/> -->
>
><!-- THE FOLLOWING IS LINE WITH COMMENT 3 -->
><!-- <map:parameter name="sort"
>value="date" /> -->
> </map:transform>
> <map:serialize/>
> </map:match>
> </map:pipeline>
> </map:pipelines>
></map:sitemap>
>
>
>input.xml:
>----------
><?xml version="1.0" encoding="UTF-8"?>
><?xml-stylesheet type="text/xsl" href="output.xsl"?> <data>
> <reports>
> <report>
> <number>1</number>
> <date>03/08/01</date>
> </report>
> <report>
> <number>2</number>
> <date>03/07/01</date>
> </report>
> <report>
> <number>3</number>
> <date>22/10/01</date>
> </report>
> </reports>
></data>
>
>
>output.xsl:
>-----------
><?xml version="1.0" encoding="UTF-8"?>
><xsl:stylesheet version="1.0"
>xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
><xsl:template match="/">
>
><!-- THE FOLLOWING IS LINE WITH COMMENT 4 --> <xsl:param name="sort"/>
> <html xmlns="http://www.w3.org/1999/xhtml">
> <head>
> <meta http-equiv="Content-Type" content="text/html;
>charset=iso-8859-1" />
> <title>Report</title>
> </head>
> <body>
>
><!-- THE FOLLOWING IS LINE WITH COMMENT 5 -->
> <p>Reports - sort order = <xsl:value-of select="$sort"/>.</p>
> <p>
> <table border="1">
> <tr>
> <th><a href="?sort=number">Number</a></th>
> <th><a href="?sort=date">Date</a></th>
> </tr>
> <xsl:for-each select="data/reports/*">
>
><!-- THE FOLLOWING IS LINE WITH COMMENT 6 -->
> <xsl:sort select="$sort"/>
> <tr>
> <td><xsl:value-of select="number"/></td>
> <td><xsl:value-of select="date"/></td>
> </tr>
> </xsl:for-each>
> </table>
> </p>
> </body>
> </html>
></xsl:template>
></xsl:stylesheet>
>
>
>
>Comments:
>1. Specify use request parameters globally for transformer.
>
>2. Specify use request parameters on a pipeline basis.
>
>3. Create a parameter and pass it in "manually".
>
>4. Declare parameter in XSLT.
>
>5. Use parameter to write into HTML Body.
>
>6. Use parameter to specify sort order.
>
>
>When I make a request as such:
>http://path/to/sitemap/output?sort=date
>
>
>Using methods 1, 2 or 3 all result in 5 producing "" and 6 not working
>(presumably the same result).
>
>Now, I would suspect that methods 1, 2 OR 3 should all work, but the
>parameter does not appear to be passed in.
>
>
>The section of HTML I get back is:
>
><p>Reports - sort order = .</p>
>
>But I would expect:
>
><p>Reports - sort order = date.</p>
>
>If I put:
><xsl:sort select="date"/> instead of <xsl:sort select="$sort"/>
>
>The report order is 2,1,3 as expected - hence I know it's processing the
>pipeline, not sending input.xml and leaving the rendering all to IE!
>
>
>Anybody got any ideas on what I've missed? This is driving me mad!
>
>
>I've tried this from Jetty (shipped with Cocoon) and Tomcat 5.0.25 under
>Windows 2000 SP4, everything is default, just extracted the source and did a
>"build webapp" and dropped those files in suitable locations.
>
>There wasn't a .war file created (as the documentation suggests) so I just
>dumped the webapp directory as-is into the Tomcat directory. Cocoon appears
>to work, apart from the request parameters. (all the samples seem to work
>in both configs)
>
>Any help is MUCH appreciated. Alternative methods that are more appropriate
>are also welcomed.
>
>Thank you for your time,
>Ben
>
>---------------------------------------------------------------------
>To unsubscribe, e-mail: users-unsubscribe@cocoon.apache.org
>For additional commands, e-mail: users-help@cocoon.apache.org
>
>
>
>
---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@cocoon.apache.org
For additional commands, e-mail: users-help@cocoon.apache.org