Re: [xsl] xsl -> xhtml and xlmns-namespace

Subject: Re: [xsl] xsl -> xhtml and xlmns-namespace
From: Jeni Tennison <jeni@xxxxxxxxxxxxxxxx>
Date: Thu, 19 Feb 2004 15:03:30 +0000
Hi Peter,

> 1) What do I have to add to my .xsl-file to have '<!DOCTYPE html
> PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
> "";> !-->' added as
> the first line of my output? Typing the above doctype doesn't work,
> because then my xml isn't valid anymore

Use the doctype-system and doctype-public attributes on the
<xsl:output> declaration:

  doctype-public="-//W3C//DTD XHTML 1.0 Strict//EN"

> 2) Why is xmlns="..." added in <a href="..">-tags? That's not
> XHTML-valid!

XSLT (1.0) doesn't know anything about XHTML -- as far as it's
concerned, it's just another XML-based markup language, and it should
obey the same rules as any other XML-based markup language. XSLT never
checks the output it generates to make sure that it's valid against a
particular DTD, so it's up to you to make sure you create valid

If you're getting namespace declarations that you don't want, it's
probably because the elements that you're generating are in a
different namespace from the one that you expect. Typically this
happens when you put namespace declarations on a literal result
element, within a template, such that the scope is only within that
literal result element, rather than on the <xsl:stylesheet> document
element, such that the scope is the entire stylesheet.

For example, rather than:

<xsl:stylesheet version="1.0"

<xsl:template match="/">
  <html xmlns="";>


<xsl:stylesheet version="1.0"

<xsl:template match="/">

The latter ensures that all the literal result elements that don't
have a prefix are generated in the XHTML namespace. Typically, an XSLT
processor will output the resulting document with the default
namespace declaration only appearing on the document element of the
result. (I say "typically" because an XSLT processor is allowed to add
any namespace declarations it wants, provided the resulting document
is the same to a namespace-aware processor.)

If that doesn't solve the namespace declaration problem, show us the
code and we should be able to work out where the additional
declaration is coming from.



Jeni Tennison

 XSL-List info and archive:

Current Thread