Accursed XMLNS pseudo-attributes
Posted by mholmes on 27 Mar 2007 in Activity log
In an effort to find a way to inject a single rend attribute into the root of the DMS document when it's retrieved from the database (which I'd like to do so that I can pass that on to XSLT processing, for e.g. sorting a TOC), I ran up against yet another infuriating problem with xmlns "attributes" on serialized XML. After struggling for a while, I posted this explanation and request for help to the eXist list:
I have a simple TEI document that starts like this:
<TEI xmlns="http://www.tei-c.org/ns/1.0">
<teiHeader>
<fileDesc>
<titleStmt>
.... and so on.
I query it using a simple XQuery like this:
declare default element namespace "http://www.tei-c.org/ns/1.0";
declare namespace ....
....
<TEI xmlns="http://www.tei-c.org/ns/1.0" version="5.0"
rend="{request:get-parameter('rend', '')}">
{doc('/db/devonshire/DMs_P5.xml')/TEI/teiHeader}
{doc('/db/devonshire/DMs_P5.xml')/TEI/text}
</TEI>
(What I'm doing here basically is just inserting the request parameter
"rend" into the root as an attribute. I expect to get something like this:
<TEI xmlns="http://www.tei-c.org/ns/1.0" rend="title_asc">
<teiHeader>
<fileDesc>
<titleStmt>
...
but what I actually get is this:
<TEI xmlns="http://www.tei-c.org/ns/1.0" version="5.0" rend="">
<teiHeader xmlns="http://www.tei-c.org/ns/1.0">
<fileDesc xmlns="http://www.tei-c.org/ns/1.0">
<titleStmt xmlns="http://www.tei-c.org/ns/1.0">
...
In other words, every single element now has a redundant xmlns
"attribute" attached to it. This is what happens if I serialize the XML
using the standard Cocoon XML serializer. If I do the query in the eXist
client query window, I don't see the extra xmlns attributes. I'm
wondering whether these are added by the Cocoon serializer, and if so,
why? Is there anything in my query that would trigger such behaviour? If
I replace the query with this:
doc('/db/devonshire/DMs_P5.xml')
then I don't see the problem. Removing the default element namespace
declaration from the xquery file makes no difference at all.
I have a feeling this is something to do with the eXist XQuery generator for Cocoon, but I'm not sure yet. For the moment, I have to live with it, but it's annoying, and it makes the serialized XML document much larger than it should be.