RE: [xsl] xsl and xml CDATA or Not question

Subject: RE: [xsl] xsl and xml CDATA or Not question
From: "John Hamman" <John@xxxxxxxxxxxxxxxxx>
Date: Mon, 15 Mar 2004 10:18:19 -0500
Wow, That made sense! Thanks so much.

-----Original Message-----
From: owner-xsl-list@xxxxxxxxxxxxxxxxxxxxxx
[mailto:owner-xsl-list@xxxxxxxxxxxxxxxxxxxxxx] On Behalf Of Jeni Tennison
Sent: Monday, March 15, 2004 4:38 AM
To: John Hamman
Cc: xsl-list@xxxxxxxxxxxxxxxxxxxxxx
Subject: Re: [xsl] xsl and xml CDATA or Not question

Hi John,

> So what do I need to do if my xsl is like so.

Well, you need to make your stylesheet well-formed for a start.
Currently you're missing a <html> start tag. My guess, from the
problem that you're having, is that the <html> start tag that you've
got actually looks like:

  <html xmlns="";>

If so, the default namespace declaration within that start tag will be
in scope within that template, and the <html>, <head> and <body>
elements (which are also within that template) will be placed in the
XHTML namespace. But the <br> element, which is copied from the source
document (and isn't in a namespace) will be in no namespace, which is
why you're getting xmlns="" in it.

What I recommend is that you first move the default namespace
declaration on to the <xsl:stylesheet> element, so that it's in scope
for the entire stylesheet. The stylesheet that you have should then
work for <br> elements but for other elements you want to move them
from being in no namespace (as they are in the original XML) to being
in the XHTML namespace, which means that you need to have a template
similar to the one that David C. recommended:

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

The elements that are generated in this way will be in the XHTML
namespace because the namespace declarations that are in effect on the
<xsl:element> instruction are used to interpret the name that's
specified in the name attribute. Since these names don't have a
prefix, the XSLT processor will use the default namespace declaration,
which is for the XHTML namespace.

For what it's worth, since <br> elements are empty but might have
attributes, the template:

<xsl:template match="br | BR">
  <xsl:apply-templates /><br />

should be:

<xsl:template match="br | BR">
    <xsl:copy-of select="@*" />

Also, you probably don't want to have the xml:space attributes in the
stylesheet; use <xsl:text> to add the whitespace that you want to
appear in the output, or trust the indent="yes" on the <xsl:output>
element to give the indentation that you need.



Jeni Tennison

 XSL-List info and archive:

 XSL-List info and archive:

Current Thread