473,485 Members | 1,660 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

XSLT: avoiding unnecessary ns declaration in HTML output

Hi,

my XSLT processes input documents which use various namespaces. Short
example:
XML input:
<news:foo 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:output method="html"/>

<xsl:template match="news:foo">
<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 <sb****@reactor.de>

GnuPG key fingerprint: CA00 1611 242B 89D4 E643 E235 05F3 7689 DD3E EB26
Public key available upon request or at http://wwwkeys.de.pgp.net
Jul 20 '05 #1
3 2296
In article <20****************************@reactor.de>,
Steffen Beyer <sb****@reactor.de> wrote:
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:news="http://some.example/news">


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

-- Richard
Jul 20 '05 #2
On 2 Nov 2004 12:03:57 GMT
ri*****@cogsci.ed.ac.uk (Richard Tobin) wrote:
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:
<news:foo xmlns:news="http://some.example/news">
<bar>Demo</bar>
</news:foo>
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:output method="html"/>

<xsl:template match="news:foo">
<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,
--
Steffen Beyer <sb****@reactor.de>

GnuPG key fingerprint: CA00 1611 242B 89D4 E643 E235 05F3 7689 DD3E EB26
Public key available upon request or at http://wwwkeys.de.pgp.net
Jul 20 '05 #3
In article <20****************************@reactor.de>,
Steffen Beyer <sb****@reactor.de> wrote:
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?


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
Jul 20 '05 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
2679
by: Sergio del Amo | last post by:
Hi, I use the xslt functions provided by php. I am running in my computer the package xampp(www.apachefriends.org) which includes php/apache/mysql .. In this package the php includes the sablotron...
1
1952
by: Eric Weiss | last post by:
I have an XML document that I want to use to create two HTML versions: one detailed and one a summary. The detailed output is straight forward to create, but the summary output that excludes the...
2
3162
by: Jesper Moth | last post by:
The MSXML4 xslt-parser would output any source <div/> like this: <div></div> I never figured out how to disable this behaviour. But since it makes the source document look cleaner, and since...
20
6727
by: Bernd Fuhrmann | last post by:
Hi! I have some trouble with some simple stupid XSLT-stuff. My stylesheet: ------------- <?xml version="1.0" encoding="iso-8859-1"?> <xsl:stylesheet version="1.0"...
8
5997
by: Kathleen Dollard | last post by:
Hi, Oleg's answer about attribute value templates led me to look back at a different problem, and wonder if someone else had solved it. I want to output an ASP.NET page. Thus I need to output...
4
2173
by: Philip Rayne | last post by:
Probably a bit of a newbie question this. I have an XML file like this: <?xml version="1.0" standalone="yes"?> <AuditLogonGroup xmlns="http://tempuri.org/AuditLogon.xsd"> <AuditLogon>...
7
2825
by: Harolds | last post by:
The code below worked in VS 2003 & dotnet framework 1.1 but now in VS 2005 the pmID is evaluated to "" instead of what the value is set to: .... xmlItems.Document = pmXML // Add the pmID...
4
7710
by: th1421 | last post by:
Hi, I'm new to FireFox. I am currently trying to convert my website to be compatible with it. Doing so I’m trying to process some XML/XSLT pages (preferably without using JavaScript). When I...
3
4498
by: joelkeepup | last post by:
Hi, im trying to create a text email message using xslt template , the transforms work great, but the newlines and whitespace in the xslt doc are removed. Is there a setting somewhere I have...
0
7085
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
6954
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
7107
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
1
6816
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
7247
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
5409
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
4536
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
3048
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
1
593
muto222
php
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.