[XML4Lib] Re: ignoring doctype
Conal Tuohy
Conal.Tuohy at vuw.ac.nz
Sun Oct 29 18:24:27 EST 2006
Eric Lease Morgan wrote:
> I think I can answer my own question:
>
> 1) HTML snippet above is not accurate. My original content
> includes an unnamed namespace and looks like this:
>
> <html xmlns="http://www.w3.org/1999/xhtml">
In fact the XHTML DTD referenced by your DOCTYPE declaration defined an
"xmlns" attribute for the "html" element, with a fixed value of
"http://www.w3.org/1999/xhtml". So with your DOCTYPE declaration the
elements in the XHTML you quoted would have had a namespace, but without
the DOCTYPE there would have been no namespace.
i.e. with DOCTYPE:
<html xmlns="http://www.w3.org/1999/xhtml"> ...
without DOCTYPE:
<html> ...
> 2) By declaring the namespace in my XSLT the problem goes away:
>
> <xsl:stylesheet
> xmlns:xsl = "http://www.w3.org/1999/XSL/Transform"
> xmlns:h = "http://www.w3.org/1999/xhtml"
> version = "1.0">
>
> 3) Last, I need to include the namespace in my templates:
>
> <xsl:template match="h:meta">
>
> Namespaces have always been confusing to me. Sigh.
It's quite a common mistaken belief that a default namespace (i.e. a
namespace used without a prefix) can be matched by XSLT templates which
have the same default namespace. But in fact the "match" attribute of an
XSLT template which is supposed to match a namespaced element must
ALWAYS use a namespace prefix to do so. It makes no difference whether
the input document uses a default (unprefixed) namespace or uses
namespace prefixes. In XSLT you can use a default namespace to unclutter
your output, but it doesn't help at all for input.
Con
More information about the XML4Lib
mailing list