RE: Accessing the XML declaration, the namespace-uri() function

Subject: RE: Accessing the XML declaration, the namespace-uri() function
From: Mike Brown <mbrown@xxxxxxxxxxxxx>
Date: Fri, 5 Nov 1999 13:38:40 -0700
> >Dylan Walsh wrote:
> The default XML viewer stylesheet
> uses <xsl:template match="pi('xml')> as I've mentioned in
> another post. Alas this isn't possible with up to date XSL.

I missed the other post, but yeah, the XPath spec says:
"NOTE: The XML declaration is not a processing instruction.
Therefore, there is no processing instruction node
corresponding to the XML declaration."

What I can't figure out is if you're trying to
reconstruct the XML document based solely on what the
XSL processor sees in the source tree. If that's the
case, then you not only don't have the <?xml?>
declaration, you also don't have entity references or
the DTD. Nor do you have the original encoding of the
document, so while your original document may say
<?xml version="1.0" encoding="utf-16"?>, your HTML
representation of that is going to likely be using
iso-8859-1. I'm not sure what the ramifications of
this are, but I'm sure it's not pretty.

> I'd like elements which declare names spaces to have 
> xmlns:foo="uri" in my output, as they do in the
> source. I've made some progress with namespace-uri(),
> but I don't think I'll be able to do what I want to
> until XT supports the namespace axis (which will
> allow me to show the name of the namespace).

Oh, right. Namespace declarations are not in the tree
as attribute nodes; they're namespace nodes, which
can only be seen along the namespace axis. The XPath
function namespace-uri() exposes the namespace URI
of an element, but the prefix would have to be
deduced by looking for descendants that use it. This
is theoretically do-able if you look for a non-null
substring-before(":",name(.)) for each element and
attribute that has the namespace URI in question and
that is located on the descendant-or-self axis. But
this wouldn't catch cases where the prefix is
declared but never used, or where the prefix is
used incorrectly outside of its scope.


 XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list


Current Thread