You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@cocoon.apache.org by "Joe D. Williams" <jo...@mindspring.com> on 2004/05/04 16:15:54 UTC

Passing an input form value to the sitemap

OK. I have done this before, but am confused as to the simplest way to
accomplish a fairly trivial task: Passing a request attribute to the
sitemap.

Yes, I have read the docs. And I remain somewhat confused.

What I want to do: Select a db record (MySQL db, Cocoon 2.1) based on a
value submitted by a form.

The documentation on the SQLTransformer suggests the following:

  <page xmlns:sql="http://apache.org/cocoon/SQL/2.0">
    <execute-query xmlns="http://apache.org/cocoon/SQL/2.0">
      <query>
       select id,name from employee_table where name =
                '<sql:substitute-value sql:name="username"/>'
      </query>
    </execute-query>
  </page>

However, the example for a "dynamic" pipeline is not much help:

  <map:transform type="sql">
    <map:parameter name="use-connection" value="personnel"/>
    <map:parameter name="show-nr-of-rows" value="true"/>
    <map:parameter name="username" value="Stefano Mazzocchi"/>
  </map:transform>

Now, this example demonstrates that the SQLTransformer is capable of using a
parameter, but what is the simplest way to get the value of "username" to
the sitemap from a form?

Note: This can be accomplished by creating a "dummy" XML file...
<content>
<dynamic-query/>
</content>

...and an XSL stylesheet to prepare the query BEFORE passing it to the SQL
transformer:

<?xml version="1.0"?>

<xsl:stylesheet version="1.0"
  xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
  xmlns:sql="http://apache.org/cocoon/SQL/2.0">

 <xsl:param name="name"/>

 <xsl:template match="/">
  <page>
   <title>Hello <xsl:value-of select="$name"/></title>
   <content>
    <xsl:apply-templates/>
   </content>
  </page>
 </xsl:template>

 <xsl:template match="dynamic-query">
  <execute-query xmlns="http://apache.org/cocoon/SQL/2.0">
    <query>select * from portalusers where name= '<xsl:value-of
select="$name"/>'</query>
  </execute-query>
 </xsl:template>

</xsl:stylesheet>


This is the method Lajos Moczar describes in "Cocoon Developer's Handbook"
to achieve a truly dynamic query, and takes advantage of params in the first
XSL.

However, this was before the tag, "sql:substitute-value" became available in
Cocoon 2.1,
so I would think this is easily implemented in some way... But, how?


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


Re: Passing an input form value to the sitemap

Posted by Walter Lewis <le...@hhpl.on.ca>.
Joe D. Williams wrote:

>OK. I have done this before, but am confused as to the simplest way to
>accomplish a fairly trivial task: Passing a request attribute to the
>sitemap.
>  
>
[snip]

>The documentation on the SQLTransformer suggests the following: [snip]
>
When I first struggled with this example (not so very long ago), someone 
off list pointed out that the key was the Request generator feeding an 
XSL transformation which is passed to the SQL transformer.

Warning:  The following example was cut and edited from live code but 
hasn't actually been fully tested.

Assuming a URL like this
    http://my.cocoon.server.ca/search?SearchTerms=Help

    <map:match pattern="*/search">
            <map:generate type="request"/>
            <map:transform src="Search/Search.xsl" />
            <map:transform type="sql">
                <map:parameter name="use-connection" 
value="ConnectionName" />
                <map:parameter name="show-nr-of-rows" value="true"/>
            </map:transform>
            <map:transform src="/xsl/SearchtoHTML.xsl">
                <map:parameter name="use-request-parameters" value="true"/>
            </map:transform>
            <map:serialize type="html"/>
        </map:match>

The Request generator does not get a lot of play but it will hand off an 
xml representation of the HTML header to the transformer.

In the XSLT transformation that follows might look something like:

