You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@cocoon.apache.org by Benjamin Dixon <be...@arches.uga.edu> on 2000/09/23 06:37:07 UTC

Multiple Transformations

Hello again,

Probably another simple question but I couldn't find a solution in the
archives (which would be much nicer if searchable, BTW) so anyway, here
goes. I'm considering using Cocoon for a large-scale project that involves
query a database and possibly returning large sets of data. Currently I
have an XSP page that I have written to take care of getting the data out
of the database. The XSP page uses esql (which is REALLY nice) and then I
want to transform that data using XSL. When I was using just the sql
taglib, I had good performance and XSL worked fine. Now that I've switched
to esql, my pages load approximately 10 times slower and the stylesheet no
longer works. It says that "no data may occur before output" or some such.
So I have a number of questions:

1.) Is esql generally a lot slower than the regular sql? I understand
maybe there's an extra processing step, but 10 times slower?

2.) My goal is to separate content and logic as completely as possible so
that I can write the logic and provide a sort of taglib for others to
write up the formats. What other options would I have besides
XSP->esql->XSL? Would it be beneficial for me to use more logic and simply
skip the esql step? 

Sorry for the questions but I'm interested in the type of design patterns
people are using for projects.

Ben  


Re: Multiple Transformations

Posted by Donald Ball <ba...@webslingerZ.com>.
On Sat, 23 Sep 2000, Benjamin Dixon wrote:

> Wow! The cahcing is a major improvement (at least for 60 seconds :>) but
> I'm still mystified about how I should implement this stuff. I think our
> ideas are along the same lines, I want to provide a certain set of tags to
> other developers so that they never have to worry about logicsheets etc,
> all the need to know about is XSL and the tags at their disposal. I don't
> know how to accomplish that AND use esql. I took the XSL step out of my

that's easy. your logicsheet will perhaps have a template like so:

<xsl:template match="goheels:articles">
 <esql:execute-query>
  ...
  <esql:query>select * from article_table 
   where subject = '<xsl:value-of select="subject"/>'</esql:query>
  <esql:results>
   <article>
    <title><esql:get-string column="title"/></title>
    <body><esql:get-xml column="body"/></body>
   </article>
  </esql:results>
 </esql:execute-query>
</xsl:template>

nothing could be simpler.

> pages and I noticed that the XSP/esql combo always returns an HTML
> doctype. I suspect that is the source of all my problems. But if I want to
> dynamically select things out of a database, process some of them (format
> dates, phone numbers, etc) BEFORE they arerive at the stylesheet, I have
> no clue how to go about it. I wish there were examples of more complex
> setups lying around.

it's returning an HTML doctype since that what cocoon defaults to. that
is not the source of your problems because the document is still in XML
form when it's passed from processor to processor. you can probably do
your postprocessing of your database results in your logicsheet:

<xsl:template match="mytag:foo">
 <esql:execute-query>
  ...
  <esql:results>
   <my-date><esql:get-date format="MMM d, yyyy" column="my_date"/></my-date>
   <my-phone>
    <xsp:expr><esql:get-string column="phone"/>.substring(0,3)</xsp:expr>-
    <xsp:expr><esql:get-string column="phone"/>.substring(4)</xsp:expr>
   </my-phone>
  </esql:results>
 </esql:execute-query>
</xsl:template>

- donald


Re: Multiple Transformations

Posted by Benjamin Dixon <be...@arches.uga.edu>.
Wow! The cahcing is a major improvement (at least for 60 seconds :>) but
I'm still mystified about how I should implement this stuff. I think our
ideas are along the same lines, I want to provide a certain set of tags to
other developers so that they never have to worry about logicsheets etc,
all the need to know about is XSL and the tags at their disposal. I don't
know how to accomplish that AND use esql. I took the XSL step out of my
pages and I noticed that the XSP/esql combo always returns an HTML
doctype. I suspect that is the source of all my problems. But if I want to
dynamically select things out of a database, process some of them (format
dates, phone numbers, etc) BEFORE they arerive at the stylesheet, I have
no clue how to go about it. I wish there were examples of more complex
setups lying around.

Ben

On Sat, 23 Sep 2000, Donald Ball wrote:

