cocoon-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Steve Philp <>
Subject SQL, XSL and xml:sort'ing resultsets with request parameters
Date Tue, 01 Jan 2002 08:29:34 GMT
I've spent most of the day today trudging through various search engines, FAQs, mailing list
archives and the Cocoon-2 site, but I still seem to be missing something critical in getting
something that seems simple working.

The problem revolves around how to efficiently use request parameters to choose a SQL resultset
column to sort by in my stylesheet.

I've got the following in sitemap.xmap:

	<map:match pattern="sql/*">
		<map:generate src="docs/samples/sql/{1}.xml"/>
		<map:transform type="sql">
			<map:parameter name="use-connection" value="testdb"/>
		<map:transform src="stylesheets/employees.xsl">
			<map:parameter name="use-request-parameters" value="true"/>

I should mention that the XSLT transformer is also modified to turn on request parameters.

The SQL xml document looks like:

	<?xml version="1.0"?>

	<page xmlns:sql="">
			<execute-query xmlns=""> 
					select emid, emfname, emlname from employee

Both are nearly stock from the Cocoon distribution and seem to work just fine (that is, the
output is what I would expect to see).  

My problem comes in attempting to take that resultset and process it in the stylesheet.  Ideally,
I'd like to create a single stylesheet that would use the HTTP request parameter order_by
as the sort-by column.  My XSL looks like this (including just the relevant template):

	<xsl:template match="sql:rowset">
		<xsl:param name="order_by"/>
		<table border="0" width="100%">
			<tr bgcolor="aaccee" align="left">
				<th><a href="?order_by=sql:emid">Employee ID</a></th>
				<th><a href="?order_by=sql:emfname">First Name</a></th>
				<th><a href="?order_by=sql:emlname">Last Name</a></th>
			<xsl:for-each select="sql:row">
				<xsl:sort select="$order_by"/>
					<xsl:attribute name="bgcolor">
							<xsl:when test="position() mod 2 = 0">

It appears to me that $order_by DOES hold the value that I'm interested in, since I can include:

	<td><xsl:value-of select="$order_by"/></td>

just after the <xsl:apply-templates/> and get the expected value in that column.

The mailing list archives mentioned something similar to "*[name()=$order_by]" as being a
working answer, but it doesn't seem to have any affect upon the output in this situation.

With my limited knowledge of Cocoon and XSL, I'm not sure where to go from here.  I have tested
using URI path extensions (e.g. /sql/sql-page/ByID) and choosing the stylesheet in sitemap.xmap
based on that, and that seems to work, but it would work out to be a maintenance nightmare
holding onto stylesheets for each possible sortable column in each page.

If I want to use request parameters, are XSPs my only option?

What (obvious, I'm quite sure) options do I have at this point?

Thank you for any help or pointers anyone can offer,

Steve Philp
Advance Packaging Corporation

Please check that your question has not already been answered in the
FAQ before posting. <>

To unsubscribe, e-mail: <>
For additional commands, e-mail: <>

View raw message