You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@cocoon.apache.org by Donald Ball <ba...@webslingerZ.com> on 2000/01/31 22:20:06 UTC

flaws in XSP implementation PLUS sql taglib features discussion

Okay guys. After working my way through my first taglib, I've identified
what I believe to be a reasonably serious flaw in the XSP implementation.
Fortunately, the fix appears to be quite simple. Well, at least one of
them. Here goes.

XSP uses hard-coded namespace prefixes in cocoon's properties file to
associate elements in XSP pages with taglibs. This is bad. Why? Ricardo
has chosen the 'request' namespace prefix for the
'http://www.apache.org/1999/XSP/Request' namespace. That means that if
your XML files are already using the 'request' namespace prefix for some
other namespace, say, http://www.webslingerZ.com/XML/Request, you cannot
use the XSP Request taglib without rewriting your pages to use a different
prefix for the http://www.webslingerZ.com/XML/Request namespace. The fix
appears to be pretty simple - just change the namespace prefixes in
cocoon's properties file to be full namespace URIs and rework the logic
inside the XSP processor a bit. I'll be happy to make this change if
others concur.

One side benefit of this would be to allow XSP to use the same taglib
twice on the same page, by associating two different prefixes with the
same namespace. Why would you want to do this? I'm not sure, but I think
it's the best way to address the problem I'm having implementing nested
queries in SQL taglib.

Suppose you have two tables, article_table and subject_table.
article_table has id, name, and subject_id. subject_table has id and name.
subject_id refers to subject_table.id, of course. Suppose I want to run a
query and get the name of an article and the name of its subject. I could,
of course, write a 'join' SQL query, and it certainly would be better for
this example, but there are instances more complex than this where it
would be more desirable to split the query up. So what I want to do is
write something like this:

<sql:execute-query>
 <sql:row-element>article</sql:row-element>
 <sql:query>
  select id,name,subject_id from article_table
  <sql:execute-query>
   <sql:query>
    select name as subject_name from subject_table where id =
    <sql:value-of select="../subject_id"/>
   </sql:query>
  </sql:execute-query>
 </sql:query>
</sql:execute-query>

and then get it transformed into something like this:

<article>
 <id>23</id>
 <name>The Illuminatus Trilogy</name>
 <subject_id>5</subject_id>
 <sql:execute-query>
  <sql:query>
   select name as subject_name from subject_table where id = 5
  </sql:query>
 </sql:execute-query>
</article>
<article>
 <id>24</id>
 <name>The Lord of the Rings</name>
 <subject_id>6</subject_id>
 <sql:execute-query>
  <sql:query>
   select name as subject_name from subject_table where id = 6
  </sql:query>
 </sql:execute-query>
</article>

and then finally into something like this:

<article>
 <id>23</id>
 <name>The Illuminatus Trilogy</name>
 <subject_id>5</subject_id>
 <subject_name>Conspiracy Theories</subject_name>
</article>
<article>
 <id>24</id>
 <name>The Lord of the Rings</name>
 <subject_id>6</subject_id>
 <subject_name>Epic Novels</subject_name>
</article>

Now, it's impossible, as far as I can tell, for this transformation to be
accomplished by a single XSP/XSLT pass. Impossible, because XSLT doesn't
let you use any output nodes as input nodes. The inner SQL query needs to
use some output nodes from the outer SQL query to configure its queries,
ergo, multiple processing passes is required.

One approach would be to segment the namespaces:

<sql:execute-query>
 <sql:row-element>article</sql:row-element>
 <sql:query>
  select id,name,subject_id from article_table
  <sql2:execute-query>
   <sql2:query>
    select name as subject_name from subject_table where id =
    <sql:value-of select="../subject_id"/>
   </sql2:query>
  </sql2:execute-query>
 </sql:query>
</sql:execute-query>

-->

<article>
 <id>23</id>
 <name>The Illuminatus Trilogy</name>
 <subject_id>5</subject_id>
 <sql2:execute-query>
  <sql2:query>
   select name as subject_name from subject_table where id = 5
  </sql2:query>
 </sql2:execute-query>
</article>
<article>
 <id>24</id>
 <name>The Lord of the Rings</name>
 <subject_id>6</subject_id>
 <sql2:execute-query>
  <sql2:query>
   select name as subject_name from subject_table where id = 6
  </sql2:query>
 </sql2:execute-query>
</article>

and so forth and so on. Of course, I'm still going to have to write some
interesting code for the <sql:value-of/> tag, but that shouldn't be that
difficult. But to take this approach, I need the ability to associate
arbitrary prefixes with the same namespace, hence my desire to patch XSP
as noted above.

Now, if someone has a better suggestion for how to handle nested queries,
I'm _all_ ears. Indeed, if someone has suggestions for alternate syntaxes
for SQL taglib, I'm also all ears. I've been playing around with a verbose
syntax like this:

