XSLT: avoiding unnecessary ns declaration in HTML output

S

Steffen Beyer

Hi,

my XSLT processes input documents which use various namespaces. Short
example:


XML input:
<xmlns:news="http://some.example/news"/>


XSLT:
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:news="http://some.example/news">

<xsl:eek:utput method="html"/>

<xsl:template match="<html>
<head><title>Demo</title></head>
<body>
<p>Demo</p>
</body>
</html>
</xsl:template>

</xsl:stylesheet>


HTML output:
<html xmlns:news="http://some.example/news">
<head>
<title>Demo</title>
</head>
<body>
<p>Demo</p>
</body>
</html>


Now, the "xmlns:news" attribute is neither necessary nor valid HTML.
Using LibXSLT, how can I avoid it?

Regards,
 
S

Steffen Beyer

On 2 Nov 2004 12:03:57 GMT
Add an exclude-result-prefixes="news" attribute to the stylesheet
element.

That's a step forward, thank you!

Is it possible to let this setting apply to the "xsl:copy-of" element?

Modified example:


XML input:
<xmlns:news="http://some.example/news">
<bar>Demo</bar>
</

XSLT:
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:news="http://some.example/news"
exclude-result-prefixes="news">

<xsl:eek:utput method="html"/>

<xsl:template match="<html>
<head><title>Demo</title></head>
<body>
<xsl:apply-templates/>
</body>
</html>
</xsl:template>

<xsl:template match="bar">
<xsl:copy-of select="."/>
</xsl:template>

</xsl:stylesheet>


HTML output:
<html>
<head>
<title>Demo</title>
</head>
<body>
<bar xmlns:news="http://some.example/news">Demo</bar>
</body>
</html>


Regards,
 
R

Richard Tobin

Add an exclude-result-prefixes="news" attribute to the stylesheet
element.

That's a step forward, thank you!

Is it possible to let this setting apply to the "xsl:copy-of" element?[/QUOTE]

No, it only applies to literal result elements.

I think you have to replace xsl:copy-of with a set of templates that
do the copying. And you can't use xsl:copy for the elements, because
it copies namespace nodes. You would have to use xsl:element to
create an element of the same name.

-- Richard
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,998
Messages
2,570,242
Members
46,834
Latest member
vina0631

Latest Threads

Top