Subject: Re: [xsl] xsl and xml CDATA or Not question From: Jeni Tennison <jeni@xxxxxxxxxxxxxxxx> Date: Mon, 15 Mar 2004 09:37:36 +0000 |
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
Current Thread |
---|
|
<- Previous | Index | Next -> |
---|---|---|
RE: [xsl] xsl and xml CDATA or Not , John Hamman | Thread | RE: [xsl] xsl and xml CDATA or Not , John Hamman |
Re: [xsl] XSL Transformation, Brian Chrisman | Date | RE: [xsl] XSLT 2.0 and implementati, David . Pawson |
Month |