> > 1.) Is esql generally a lot slower than the regular sql? I understand
> > maybe there's an extra processing step, but 10 times slower?
> 
> no, it should run at about the same speed if not somewhat faster. it would
> seem that your stylesheet is messing up somewhere. also, if you're looking
> to maximize performance, you should really implement the
> hasChanged(Object) method in your xsp pages. for my database pages, i have
> a timeout method that caches stuff for 60 seconds. almost two orders of
> magnitude improvement in performance - cos you not only lose the xsp
> execution step, you also lose anything (e.g. xslt transform) that occurs
> thereafter. do a search in the archives for 'cache madness' if you want a
> complete example of how i did this for one site.
> 
> to debug your stylesheet problem, i'd lose the xslt process step and see
> how the sql results differ from what your stylesheet expects.
> 
> > 2.) My goal is to separate content and logic as completely as possible so
> > that I can write the logic and provide a sort of taglib for others to
> > write up the formats. What other options would I have besides
> > XSP->esql->XSL? Would it be beneficial for me to use more logic and simply
> > skip the esql step? 
> 
> i generally provide my authors with a set of elements in a site-specific
> namespace, e.g.
> 
> <goheels:articles subject="Basketball" number="10"/>
> 
> which gets transformed by the goheels logicsheet to a bunch of elements in
> the esql namespace (or whatever), and so forth and so on. i really like
> this approach because the elements that authors work with mean something
> at a very high level. here, for instance i'm saying i want the ten latest
> articles on basketball. the source and retrieval mechanism are specified
> by my (centralized) goheels logicsheet. the one caveat to this approach is
> that if you're using namespace-prefix invoked logicsheets, _all_ of them
> must be declared by the initial page - which is a big liability since the
> initial page shouldn't _have_ to know anything about how the data is being
> generated. this _is_ a known liability in the cocoon1 xsp implementation
> and, i'm fairly certain, has been removed in cocoon1.
> 
> cocoon1's xsp implementation is kinda hokey in another respect which i'm
> sure you're realized - tying logicsheets to namespace _prefixes_, not
> namespace _uris_. i believe this has been rectified in cocoon2 as well.
> 
> - donald
> 
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: cocoon-users-unsubscribe@xml.apache.org
> For additional commands, e-mail: cocoon-users-help@xml.apache.org
> 

Today's Random Quote--------------------------------------

 Dig a well before you are thirsty. 
   Chinese Proverb
-----------------------------------------------------------


Re: Multiple Transformations

Posted by Donald Ball <ba...@webslingerZ.com>.
On Sat, 23 Sep 2000, Benjamin Dixon wrote:

> Probably another simple question but I couldn't find a solution in the
> archives (which would be much nicer if searchable, BTW) so anyway, here
> goes. I'm considering using Cocoon for a large-scale project that involves
> query a database and possibly returning large sets of data. Currently I
> have an XSP page that I have written to take care of getting the data out
> of the database. The XSP page uses esql (which is REALLY nice) and then I
> want to transform that data using XSL. When I was using just the sql
> taglib, I had good performance and XSL worked fine. Now that I've switched
> to esql, my pages load approximately 10 times slower and the stylesheet no
> longer works. It says that "no data may occur before output" or some such.
> So I have a number of questions:
> 
> 1.) Is esql generally a lot slower than the regular sql? I understand
> maybe there's an extra processing step, but 10 times slower?

no, it should run at about the same speed if not somewhat faster. it would
seem that your stylesheet is messing up somewhere. also, if you're looking
to maximize performance, you should really implement the
hasChanged(Object) method in your xsp pages. for my database pages, i have
a timeout method that caches stuff for 60 seconds. almost two orders of
magnitude improvement in performance - cos you not only lose the xsp
execution step, you also lose anything (e.g. xslt transform) that occurs
thereafter. do a search in the archives for 'cache madness' if you want a
complete example of how i did this for one site.

to debug your stylesheet problem, i'd lose the xslt process step and see
how the sql results differ from what your stylesheet expects.

> 2.) My goal is to separate content and logic as completely as possible so
> that I can write the logic and provide a sort of taglib for others to
> write up the formats. What other options would I have besides
> XSP->esql->XSL? Would it be beneficial for me to use more logic and simply
> skip the esql step? 

