XSLT: avoiding unnecessary ns declaration in HTML output

Steffen Beyer

Usenet Archive
Joined
Apr 17, 2001
Messages
7
Reaction score
0
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,
 

Steffen Beyer

Usenet Archive
Joined
Apr 17, 2001
Messages
7
Reaction score
0
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,
 

Richard Tobin

Usenet Archive
Joined
Jan 6, 2000
Messages
4,251
Reaction score
0
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

No members online now.

Forum statistics

Threads
548,208
Messages
3,104,799
Members
249,594
Latest member
henrywalsh

Latest Threads

Top