cocoon-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Adam Walsh <awa...@contal.net.au>
Subject Re: Request Parameters in XSLT (Cocoon 2.1.5)
Date Sun, 18 Jul 2004 23:47:58 GMT
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


Mime
View raw message