cocoon-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Ricardo Rocha <rica...@apache.org>
Subject Re: Preserving namespaces in XSP
Date Sun, 07 May 2000 15:19:38 GMT
On Sun, 07 May 2000, Stefano Mazzocchi wrote:
> ricardo@locus.apache.org wrote:
> >      <action dev="RR" type="update">
> >        Added namespace preservation for XSP pages. To preserve namespaces in an
> >        XSP page, add an "xsp:xxx" attribute to the page's root element, where
> >        "xxx" is the namespace and the attribute value is the namespace URI
> >      </action>
>  > Ahhhhh!!!! This is invalid :)

Caramba! I know this mechanism may look kinda kludgy, but let's
take the following into consideration:

Namespace usage in XSP is typically associated with logicsheet
activation (1).

Most logicsheets declare only their own namespace as well as
that of XSP.

During XSP code generation, one or more selected logicsheets
are applied in turn to transform the input XSP document into an
equivalent source program.

As each logicsheet is applied, those namespaces not explicitly
declared in it are _not_ preserved in the [intermediate] resulting
document.

Briefly stated, "xmlns:" attributes are not copied by XSLT unless
they correspond to a namespace declared at the stylesheet root
element level.

To avoid this, one would need to declare all namespaces in all
logicsheets!

In many cases namespaces used for logicsheets need not be
preserved on output, as their dynamic tags are typically
substituted by Java expressions rather than by markup.

For those cases where the result of dynamic tag expansion _is_
a set of one or more namespace-qualified elements, preserving
namespace becomes a necessity.

So far, XSP would silently drop namespace prefixes forcing
stylesheet templates to match _non-qualified_ elements only.
While this works in most cases, it also impairs the usefulness
of namespaces: the resulting element names may well clash
with unrelated, "synonymous" elements...

Thus, a mechanism is needed to selectively preserve
namespaces in XSP documents. "Selectively" here means
that namespaces declared only for logicsheet processing
should not be preserved in the output document.

The strategy chosen for this is to "reuse" the "xsp:" prefix
(not used at all for attributes in XSP) to preserve namespaces
dropped by logicsheet processing.

Thus, for example, if logicsheet "xsql.xsl" uses namespace
"xsql:" for both dynamic and result tags, the following XSP
page illustrates how to preserve the namespace:

  <?cocoon-process type="xsp"?>
  <?xml-logicsheet href="xsql.xsl"?>
  <?cocoon-process type="xslt"?>
  <?xml-stylesheet href="page.xsl" type="text/xsl"?>
  <xsp:page
    language="java"
    xmlns:xsql="http://www.plenix.org/xsp/xsql"
    xmlns:xsp="http://www.apache.org/1999/XSP/Core"
  >
    <-- Namespace preserved here -->
    <page xsp:xsql="http://www.plenix.org/xsp/xsql">
      <title>Employee List<title>
      <xsql:execute-query id="demo" use-connection="scott">
        <xsql:statement>
          SELECT      ename, job, sal
          FROM        emp
          ORDER BY ename
        </xsql:statement>
      </xsql:execute-query>
    </page>
  </xsp:page>

Upon execution, this XSP page would yield:

  <page xmlns:xsql="http://www.plenix.org/xsp/xsql">
    <title>Employee List</title>
    <xsql:rowset id="demo">
      <xsql:row sequence="1">
        <ename>ADAMS</ename>
        <job>CLERK</job>
        <sal>1100</sal>
      </xsql:row>
      .  .  .
    </xsql:rowset>
  </page>

which could then be processed by an XSLT template like:

  <xsl:template match="xsql:rowset[@id = 'demo']">
    <center>
      <table border="1">
        <tr>
          <th>Name</th>
          <th>Jon</th>
          <th>Salary</th>
        </tr>
        <xsl:for-each select="xsql:row">
          <tr>
            <td><xsl:value-of select="ename"/></td>
            <td><xsl:value-of select="job"/></td>
            <td align="right"><xsl:value-of select="sal"/></td>
          </tr>
        </xsl:for-each>
      </table>
    </center>
  </xsl:template>
===============================================================
(1) Btw, let's recall that logicsheets can now be explicitly declared by means
     of  the <?xml-logicsheet?> pi and are no longer tied to namespaces


Mime
View raw message