?xml version="1.0" ?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" 
version="1.0"  xmlns:h="http://apache.org/cocoon/request/2.0">
<xsl:param name="SearchTerms"><xsl:value-of 
select="//h:parameter[@name='SearchTerms']/h:value"/></xsl:param>
xsl:template match="/">
    <document>
        <sql:execute-query xmlns:sql="http://apache.org/cocoon/SQL/2.0">
            <sql:query name="Main">
               [Your SQL statement with the search parameters 
<xsl:value-of select="$SearchTerms"/> substituted in the appropriate place]
            </sql:query>
        </sql:execute-query>
       <!-- and at this point you can include additional queries or 
XIncludes or other good stuff not in the example -->
    </document>
</xsl:template>
</xsl:stylesheet>

Presumably there are Good Things one could do in the XSL Transformation 
to validate the parameters from the URL and to ensure Unpleasant Things 
didn't come along for the ride.  I would *love* to see some examples of 
the kinds of things people actually do. 

The XML coming out of this should be ready for the SQLTransformer to act 
on it.

I haven't been following along for long enough to know if the 
SQLTransformer is considered Due For Deprecation.  If it isn't, a use 
case with URL submitted parameters would be a useful enhancement to the 
documentation. 

Walter Lewis
virtual Cocoon newbie


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


Re: Passing an input form value to the sitemap

Posted by Upayavira <uv...@upaya.co.uk>.
  <map:transform type="sql">
    <map:parameter name="use-connection" value="personnel"/>
    <map:parameter name="show-nr-of-rows" value="true"/>
    <map:parameter name="username" value="{request-param:username}"/>
  </map:transform>


Upayavira

Joe D. Williams wrote:

>OK. I have done this before, but am confused as to the simplest way to
>accomplish a fairly trivial task: Passing a request attribute to the
>sitemap.
>
>Yes, I have read the docs. And I remain somewhat confused.
>
>What I want to do: Select a db record (MySQL db, Cocoon 2.1) based on a
>value submitted by a form.
>
>The documentation on the SQLTransformer suggests the following:
>
>  <page xmlns:sql="http://apache.org/cocoon/SQL/2.0">
>    <execute-query xmlns="http://apache.org/cocoon/SQL/2.0">
>      <query>
>       select id,name from employee_table where name =
>                '<sql:substitute-value sql:name="username"/>'
>      </query>
>    </execute-query>
>  </page>
>
>However, the example for a "dynamic" pipeline is not much help:
>
>  <map:transform type="sql">
>    <map:parameter name="use-connection" value="personnel"/>
>    <map:parameter name="show-nr-of-rows" value="true"/>
>    <map:parameter name="username" value="Stefano Mazzocchi"/>
>  </map:transform>
>
>Now, this example demonstrates that the SQLTransformer is capable of using a
>parameter, but what is the simplest way to get the value of "username" to
>the sitemap from a form?
>
>Note: This can be accomplished by creating a "dummy" XML file...
><content>
><dynamic-query/>
></content>
>
>...and an XSL stylesheet to prepare the query BEFORE passing it to the SQL
>transformer:
>
><?xml version="1.0"?>
>
><xsl:stylesheet version="1.0"
>  xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
>  xmlns:sql="http://apache.org/cocoon/SQL/2.0">
>
> <xsl:param name="name"/>
>
> <xsl:template match="/">
>  <page>
>   <title>Hello <xsl:value-of select="$name"/></title>
>   <content>
>    <xsl:apply-templates/>
>   </content>
>  </page>
> </xsl:template>
>
> <xsl:template match="dynamic-query">
>  <execute-query xmlns="http://apache.org/cocoon/SQL/2.0">
>    <query>select * from portalusers where name= '<xsl:value-of
>select="$name"/>'</query>
>  </execute-query>
> </xsl:template>
>
></xsl:stylesheet>
>
>
>This is the method Lajos Moczar describes in "Cocoon Developer's Handbook"
>to achieve a truly dynamic query, and takes advantage of params in the first
>XSL.
>
>However, this was before the tag, "sql:substitute-value" became available in
>Cocoon 2.1,
>so I would think this is easily implemented in some way... But, how?
>
>
>---------------------------------------------------------------------
>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