Alan Hodgkinson wrote: >>Christian Haul wrote: > > <snip/> > >>Two options: >> >>a) create the query dynamically. esql expects just a string. Thus you >>need to >> <esql:query> >> <xsp:expr>"select name from clients where clientid=" + >> <xsp-request:get-parameter name="clientId"/> >> <xsp:expr> >> </esql:query> > > > This does not work as is, because the conversion to JSP/Java > results in a some local definitions, which cannot be simply added > to an <xsp:expr>. I needed to use the XMST variable as described > above.
I'm afraid that you lost me here. Your solution adds it to an expression as well. So, where's the difference? (BTW: you should really use copy-of) Your solution: > <xsp:logic> > String idSelect = "select <xsl:value-of select="@value-field"/> > from <xsl:value-of select="@table"/> where <xsl:value-of > select="@id-field"/> = " + <xsl:value-of select="$id-value"/> ; > </xsp:logic> > > <esql:connection> > <esql:pool><xsl:value-of select="@connection"/></esql:pool> > <esql:execute-query> > <esql:query> > <xsp:expr>idSelect</xsp:expr> > > >>b) use a prepared statement >> <esql:query> >> select name from clients where clientid= >> <esql:parameter><xsp-request:get-parameter >>name="clientId"/></esql:parameter> >> </esql:query> >> >>Preferable is b). > > > This would work, but requires that my parameter comes from the > HTML form parameters. Remember how I call my logicsheet: Oh no! I've just taken your example and used it. So replace it with <esql:query> select name from clients where clientid= <esql:parameter> String.valueOf(<xsl:copy-of select="."/>) </esql:parameter> </esql:query> > E.g. I should be free to replace the <xsp-request:get-parameter> > with anything and the logic sheet shouldn't have to worry about > what it gets. With XSLT this isn't normally a problem. That fact > that the parameter, which could be XML nodes instead of text, is > placed in to a Java string that is evaluated by the DB server is > what causes the problem. In Lisp or Bourne shell you'de use the > an 'eval' function to guarantee that your parameters are > completely resolved. That's not available here. Indeed, you need to worry about the resulting type. But there's really no way around. The XSL is used as macro language and does not know anything about the underlying language. XSP is not bound to java, python and javascript are available as well. Java is just more common and therefore more logicsheets exist. In the example above you will always get the string representation. But whatever gets placed in the tag as argument must be replaced with an expression. If it doesn't, you're lost. But there is no way that I am aware of to cater for that case. Thus it is good practice to write logicsheets in a way that delegates the real processing to java classes i.e. beans and have a 2 phase processing: 1) prepare 2) evaluate. Even if you take the esql logicsheet, you have large parts for the prepare stage although not only java classes but a lot loops and stuff, and you can use any of the esql:get-xxx tags in any expression (evaluate stage). If you are going to write a dbutil logicsheet that looks up a value based on the id you will need to follow this pattern: <dbutil:lookup> <!-- note that arbitrary code may be present anywhere here --> <!-- setup --> <!-- everything is hardcoded ? no need to pass connection name? --> <!-- now evaluate --> <dbutil:get-object oid="something"/> </dbutil:lookup> Oh, yes, you will need to create a way to have a dynamic id: <dbutil:lookup> <!-- note that arbitrary code may be present anywhere here --> <!-- setup --> <!-- everything is hardcoded ? no need to pass connection name? --> <!-- now evaluate --> <dbutil:get-object> <dbutil:param name="oid"><xsp:expr>something</xsp:expr> </dbutil:get-object> </dbutil:lookup> For this you may want to look at the logicsheet-utils.xsl that provides templates for this. BTW the above rationale is explained in the "Logicsheet Concepts" chapter http://xml.apache.org/cocoon/userdocs/xsp/logicsheet-concepts.html Oh, another thing: SiLLy does not exist. Chris. Haul -- C h r i s t i a n H a u l [EMAIL PROTECTED] fingerprint: 99B0 1D9D 7919 644A 4837 7D73 FEF9 6856 335A 9E08 --------------------------------------------------------------------- Please check that your question has not already been answered in the FAQ before posting. <http://xml.apache.org/cocoon/faq/index.html> To unsubscribe, e-mail: <[EMAIL PROTECTED]> For additional commands, e-mail: <[EMAIL PROTECTED]>