Re: Incorrect output with Firefox when using xmlns attribute
Fabrice Desré <[email protected]> Mon, 17 Sep 2007 04:22:41 -0500
| Newsgroups | gmane.comp.mozilla.devel.layout.xslt |
|---|---|
| Message-ID | <[email protected]> |
On Sun, 16 Sep 2007 23:21:20 +0000, aaronaberg wrote:
> When I use Firefox to open the xml file it works properly when I dont
> have the xmlns attribute, but it only shows "a" on the screen when I do
> include it. This tells me that match="/" works in both cases but
> match="head" does not. Why is this?
This is because when adding the xmlns="http://www.w3.org/1999/xhtml"
attribute, all the unprefixed elements in your source documents end up in
the xhtml namespace. Since XPath 1.0 has no default namespace, all
unprefixed elements in XPath 1.0 are in the "null" namespace. So you need
to declare a prefix bound to the xhtml namespace in your stylesheet, and
use it in your templates. This should work :
<xsl:stylesheet xmlns:xsl = "http://www.w3.org/1999/XSL/Transform" version
= "1.0" xmlns:h="http://www.w3.org/1999/xhtml">
<xsl:output method = "text" />
<xsl:template match = "/" >a
<xsl:apply-templates/>
</xsl:template>
<xsl:template match="h:head">b
<xsl:apply-templates/>
</xsl:template>
<xsl:template match="h:title">c
Title: <xsl:value-of select="."/>
</xsl:template>
</xsl:stylesheet>
HTH,
Fabrice