<sql:execute-query>
 <sql:operation>select</sql:operation>
 <sql:table>article_table</sql:table>
 <sql:column>id</sql:column>
 <sql:column>name</sql:column>
 <sql:where>id = <request:get-parameter name="id"/></sql:where>
</sql:execute-query>

It should be fairly easy to come up with a generic DTD for writing SQL
queries in XML, but I personally can't see wy it would be desirable to
write them this way. Too verbose. But some people have suggested that
they'd like it. If that's you, please send in suggestions and
justifications.

- donald


Re: flaws in XSP implementation PLUS sql taglib features discussion

Posted by Donald Ball <ba...@webslingerZ.com>.
On Tue, 1 Feb 2000, Luis Arias wrote:

> ----- Original Message -----
> From: Donald Ball <ba...@webslingerZ.com>
> To: Cocoon <co...@xml.apache.org>
> Sent: Monday, January 31, 2000 10:20 PM
> Subject: flaws in XSP implementation PLUS sql taglib features discussion
> >
> > <sql:execute-query>
> >  <sql:row-element>article</sql:row-element>
> >  <sql:query>
> >   select id,name,subject_id from article_table
> >   <sql:execute-query>
> >    <sql:query>
> >     select name as subject_name from subject_table where id =
> >     <sql:value-of select="../subject_id"/>
> >    </sql:query>
> >   </sql:execute-query>
> >  </sql:query>
> > </sql:execute-query>
> >
> 
> Hi,
> 
> I was just wondering why you were thinking of using an "all-xslt" approach
> to this ...  Wouldn't it be better for this type of problem to have another
> separate mechanism in your taglib that allows you to keep the current row in
> the outer result set around for this type of purpose ?  That way if you
> could refer to previous result set columns by automagically having them
> bound to some name.
> 
> For instance, taking up on your example :
> 
> <sql:execute-query>
> <sql:row-element>article</sql:row-element>
> <sql:query id="first">
>  select id,name,subject_id from article_table
>  <sql:execute-query>
>   <sql:query id="second">
>    select name as subject_name from subject_table where id =
>    <sql:result column="first.id"/>
>   </sql:query>
>  </sql:execute-query>
> </sql:query>
> </sql:execute-query>
> 
> (Here "first.id" refers to the id column in the result set "of query
> "first", of course, and not the "id" attribute in the xml tag.)
> 
> Am I missing something big here ?

I'm not exactly sure - I'm not relying on XSLT in any way here except in
my choice of element names. The only real difference between your syntax
and my own is my

<sql:value-of select="../id"/>

is replaced by

<sql:result column="first.id"/>

(and of course the id attributes in the query elements)

sql:value-of isn't an element in the XSLT namespace, but an element in the
SQL namespace. I deliberately chose the element's name to be similar to
the XSLT element, but I was under the impression that I'd have to write my
own code to do the value-of lookup routine as I don't see how I could rely
on XSLT (or more generally speaking, an XPath, uh, resolver) to do it for
me. Mind you, if I could, I'd be inclined to do so, but I really can't
visualize a clean way to do so.

Assuming that's correct, I think I like your syntax better. Thanks. If I
can tackle the namespace prefix problem, we'll see how well it works in
practice.

- donald


Re: flaws in XSP implementation PLUS sql taglib features discussion

Posted by Luis Arias <lu...@elysia.com>.
----- Original Message -----
From: Donald Ball <ba...@webslingerZ.com>
To: Cocoon <co...@xml.apache.org>
Sent: Monday, January 31, 2000 10:20 PM
Subject: flaws in XSP implementation PLUS sql taglib features discussion
>
> <sql:execute-query>
>  <sql:row-element>article</sql:row-element>
>  <sql:query>
>   select id,name,subject_id from article_table
>   <sql:execute-query>
>    <sql:query>
>     select name as subject_name from subject_table where id =
>     <sql:value-of select="../subject_id"/>
>    </sql:query>
>   </sql:execute-query>
>  </sql:query>
> </sql:execute-query>
>

Hi,

I was just wondering why you were thinking of using an "all-xslt" approach
to this ...  Wouldn't it be better for this type of problem to have another
separate mechanism in your taglib that allows you to keep the current row in
the outer result set around for this type of purpose ?  That way if you
could refer to previous result set columns by automagically having them
bound to some name.

For instance, taking up on your example :

<sql:execute-query>
<sql:row-element>article</sql:row-element>
<sql:query id="first">
 select id,name,subject_id from article_table
 <sql:execute-query>
  <sql:query id="second">
   select name as subject_name from subject_table where id =
   <sql:result column="first.id"/>
  </sql:query>
 </sql:execute-query>
</sql:query>
</sql:execute-query>

(Here "first.id" refers to the id column in the result set "of query
"first", of course, and not the "id" attribute in the xml tag.)

Am I missing something big here ?

Luis.