However, creating the html root as a literal result element (or via
xsl:element), used in combination with namespace declarations and
exclude-result-prefixes on the stylesheet element, will give you a
certain
control over the namespace declarations to be added/omitted.
(Don't know about the rest of you over here, but simply copying the
root in
this case seems to be asking for trouble --or at least, seems to
complicate
things unnecessarily...)
I've noticed this with few other tests I did, and fised it accordingly
as suggested by Ken Holman few emails back.
(I'm not really concerted with removing them, as they do no
harm, but it would certainly be cleaner. I'm more concerned about
adding new ones in.)
Can you be a bit more specific about this? Do you mean that you
introduce
new namespaces in the transform that are declared in none of the source
documents?
Again, if you create the root as a literal result element, you can add
custom namespace declarations to it by defining them on xsl:stylesheet
(and
not adding their respective prefixes to the list in the
exclude-result-prefixes attribute).
The was I had my stylesheet working was that I introduces namespaces
that I wanted to process in the source html document (and hence could
not introduce xhtml one, as it would strip all the tags out.
And becaused I used to use copy, the xhtml namespace would not be
introduces in the output (only my custom one was preserved - copied
from the source).
With rewriting the stylesheet as suggested and introducing doctype, the
xhtml xmlns is now in the output document.
I'm attaching my current version below, just so it's easier to
understand. Anyway, thanks everyone for their help, I've got it almost
all working.
Thanks,
Mayo
Source: (not including doctype)
<html xmlns="http://www.w3.org/1999/xhtml"
xmlns:tpl="tpl:namespace"
xml:lang="en" lang="en">
<head>
<meta http-equiv="content-type" content="text/html;
charset=ISO-8859-1" />
<title>xslt test</title>
</head>
<body>
<p>xsl test1: <tpl:var/></p>
</body>
</html>
Stylesheet:
<?xml version="1.0" encoding="ISO-8859-1"?>
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:tpl="tpl:namespace"
xmlns:xhtml="http://www.w3.org/1999/xhtml"
exclude-result-prefixes="tpl">
<xsl:output method="xml" indent="yes"
doctype-public="-//W3C//DTD XHTML 1.0 Strict//EN"
doctype-system="http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"
omit-xml-declaration="yes"/>
<xsl:strip-space elements="*"/>
<xsl:template match="*[not(namespace-uri())] | xhtml:*">
<xsl:element name="{local-name(.)}">
<xsl:apply-templates/>
</xsl:element>
</xsl:template>
<xsl:template match="tpl:var">
<xsl:element name="b">
<xsl:value-of select="'blarg'"/>
</xsl:element>
</xsl:template>
<!-- last catchall, to be safe -->
<xsl:template match="tpl:*"/>
</xsl:stylesheet>