[xsl] Namespaces and the identity transform

Subject: [xsl] Namespaces and the identity transform
From: "James Carlyle" <james.carlyle@xxxxxxxxxxxx>
Date: Thu, 17 Oct 2002 18:01:16 +0100
I have a simple document:
<?xml version="1.0"?>
	<div id="header">

I want to produce a strict xhtml document and use the following stylesheet:
<?xml version="1.0" ?>
<xsl:stylesheet version="1.0"
<xsl:output method="xml"
	doctype-public="-//W3C//DTD XHTML 1 Strict//EN"

<xsl:template match="@*|node()">
		<xsl:apply-templates select="@*|node()"/>

<xsl:template match="doc">
		<xsl:apply-templates select="@*|node()"/>

What I get is
<?xml version="1.0" encoding="UTF-16"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1 Strict//EN"
<html xmlns="http://www.w3.org/1999/xhtml";>
	<body xmlns="">
		<div id="header"><h1>TakePart</h1></div>

This is correct, since the html output element has the default namespace,
whereas the body element outputted through the identity transform has no
namespace.  I get the null namespace on any elements passing through the
identity transform.

How can I design an identity transform that applies the default namespace to
the output?  I prefer not to have to restructure my input, and I want all
output nodes to use the strict xhtml namespace.  I substituted the above
identity transform with the following and this seems to produce the correct
output, but is this the most efficient way of doing it?

<xsl:template match="*">
	<xsl:element name="{name()}">
		<xsl:apply-templates select="@*|node()"/>

<xsl:template match="@*">
	<xsl:attribute name="{name()}">
		<xsl:value-of select="."/>

Many thanks,

James Carlyle

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

Current Thread