cocoon-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Ricardo Rocha <>
Subject Re: [PATCH] and fix Re: Trouble with namespace
Date Wed, 16 Aug 2000 18:31:08 GMT
Robin Green wrote:
> Alexander Krasilnikov <> wrote:
> >       I have strange trouble with namespace's. Small example:
> I had a similar problem. The undocumented workaround is to replace
> <em:page xmlns:em="http://west/">
> with
> <em:page xsp:em="http://west/">
> The xsp: namespace prefix acts as a surrogate xmlns: and is read in and
> corrected by the XSP processor. The need for this is due to a frankly
> patronising flaw in the XSLT specification, where they decided that
> stylesheet authors should not be able to access xmlns attributes - I don't
> know why - presumably because there was "too much potential for
> confusion/abuse". Sigh.
> Since the XSP processor uses a logicsheet (xsp-java.xsl) to do most of the
> xsp transformations, it is hampered by this limitation. However, I have a
> (not-very-much-tested) patch here which should allow you to use xmlns: in
> content elements (i.e. anything except the xsp:page element, which is
> reserved for logicsheet namespaces), in the standard way, and the
> substitition would be performed automatically.

Yes, as usual, Robin is absolutely right.

I may have found a solution for this. In the last-step XSP
logicsheet we can rewrite the generic element-matching
template to read:

  <xsl:template match="*">
    xspParentNode = xspCurrentNode;
    xspCurrentNode =
      document.createElement("<xsl:value-of select="name(.)"/>");

    <!-- Begin namespace workaround -->
    <xsl:for-each select="namespace::*">
      ((Element) xspCurrentNode).setAttribute(
        "xmlns:<xsl:value-of select="local-name(.)"/>",
        "<xsl:value-of select="."/>"
    <!-- End namespace workaround -->

    <xsl:apply-templates select="@*"/>

    ((Element) xspCurrentNode).normalize();
    xspCurrentNode = (Node) xspNodeStack.pop();

This is more general than the current hack: it'll preserve namespace
declarations in every element, not just the root.

I've used a similar approach in XSP for Cocoon2 and it preserves
namespaces correctly.

View raw message