Update:

Current Cocoon (2.2 trunk) contains a SAX-based Transformer org.apache.cocoon.transformation.StripNameSpacesTransformer that strips all namespaces. It's like the NamespaceStripperTransfomer mentioned below, but faster because it does not use the DOM.

Solutions, which WORK:

1.) Serializer (by 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 start!PrefixMapping, end!PrefixMapping, methods to do nothing, effectively removing all namespaces from my HTML. Also startElement and endElement must be overridden, in order to remove namespaces from attributes. 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 serializer).

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

Use the attached NamespaceStripperTransformer to kill all unsused namespaces. It works for me, but isn't really fast. Read the comment of the class in the source for details.

5.) OmitNsTransformer

Updated! New version - should properly omit xmlns:xyz=http://... attributes too. Also clears uri's of appropriate elements.

There is new parameter omit-plain-xmlns, set it to true to omit main xmlns=http://... declaration. It is useful especialy for HTMLSerializer to produce correct HTML without any namespace declaration.

You may also use attached OmitNsTransformer.java - simple SAX event based transformer. This transformer omit just the xmlns:xyz declarations. It can omit all or few of them using special parameter omit-namespaces. Example included in javadoc comments. Brief excerpt from sitemap: