cocoon-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Tobia <tobia.confo...@linux.it>
Subject Re: Cocoon database access strategy
Date Wed, 04 Jul 2007 11:02:02 GMT
Here's a followup for the fellow users who build their queries with XSLT.

I found the question-mark + sql:in-parameter syntax a bit inconvenient,
especially when the query is composed out of building blocks in XSLT:

	<sql:query>
	  SELECT ...
	  FROM ...
	  WHERE ...
	  <xsl:if test="$name and $filter-name">
	    AND name = ?
	  </xsl:if>
	</sql:query>

	<xsl:if test="$name and $filter-name">
	  <sql:in-parameter nr="1" value="{$name}"/>
	</xsl:if>

As you can see, this approach is a maintainability nightmare: think of a
50 line query with dozens of parameters.

So I came up with this solution, which works very well for me.
It's somewhat similar in usage to <esql:parameter>:

	<sql:query>
	  SELECT ...
	  FROM ...
	  WHERE ...
	  <xsl:if test="$name and $filter-name">
	    AND name = <sql:param value="{$name}"/>
	  </xsl:if>
	</sql:query>

This is processed by an additional XSLT transformer before being fed to
the SQL transformer:

	<xsl:template match="sql:query">
	  <xsl:copy>
	    <xsl:apply-templates select="@*|node()"/>
	  </xsl:copy>
	  <xsl:for-each select=".//sql:param">
	    <sql:in-parameter value="{@value}" nr="{position()}"/>
	  </xsl:for-each>
	</xsl:template>

	<xsl:template match="sql:param">
	  <xsl:text>?</xsl:text>
	</xsl:template>

I think it would be useful to include this functionality in the SQL
transformer itself.


HTH
Tobia

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@cocoon.apache.org
For additional commands, e-mail: users-help@cocoon.apache.org


Mime
View raw message