473,466 Members | 1,382 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 2295
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
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
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
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
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
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
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
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
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
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
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
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
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,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
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
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
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...
0
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...

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.