Re: [xsl] Namespace conflicts processing Word documents

Subject: Re: [xsl] Namespace conflicts processing Word documents
From: Peter Flynn <pflynn@xxxxxx>
Date: Mon, 06 Oct 2008 16:52:23 +0100
G. Ken Holman wrote:
Prefixes are cheap and ambiguous ... namespace-aware processing is based on the URI a prefix points to, not the prefix itself. A WordML document using "w:" as a prefix is independent of an OOXML document using "w:" as a prefix.

Syntactically, yes. Semantically, a paragraph is a paragraph is a paragraph (unless it's a heading, or a list item -- but those are just qualified paragraphs in Word :-)

On the surface, this appears to mean that an XSLT file written to process WordML files' w:* elements cannot be used to process OOXML files' w:* elements -- two parallel versions are needed, one with the WordML w: namespace and one with the OOXML w: namespace.

But XSLT only worries about the namespace URI and prefixes used in XSLT are independent of prefixes used in XML source documents.

Also, prefixes used in *different* XSLT fragments (even when imported or included) are independent of the prefixes used in the importing and including stylesheets.

This is because all of the documents described above are standalone XML documents so each document can have an independent set of prefixes.

Right, so I can have two otherwise identical stylesheets, one declaring the WordML w: namespace and the other declaring the OOXML w: namespace, with both using the identical
<xsl:template match="w:p[w:pPr[w:pStyle[@w:val='Heading1']]]">
but I can't have a shell stylesheet for each namespace which both import/include the template code from a common (shared) file, because (a) namespaces don't get inherited into imports/includes, and (b) the common file will necessarily lack any namespace declaration for w: and will therefore not be well-formed.

OK. So long as I wasn't missing a trick there.

What I think you are missing is that an XSLT stylesheet has no obligation to use the same prefix as another XSLT stylesheet or any XML document being used as a source file.

Except that when it comes to process the document, the declared namespace URI (IRI) must be the same in both the stylesheet and the document.

I was hoping to do without preprocessing, but as this is all in Cocoon anyway, pipelining it isn't really a problem.


Current Thread