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

RE: xsl and xml CDATA or Not question

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

-----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 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="http://www.w3.org/1999/xhtml">

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

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

should be:

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

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.

Cheers,

Jeni

---
Jeni Tennison
http://www.jenitennison.com/


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



 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.