cocoon-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Reinhard Poetz" <>
Subject [Summary] How to remove namespace declarations and prefixes?
Date Mon, 01 Jul 2002 15:15:11 GMT
Thank you Harry and Manos!

I want to provide a summary of this thread - maybe this could be included
into some docs.


 ... I use namespaces and I want to remove them in my result xml ...

(original mail:

Solutions, which NOT work:
exclude-result-prefixes (in the stylesheet)

<omit-xml-declaration> (in the sitemap)

exclude-prefixes (in the stylesheet)

Solutions, which WORK:

Harry Lai:
Kay's XSLT Programmer's Reference:
"The xsl:exclude-result-prefixes and exclude-result-prefixes attributes
apply only to namespace nodes copied from the stylesheet using literal
result elements.  They do not affect namespace nodes copied from
the source document using <xsl:copy> or <xsl:copy-of>: there is no way
of suppressing these."

Unfortunately, since xslt's will often have a catch-all template
matcher to copy elements it doesn't transform, this comes up quite a bit.

So... what I ended up doing was extending the HTMLSerializer (or whatever
serializer you're using for your pipelines), and overriding the
startPrefixMapping and endPrefixMapping methods to do nothing, effectively
removing all namespaces from my HTML.  This also had the added benefit of
having no performance penalties (and theoretically, a
ever-so-slight speedup since we no longer process namespaces in our

You could make this more general, and use the serializer's
configuration to declare which namespaces you want to exclude, but excluding
worked well for us, especially since we were outputting HTML.

(complete mail:

Manos Batsis:
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="1.0"
  <xsl:output method="xml" version="1.0" encoding="UTF-8" indent="yes"/>
    <xsl:template match="*">
      <!-- remove element prefix (if any) -->
      <xsl:element name="{local-name()}">
        <!-- process attributes -->
        <xsl:for-each select="@*">
          <!-- remove attribute prefix (if any) -->
          <xsl:attribute name="{local-name()}">
            <xsl:value-of select="."/>

(complete mail:


Please check that your question  has not already been answered in the
FAQ before posting.     <>

To unsubscribe, e-mail:     <>
For additional commands, e-mail:   <>

View raw message