To acquaint myself with the sitemap and the ESQL logicsheet, I wrote a
small application that takes a database named IXIDB, lists the tables
and shows the table contents.  The goal was not to have to adapt the
application if database tables were to change.  One of the problems I
found difficult to deal with was extracting the table descriptions so
I could turn the fields into headers (<th>) in the output.  I solved
this with a dynamically generated XSL sheet.  Now I'm wondering:

Is this 'The Way' or are there more elegant/ more flexible/ easier/
approaches to solve this problem?  Would nested queries help?  I
tried, but found them difficult to debug.

Is this likely to work with future versions of Cocoon (I did it in
2.0.4)?  Or is ESQL going to be superceded by the SQL Transformer?

I would appreciate any hints, comments, 'RTFM' pointers or anything
else that will help me on my learning curve...

Thanks

Rolf Heckemann


============= sitemap.xmap ============= 
<?xml version="1.0"?>
<map:sitemap xmlns:map="http://apache.org/cocoon/sitemap/1.0";>
  <map:components> 
    <map:generators   default="file"/>
    <map:transformers default="xslt"/>
    <map:readers      default="resource"/>
    <map:serializers  default="html"/>
    <map:matchers default="wildcard"/>
  </map:components>

  <map:pipelines>
    <map:pipeline>
      <map:match pattern="dbreq">
        <map:generate src="xsp/dbreq.xsp" type="serverpages"/>
        <map:transform src="stylesheets/query2html.xsl"/> 
        <map:serialize type="html"/>
      </map:match>
    </map:pipeline>

    <map:pipeline>
      <map:match pattern="showtable">
        <map:generate src="xsp/showtable.xsp" type="serverpages"/>
        <map:transform src="cocoon:/descrtable"/>
        <map:serialize type="html"/>
      </map:match>
    </map:pipeline>

    <map:pipeline>
      <map:match pattern="descrtable">
        <map:generate src="xsp/descrtable.xsp" type="serverpages"/>
        <map:transform src="stylesheets/query2html.xsl"/>
        <map:serialize type="html"/>
      </map:match>
    </map:pipeline>

  </map:pipelines>
</map:sitemap>


=============  dbreq.xsp ============= 
<?xml version="1.0" encoding="ISO-8859-1"?>
<xsp:page
  language="java"
  xmlns:xsp="http://apache.org/xsp";
  xmlns:xsp-request="http://apache.org/xsp/request/2.0";
  xmlns:xsp-response="http://apache.org/xsp/response/2.0";
  xmlns:log="http://apache.org/xsp/log/2.0";
  xmlns:esql="http://apache.org/cocoon/SQL/v2";>
  
  
  <page>
    <esql:connection>
      <esql:pool>workbench</esql:pool>

      <esql:execute-query>
        <esql:query>
          show tables
        </esql:query>
        <esql:results>
          Tables in IXIDB: 
          <br/>
          <esql:row-results>
            <a>
              <xsp:attribute
              name="href">showtable?table=<esql:get-string
              column="Tables_in_IXIDB"/></xsp:attribute>
              <esql:get-string column="Tables_in_IXIDB"/>
            </a>
            <br/>
          </esql:row-results>
        </esql:results>     
        <esql:no-results>No results</esql:no-results>
        <esql:error-results>Error in query</esql:error-results>
      </esql:execute-query>

    </esql:connection>
  </page>
  </xsp:page>


============= query2html.xsl ============= 
(This is essentially the same as the example 
 xxx2html.xsl's from the Cocoon dist.)


=============  showtable.xsp ============= 
<?xml version="1.0" encoding="ISO-8859-1"?>
<xsp:page
  language="java"
  xmlns:xsp="http://apache.org/xsp";
  xmlns:xsp-request="http://apache.org/xsp/request/2.0";
  xmlns:xsp-response="http://apache.org/xsp/response/2.0";
  xmlns:log="http://apache.org/xsp/log/2.0";
  xmlns:esql="http://apache.org/cocoon/SQL/v2";>

  <page>
    <esql:connection>
      <esql:pool>workbench</esql:pool>
      
      <esql:execute-query>
        <esql:query>
          select * from <xsp-request:get-parameter name="table"/>;
        </esql:query>
        <esql:results>
          <esql:row-results>
            <row>
              <esql:get-columns />
            </row>
          </esql:row-results>
        </esql:results>     
        <esql:no-results>No results</esql:no-results>
        <esql:error-results>Error in query</esql:error-results>
      </esql:execute-query>
    </esql:connection>
  </page>
</xsp:page>

=============  descrtable.xsp ============= 
<?xml version="1.0" encoding="ISO-8859-1"?>
<xsp:page
  language="java"
  xmlns:xsp="http://apache.org/xsp";
  xmlns:xsp-request="http://apache.org/xsp/request/2.0";
  xmlns:xsp-response="http://apache.org/xsp/response/2.0";
  xmlns:log="http://apache.org/xsp/log/2.0";
  xmlns:esql="http://apache.org/cocoon/SQL/v2";
  xmlns:xsl="http://www.w3.org/1999/XSL/Transform";
  >
  
  <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform";>
    
    <esql:connection>
      <esql:pool>workbench</esql:pool>
      
      <esql:execute-query>
        <esql:query>
          describe <xsp-request:get-parameter name="table"/>
        </esql:query>
        
        <esql:results>
          <xsl:template match="page">
            <html>
              <head>
                <title>Showing table</title>
              </head>
              <body>
                <table border="1">
                  <tr>
                    <esql:row-results>
                      <th>
                        <esql:get-string column="Field" />
                      </th>
                    </esql:row-results>
                  </tr>
                  <xsl:apply-templates/>
                </table>
              </body>
            </html>
          </xsl:template>
        </esql:results>
        <esql:no-results>No describe results</esql:no-results>
        <esql:error-results>Error describe query</esql:error-results>
      </esql:execute-query>
      
      <xsl:template match="row">
        <tr>
          <xsl:apply-templates/>
        </tr>
      </xsl:template>
      
      <esql:execute-query>
        <esql:query>
          describe <xsp-request:get-parameter name="table"/>
        </esql:query>
        
        <esql:results>
          <esql:row-results>
            <xsl:template>
              <xsp:attribute name="match"><esql:get-string column="Field" 
/></xsp:attribute>
              <td>
                <xsl:value-of select="."/>
              </td>
            </xsl:template>
          </esql:row-results>
          
        </esql:results>     
        
        <esql:no-results>No describe results</esql:no-results>
        <esql:error-results>Error describe query</esql:error-results>
      </esql:execute-query>
      
    </esql:connection>
  </xsl:stylesheet>
 </xsp:page>


---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to