xml-general mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Dave Jarvis <d...@joot.com>
Subject Re: Business-Oriented XML
Date Sat, 17 Nov 2001 04:58:06 GMT
Hello, again.

Neeme Praks wrote:
> Have you ever had a look at Apache Cocoon project? That achieves all the

Yes.

> benefits you outlined in your paper plus more.

Here are a few items BOX addresses that Cocoon does not (as far as I can
discern; please correct my errors):

	o doesn't provide an inherent state-based architecture (it's an aside,
not focus)
	o doesn't automatically apply a different view of logic based on the
domain
	o extremely complex; it mixes multiple languages and odd syntax (e.g.,
&connectDatabase)
	o makes it easy to couple presentation and logic (see below)
	o lacks an integrated expression parser
	o doesn't expose a consistent syntax for doing tasks such as:
		- file I/O
		- sending XML to remote servers
		- calling native code (Java, C, Perl, etc.)
		- SQL statements
	o cookies, FORM parameters, and URL encoded variables are not treated
uniformly
	o doesn't use plain XML (i.e., embeds other language source directly)

If there's interest, I would be more than happy to illustrate a full
cycle of data acquisition (via HTML FORM) to SQL deposit, retrieval, and
final HTML page.  For those who enjoy gory details, I've made a brief
comparison of Cocoon and BOX for two very simple examples.  The first is
a little counter program, the second shows how to do SQL in both
tongues.

Sincerely,
Dave Jarvis

-=( First Example )=-

 ]] Cocoon's Logic (18 lines of code; tied to Java) [[
 <?xml version="1.0"?>
 <?cocoon-process type="xsp"?>
 <?cocoon-process type="xslt"?>
 <?xml-stylesheet href="page-html.xsl" type="text/xsl"?>

 <xsp:page language="java"
xmlns:xsp="http://www.apache.org/1999/XSP/Core">
 <xsp:logic>
 static private int counter = 0;

 private synchronized int count() {
 return counter++;
 }
 </xsp:logic>

 <page>
 <p>I've been requested <xsp:expr>count()</xsp:expr> times.</p>
 </page>
 </xsp:page>

 ]] Cocoon's XSP (6 lines of generated code) [[
 <?xml version="1.0"?>
 <?cocoon-process type="xslt"?>
 <?xml-stylesheet href="page-html.xsl" type="text/xsl"?>
 <page>
 <p>I've been requested 0 times.</p>
 </page>

 ]] Cocoon's XSL (10 lines of code) [[
 <?xml version="1.0"?>
 <xsl:stylesheet>
 <xsl:output method="html" encoding="US-ASCII"/>

 <xsl:template match="page">
   <xsl:apply-templates/>
 </xsl:template>

 <xsl:template match="p">
   <xsl:apply-templates/>
 </xsl:template>
 </xsl:stylesheet>

BOX code, in my opinion, is much simpler and straightforward, as there
is no intermediary XSP page:

 ]] BOX's Logic (7 lines of code; tied to XML) [[
 <?xml version="1.0"?>
 <businessLogic>
   <main>
     <session name="count" expr="#count + 1"/>
     <tag name="count" expr="#count"/>
   </main>
 </businessLogic>

 ]] BOX's XML (4 lines of generated code) [[
 <?xml version="1.0"?>
 <document>
   <count>0</count>
 </document>

 ]] BOX's XSL (7 lines of code) [[
 <?xml version="1.0"?>
 <xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
 <xsl:output method="html" encoding="US-ASCII"/>

 <xsl:template match="document">
   <P>I've been requested <xsl:value-of select="count"/> times.</P>
 </xsl:template>

 </xsl:stylesheet>

By adding "<babel>" tags around the English text, you automatically get
a stylesheet that is in the viewer's language (based on their browser's
Accept-Language).  This is part of the architecture; no extra futzing is
required.  BOX makes it difficult to couple logic and presentation.  For
example, to write a "<p>" tag with logic, you must write <tag
name="p"/>.  XSL is where the <p> tag belongs; not snuggled in with
logic.

Let's look at a slightly more complex example, involving SQL.  First
Cocoon, then BOX.

