cocoon-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Donald Ball <ba...@webslingerZ.com>
Subject flaws in XSP implementation PLUS sql taglib features discussion
Date Mon, 31 Jan 2000 21:20:06 GMT
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


Mime
View raw message