i generally provide my authors with a set of elements in a site-specific
namespace, e.g.

<goheels:articles subject="Basketball" number="10"/>

which gets transformed by the goheels logicsheet to a bunch of elements in
the esql namespace (or whatever), and so forth and so on. i really like
this approach because the elements that authors work with mean something
at a very high level. here, for instance i'm saying i want the ten latest
articles on basketball. the source and retrieval mechanism are specified
by my (centralized) goheels logicsheet. the one caveat to this approach is
that if you're using namespace-prefix invoked logicsheets, _all_ of them
must be declared by the initial page - which is a big liability since the
initial page shouldn't _have_ to know anything about how the data is being
generated. this _is_ a known liability in the cocoon1 xsp implementation
and, i'm fairly certain, has been removed in cocoon1.

cocoon1's xsp implementation is kinda hokey in another respect which i'm
sure you're realized - tying logicsheets to namespace _prefixes_, not
namespace _uris_. i believe this has been rectified in cocoon2 as well.

- donald


Re: Multiple Transformations

Posted by Donald Ball <ba...@webslingerZ.com>.
On Sat, 23 Sep 2000, Benjamin Dixon wrote:

> After I run this, I get the following:
> 
> <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0//EN"
> "http://www.w3.org/TR/REC-html40/strict.dtd">
> <page title="Simple Test">
> ...
> </page>
> 
> I think the DOCTYPE is messing everything up but I don't understand how
> it gets there in the first place and I can't figure out how to remove it.
> I've looked into <xsp:pi> but was not able to get it to do anything other
> than output itself to the code or do nothing at all. I'd appreciate any
> help you guys can provide.

read the docs, dude. add <?cocoon-format type="text/xml"?> - but again,
that's _not_ there when the document is being passed from processor to
processor.

- donald


Re: Multiple Transformations

Posted by Benjamin Dixon <be...@arches.uga.edu>.
Reading over my last post, I think I was a bit ambiguous as to what I
wanted to do. Basically, I want to write an XSP page that uses esql and I
want the result to be run through XSLT so it comes out as HTML. Something
like so:

XSP (w/ esql query) -> XML data to be transformed -> HTML

Here is some sample code I whipped up, a much simpler version of the
original but exhibiting the same problem (minus the XSLT):

-----------------------------------------
<?xml version="1.0"?>

<?cocoon-process type="xsp"?>
<?xml-logicsheet
href="resource://org/apache/cocoon/processor/xsp/library/sql/esql.xsl"?>

<xsp:page
  language="java"
  xmlns:xsp="http://www.apache.org/1999/XSP/Core"
  xmlns:esql="http://apache.org/cocoon/SQL/v2"
>

<page title="Simple Test">
   <esql:execute-query>
      <esql:driver>net.avenir.jdbc2.Driver</esql:driver>
      <esql:dburl>jdbc:AvenirDriver://10.1.1.14:1433/prod</esql:dburl>
      <esql:username>xxxxxx</esql:username>
      <esql:password>xxxxxx</esql:password>
      <esql:doc-element>event</esql:doc-element>
      <esql:row-element>event_row</esql:row-element>
      <esql:tag-case>lower</esql:tag-case>
      <esql:null-indicator>yes</esql:null-indicator>
      <esql:id-attribute>sref</esql:id-attribute>
      <esql:id-attribute-column>sref</esql:id-attribute-column>
      <esql:count-attribute>event_count</esql:count-attribute>
      <esql:query>
          select sref from event_tab where city like 'athens'
      </esql:query>
      <esql:results>
         <sref><esql:get-string column="sref"/></sref>
      </esql:results>
      <esql:no-results>
         <error>No results to query</error>
      </esql:no-results>
   </esql:execute-query>
</page>

</xsp:page>
------------------------------------------------

After I run this, I get the following:

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0//EN"
"http://www.w3.org/TR/REC-html40/strict.dtd">
<page title="Simple Test">
...
</page>

I think the DOCTYPE is messing everything up but I don't understand how
it gets there in the first place and I can't figure out how to remove it.
I've looked into <xsp:pi> but was not able to get it to do anything other
than output itself to the code or do nothing at all. I'd appreciate any
help you guys can provide.

Ben