-=( Second Example )=-

]] Cocoon Logic (20 lines of code) [[
<?xml version="1.0" encoding='ISO-8859-1' standalone="no"?>
<?xml-stylesheet href="../xsl/wic_fournisseursListe.xsl"
type="text/xsl"?>
<?cocoon-process type="xsp"?>
<?cocoon-process type="xslt"?>
<!DOCTYPE page SYSTEM "./librairies/entity.dtd">
<xsp:page
   language="java"
   xmlns:xsp="http://www.apache.org/1999/XSP/Core"
   xmlns:session="http://www.apache.org/1999/XSP/Session"
   xmlns:request="http://www.apache.org/1999/XSP/Request"
   xmlns:response="http://www.apache.org/1999/XSP/Response"
   xmlns:sql="http://www.apache.org/1999/SQL"
   xmlns:log="http://www.arctis.com/2000/XSP/Log"
   create-session="true">
<page title="Liste des fournisseurs">
<xsp:logic>
  try {
    <sql:execute-query>
    &connectDatabase;
    <sql:doc-element>FOURNISSEURS</sql:doc-element>
    <sql:row-element>FOURNISSEUR</sql:row-element>
    <sql:query>
      SELECT * FROM WIC.FOURNIS
      WHERE COD_CLIENT = '<session:get-value> name="WIC_CLIENT"/>'
      ORDER BY NOM_FOURNIS
    </sql:query>
    </sql:execute-query>
  }
  catch (Exception e) {
    <response:send-redirect location="wic_erreur.xml?Langue=FR"/>
  }
</xsp:logic>
</page>
</xsp:page>

]] Cocoon XSL (43 lines of code) [[
 <?xml version="1.0" encoding='ISO-8859-1'?>
 <?cocoon-format type="text/xsl"?>
 <xsl:stylesheet version="1.0"
                 xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
                 xmlns="http://www.w3.org/TR/xhtml1/strict">
 <xsl:import href="./librairies/mainhtml.xsl"/>
 <xsl:import href="./librairies/lib_listes.xsl"/>

 <xsl:template match="/">
   <xsl:call-template name="main"/>
 </xsl:template>

 <xsl:template match="page">
   <xsl:apply-templates select="@title"/>
   <P align="center">
   <xsl:call-template name="tableauFournisseurs">
   <xsl:with-param name="actions">true</xsl:with-param>
   </xsl:call-template>
   </P>
 </xsl:template>

 <xsl:template name="tableauFournisseurs">
   <table border="1" width="100%" align ="center">
   <tr align="center">
     <th>Nom</th>
     <th>Adresse</th>
     <th>Banque</th>
   <xsl:apply-templates select=".//FOURNISSEUR">
   <xsl:with-param name="actions"><xsl:value-of
select="$actions"/></xsl:with-param>
   </xsl:apply-templates>
   </table>
 </xsl:template>

 <xsl:template match="FOURNISSEUR">
 <tr align="left">
   <td>
     <xsl:apply-templates select="NOM_FOURNIS"/>
   </td>
   <td>
     <xsl:apply-templates select="ADR_FOURNIS_1"/><BR/>
     <xsl:apply-templates select="ADR_FOURNIS_2"/><BR/>
     <xsl:apply-templates select="ADR_FOURNIS_3"/>
    </td>
    <td>
     <xsl:apply-templates select="BQE_FOURNIS"/>
    </td>
 </tr>
 </xsl:template>
 </xsl:stylesheet>

]] BOX Logic (28 lines of code) [[
<?xml version="1.0"?>
<businessLogic>
  <main>
    <var name="title" expr="'Liste des fournisseurs'"/>

    <sql>
      <select>
        * FROM WIC.FOURNIS
        WHERE COD_CLIENT=?
        ORDER BY NOM_FOURNIS
      </select>
      <using>
        <value-of expr="#WIC_CLIENT"/>
      </using>
      <container name="results"/>
    </sql>

    <if test="!$RowCount">
      <var name="Phase" expr="'erreur'"/>
      <stop/>
    </if>

    <enumerate container="@results">
      <tag name="fournis"/>
      <tag name="cod_client" expr="@results.cod_client"/>
      <tag name="nom_fournis" expr="@results.nom_fournis"/>
      <tag name="adr_fournis_1" expr="@results.adr_fournis_1"/>
      <tag name="adr_fournis_2" expr="@results.adr_fournis_2"/>
      <tag name="adr_fournis_3" expr="@results.adr_fournis_3"/>
      <tag name="bqe_fournis" expr="@results.bqe_fournis"/>
      <tag name="/fournis"/>
    </enumerate>
  </main>
</businessLogic>

]] BOX XSL (29 lines of code) [[
<?xml version="1.0" encoding='ISO-8859-1'?>
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">

<xsl:import href="/common/header.xsl"/>

<xsl:template name="content">
  <table border="1" width="100%" align ="center">
  <tr align="center">
     <th>Nom</th>
     <th>Adresse</th>
     <th>Banque</th>
  </tr>
  <xsl:apply-templates/>
  </table>
</xsl:template>

<xsl:template match="fournis">
<tr align="left">
  <td>
    <xsl:apply-templates select="nom_fournis"/>
  </td>
  <td>
    <xsl:apply-templates select="adr_fournis_1"/><BR/>
    <xsl:apply-templates select="adr_fournis_2"/><BR/>
    <xsl:apply-templates select="adr_fournis_3"/>
  </td>
  <td>
    <xsl:apply-templates select="bqe_fournis"/>
  </td>
</tr>
</xsl:template>

</xsl:stylesheet>

-fin-

---------------------------------------------------------------------
In case of troubles, e-mail:     webmaster@xml.apache.org
To unsubscribe, e-mail:          general-unsubscribe@xml.apache.org
For additional commands, e-mail: general-help@xml.apache.org


Mime
View raw message