[XSL-LIST Mailing List Archive Home] [By Thread] [By Date] [Recent Entries] [Reply To This Message]

Namespaces and the identity transform

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

I want to produce a strict xhtml document and use the following stylesheet:
<?xml version="1.0" ?>
<xsl:stylesheet version="1.0"
	xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns="http://www.w3.org/1999/xhtml">
<xsl:output method="xml"
	doctype-public="-//W3C//DTD XHTML 1 Strict//EN"
	doctype-system="http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"/>

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

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

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

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:element>
</xsl:template>

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


Many thanks,

James Carlyle


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


Current Thread

PURCHASE STYLUS STUDIO ONLINE TODAY!

Purchasing Stylus Studio from our online shop is Easy, Secure and Value Priced!

Buy Stylus Studio Now

Download The World's Best XML IDE!

Accelerate XML development with our award-winning XML IDE - Download a free trial today!

Don't miss another message! Subscribe to this list today.
Email
First Name
Last Name
Company
Subscribe in XML format
RSS 2.0
Atom 0.3
Site Map | Privacy Policy | Terms of Use | Trademarks
Free Stylus Studio XML Training:
W3C Member
Stylus Studio® and DataDirect XQuery ™are products from DataDirect Technologies, is a registered trademark of Progress Software Corporation, in the U.S. and other countries. © 2004-2013 All Rights Reserved.