473,543 Members | 4,392 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

namespace problem with XSLT

Hi!

I have some trouble with some simple stupid XSLT-stuff.

My stylesheet:
-------------
<?xml version="1.0" encoding="iso-8859-1"?>
<xsl:styleshe et
version="1.0"
xmlns:xsl="http ://www.w3.org/1999/XSL/Transform"
xmlns="http://www.w3.org/1999/xhtml"

<xsl:output method="xml"
cdata-section-elements="scrip t"
doctype-public="-//W3C//DTD XHTML 1.0 Transitional//EN"
doctype-system="http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dt d"
encoding="iso-8859-1"/>

<xsl:template match="html">
<p>Inserted</p>
</xsl:template>

</xsl:stylesheet>
-------------
My XML-Document:
-------------
<?xml version="1.0" encoding="iso-8859-1"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dt d">
<html xmlns="http://www.w3.org/1999/xhtml">
<head><title>Wh atever</title></head><body></body></html>
-------------

The result of this transformation is:
-------------
<?xml version="1.0" encoding="iso-8859-1"?>
-------------
or
-------------
<?xml version="1.0" encoding="iso-8859-1"?>

Whatever
-------------

Obviously the result should be sth. like <?xml ...><p>Inserted </p> and
now for the truly strange thing: Changing the stylesheet to:
------------
<?xml version="1.0" encoding="iso-8859-1"?>
<xsl:styleshe et
version="1.0"
xmlns:xsl="http ://www.w3.org/1999/XSL/Transform"
xmlns="http://www.w3.org/1999/xhtml"
xmlns:xhtml="ht tp://www.w3.org/1999/xhtml"


<xsl:output method="xml"
cdata-section-elements="scrip t"
doctype-public="-//W3C//DTD XHTML 1.0 Transitional//EN"
doctype-system="http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dt d"
encoding="iso-8859-1"/>

<xsl:template match="xhtml:ht ml">
<p>Inserted</p>
</xsl:template>

</xsl:stylesheet>
------------
results in:
------------
<?xml version="1.0" encoding="iso-8859-1"?>
<!DOCTYPE p PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dt d">
<p xmlns="http://www.w3.org/1999/xhtml"
xmlns:xhtml="ht tp://www.w3.org/1999/xhtml">Inserted </p>
------------

Why? Why does changing a namespace declaration change the behaviour of a
XSLT processor (tried Saxon (7.6.5) and Xalan (1.6.0 with Xerxes 2.3.0))
in that way? Shouldn't match="sometag" mean default-xmlns:sometag?

In case the xmlns:xhtml-Namespace is necessary: Is there a way to keep
the xslt-processors (saxon or xalan) from inserting unused, thus
unnecessary namespace declarations that interfere with the W3C XHTML
validator?

Thanks in advance
Bernd Fuhrmann

Jul 20 '05 #1
20 6735
This is a very FAQ.

See:

http://www.topxml.com/people/bosley/defaultns.asp
=====
Cheers,

Dimitre Novatchev.
http://fxsl.sourceforge.net/ -- the home of FXSL
"Bernd Fuhrmann" <si**********@g mx.de> wrote in message
news:bl******** *****@news.t-online.com...
Hi!

I have some trouble with some simple stupid XSLT-stuff.

My stylesheet:
-------------
<?xml version="1.0" encoding="iso-8859-1"?>
<xsl:styleshe et
version="1.0"
xmlns:xsl="http ://www.w3.org/1999/XSL/Transform"
xmlns="http://www.w3.org/1999/xhtml"
>


<xsl:output method="xml"
cdata-section-elements="scrip t"
doctype-public="-//W3C//DTD XHTML 1.0 Transitional//EN"
doctype-system="http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dt d"
encoding="iso-8859-1"/>

<xsl:template match="html">
<p>Inserted</p>
</xsl:template>

</xsl:stylesheet>
-------------
My XML-Document:
-------------
<?xml version="1.0" encoding="iso-8859-1"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dt d">
<html xmlns="http://www.w3.org/1999/xhtml">
<head><title>Wh atever</title></head><body></body></html>
-------------

The result of this transformation is:
-------------
<?xml version="1.0" encoding="iso-8859-1"?>
-------------
or
-------------
<?xml version="1.0" encoding="iso-8859-1"?>

Whatever
-------------

Obviously the result should be sth. like <?xml ...><p>Inserted </p> and
now for the truly strange thing: Changing the stylesheet to:
------------
<?xml version="1.0" encoding="iso-8859-1"?>
<xsl:styleshe et
version="1.0"
xmlns:xsl="http ://www.w3.org/1999/XSL/Transform"
xmlns="http://www.w3.org/1999/xhtml"
xmlns:xhtml="ht tp://www.w3.org/1999/xhtml"
>


<xsl:output method="xml"
cdata-section-elements="scrip t"
doctype-public="-//W3C//DTD XHTML 1.0 Transitional//EN"
doctype-system="http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dt d"
encoding="iso-8859-1"/>

<xsl:template match="xhtml:ht ml">
<p>Inserted</p>
</xsl:template>

</xsl:stylesheet>
------------
results in:
------------
<?xml version="1.0" encoding="iso-8859-1"?>
<!DOCTYPE p PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dt d">
<p xmlns="http://www.w3.org/1999/xhtml"
xmlns:xhtml="ht tp://www.w3.org/1999/xhtml">Inserted </p>
------------

Why? Why does changing a namespace declaration change the behaviour of a
XSLT processor (tried Saxon (7.6.5) and Xalan (1.6.0 with Xerxes 2.3.0))
in that way? Shouldn't match="sometag" mean default-xmlns:sometag?

In case the xmlns:xhtml-Namespace is necessary: Is there a way to keep
the xslt-processors (saxon or xalan) from inserting unused, thus
unnecessary namespace declarations that interfere with the W3C XHTML
validator?

Thanks in advance
Bernd Fuhrmann

Jul 20 '05 #2
Dimitre Novatchev wrote:
See:
http://www.topxml.com/people/bosley/defaultns.asp Read. However that wasn't obvious from reading the standard. At least I
have not found any part in XSLT/XPath/... 1.0 that talks about this problem.
This is a very FAQ.


Possible. I have, so far, only read some examples and done some stuff
myself. So I must write <xsl:template match="xhtml:so metag">... . But
how can I then avoid to break validation of XHTML by their DTDs when
Xalan and Saxon (and most likely some other XSLT processors too) insert
their redundant xmlns:xhtml=".. ." in the result?

Thanks again in advance,
Bernd Fuhrmann

Jul 20 '05 #3
> So I must write <xsl:template match="xhtml:so metag">... . But
how can I then avoid to break validation of XHTML by their DTDs when
Xalan and Saxon (and most likely some other XSLT processors too) insert
their redundant xmlns:xhtml=".. ." in the result?

Can you give an example?
=====
Cheers,

Dimitre Novatchev.
http://fxsl.sourceforge.net/ -- the home of FXSL

Jul 20 '05 #4
Dimitre Novatchev wrote:
Can you give an example? Sure:
Stylesheet:
-----------
<?xml version="1.0" encoding="iso-8859-1"?>
<xsl:styleshe et
version="1.0"
xmlns:xsl="http ://www.w3.org/1999/XSL/Transform"
xmlns="http://www.w3.org/1999/xhtml"
xmlns:xhtml="ht tp://www.w3.org/1999/xhtml"


<xsl:output method="xml"
cdata-section-elements="scrip t"
doctype-public="-//W3C//DTD XHTML 1.0 Transitional//EN"
doctype-system="http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dt d"
encoding="iso-8859-1"/>

<xsl:template match="*|@*|tex t()|processing-instruction()">
<xsl:copy>
<xsl:apply-templates select="*|@*|te xt()|processing-instruction()"/>
</xsl:copy>
</xsl:template>

<xsl:template match="xhtml:ht ml/xhtml:head/xhtml:title">
<title>Some Title</title>
</xsl:template>

</xsl:stylesheet>
-----------
XML-Document:
-----------
<?xml version="1.0" encoding="iso-8859-1"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dt d">
<html xmlns="http://www.w3.org/1999/xhtml">
<head><title>Wh atever</title></head><body></body></html>
-----------
Result:
<?xml version="1.0" encoding="iso-8859-1"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dt d">
<html xmlns="http://www.w3.org/1999/xhtml">
<head><title xmlns:xhtml="ht tp://www.w3.org/1999/xhtml">Some
Title</title></head><body /></html>
-----------
The result actually changes a bit (but not to any solution) when I use
<xhtml:title>So me Title</xhtml:title>.
Both, Xalan and Saxon give me a similar result. Of course this will
never validate to the XHTML-DTD.

Any idea what I could do to fix this problem?

Thanks in advance,
Bernd Fuhrmann

Jul 20 '05 #5
In article <bl************ *@news.t-online.com>, Bernd Fuhrmann wrote:
[snip]
Possible. I have, so far, only read some examples and done some stuff
myself. So I must write <xsl:template match="xhtml:so metag">... . But
how can I then avoid to break validation of XHTML by their DTDs when
Xalan and Saxon (and most likely some other XSLT processors too) insert
their redundant xmlns:xhtml=".. ." in the result?


Add

exclude-result-prefixes="xhtml "

as an attribute of xsl:stylesheet.
Jul 20 '05 #6
Using
exclude-result-prefixes="xhtml "

on the xsl:stylesheet element

I get a good result from XalanJ 2.1.4

but with Saxon 6.5.2 still the prefix is on the title element.

File this as a Saxon bug (the latest version is 6.5.3 -- probably this is
fixed there?)

or
use Saxon 7, which also produces the correct result.
=====
Cheers,

Dimitre Novatchev.
http://fxsl.sourceforge.net/ -- the home of FXSL
"Bernd Fuhrmann" <si**********@g mx.de> wrote in message
news:bl******** *****@news.t-online.com...
Dimitre Novatchev wrote:
Can you give an example?

Sure:
Stylesheet:
-----------
<?xml version="1.0" encoding="iso-8859-1"?>
<xsl:styleshe et
version="1.0"
xmlns:xsl="http ://www.w3.org/1999/XSL/Transform"
xmlns="http://www.w3.org/1999/xhtml"
xmlns:xhtml="ht tp://www.w3.org/1999/xhtml"
>


<xsl:output method="xml"
cdata-section-elements="scrip t"
doctype-public="-//W3C//DTD XHTML 1.0 Transitional//EN"
doctype-system="http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dt d"
encoding="iso-8859-1"/>

<xsl:template match="*|@*|tex t()|processing-instruction()">
<xsl:copy>
<xsl:apply-templates select="*|@*|te xt()|processing-instruction()"/>
</xsl:copy>
</xsl:template>

<xsl:template match="xhtml:ht ml/xhtml:head/xhtml:title">
<title>Some Title</title>
</xsl:template>

</xsl:stylesheet>
-----------
XML-Document:
-----------
<?xml version="1.0" encoding="iso-8859-1"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dt d">
<html xmlns="http://www.w3.org/1999/xhtml">
<head><title>Wh atever</title></head><body></body></html>
-----------
Result:
<?xml version="1.0" encoding="iso-8859-1"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dt d">
<html xmlns="http://www.w3.org/1999/xhtml">
<head><title xmlns:xhtml="ht tp://www.w3.org/1999/xhtml">Some
Title</title></head><body /></html>
-----------
The result actually changes a bit (but not to any solution) when I use
<xhtml:title>So me Title</xhtml:title>.
Both, Xalan and Saxon give me a similar result. Of course this will
never validate to the XHTML-DTD.

Any idea what I could do to fix this problem?

Thanks in advance,
Bernd Fuhrmann

Jul 20 '05 #7
Dimitre Novatchev wrote:
Using
exclude-result-prefixes="xhtml "

on the xsl:stylesheet element

I get a good result from XalanJ 2.1.4

but with Saxon 6.5.2 still the prefix is on the title element.

File this as a Saxon bug (the latest version is 6.5.3 -- probably this is
fixed there?)

or
use Saxon 7, which also produces the correct result.

I'm using Saxon 7 and/or Xalan. It works, thanks a lot. Thanks aswell to
A. Bolmarcich!
Bernd Fuhrmann
Jul 20 '05 #8
Sorry if I'm not posting to the right place.

I have an unwanted "xmlns" attribute showing up in my otherwise-valid
XHTML result document from an XSLT transformation.

The source XML document uses XHTML elements. To avoid prefixing them,
I have made "http://www.w3.org/1999/xhtml" the default namespace.

<?xml version="1.0" encoding="UTF-8"?>
<myml:thought
xmlns:myml="htt p://www.mywords.com "
xmlns="http://www.w3.org/1999/xhtml">

<myml:translati on xml:lang="fr">
<p>
Tu es <em>belle</em>.
</p>
</myml:translatio n>

</myml:thought>
In XSLT style sheet, I again make "http://www.w3.org/1999/xhtml" the
default namespace. Notice that I have using the XLST "copy-of" to get
the XHTML elements from the XML source document into the result
document.

<?xml version="1.0" encoding="UTF-8"?>
<xsl:styleshe et
version="1.0"
xmlns:xsl="http ://www.w3.org/1999/XSL/Transform"
xmlns:myml="htt p://www.mywords.com "
xmlns="http://www.w3.org/1999/xhtml"


<xsl:output
method="xml"
version="1.0"
doctype-public="-//W3C//DTD XHTML 1.0 Strict//EN"

doctype-system="http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"
indent="yes"
media-type="applicati on/xhtml+xml"
/>

<xsl:template match="myml:tho ught">
<html>
<head>
<title></title>
</head>
<body>
<xsl:apply-templates select="myml:tr anslation"/>
</body>
</html>
</xsl:template>

<xsl:template match="myml:tra nslation">
<div>
<xsl:attribut e name="xml:lang" >
<xsl:value-of select="@xml:la ng"/>
</xsl:attribute>
<xsl:copy-of select="./*"/>
</div>
</xsl:template>

</xsl:stylesheet>
The result I would hope for is this, a valid XHTML 1.0 Strict web page:
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title />
</head>
<body>
<div xml:lang="fr">
<p>
Tu es <em>belle</em>.
</p>
</div>
</body>
</html>
But the result I get is an invalid XHTML 1.0 Strict web page:

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml"
xmlns:myml="htt p://www.mywords.com ">
<head>
<title />
</head>
<body>
<div xml:lang="fr">
<p>
Tu es <em>belle</em>.
</p>
</div>
</body>
</html>

Note that the opening html tag of this result includes a "xmlns:myml "
which I don't think I need. Is there any way to make sure that it
doesn't get into the result document?

I'm using Ant 1.6.2 to make the transformation (so Xalan 2.6.0?).
Thanks,

Greg.

Jul 20 '05 #9

copy-of copies the node with all its in scope namespaces, which you
don't want here, so instead do something like

<xsl:template match="myml:tra nslation">
<div>
<xsl:copy-of select="@xml:la ng"/>
<xsl:apply-templates mode="h"/>
</div>
</xsl:template>

<xsl:template mode="h">
<xsl:element name="{name()}" >
<xsl:copy-of select="@"/>
<xsl:apply-templates mode="h"/>
</xsl:element>
</xsl:template>

that stops the namespace nodes being copied from the source
and add

exclude-result-prefixes = "myml"

to your xsl:stylesheet to stop the myxml namespace nodes being copied
from the stylesheet.

David
Jul 20 '05 #10

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

Similar topics

6
2386
by: Mikko Nummelin | last post by:
As the XSLT namespace is declared to be used in XSL documents like this: <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"> , isn't this a risky practice as it refers to an external web site and if that web site is down at a particular time or is moved to another place, then even large web sites referring to...
4
1219
by: Trygve | last post by:
I'm trying to convert a XML-document using XSLT. Depending on the source file (the XML-document) the conversion is either correct or incorrect. If the first tag in the document contains an non empty xmlns attribute: <Meldekorttype xmlns="http://myhost.com/mk_print_meldekort.xsd"> <tag1>Value1</tag1> <tag2>Value2</tag2> </Meldekorttype>
1
3253
by: Rolf Kemper | last post by:
Dear Experts, I'm going to create an Excell spreadsheet xml. So far things work very well. But in case I add <Row> elements by a recursive template call it goes wrong. See the attached XSLT and the result. Last 30 lines of the xslt may be the most interesting ones. I'm processing it with XMLSPY. Regardless of the xslt processor (ALTOVA /...
3
10025
by: Mike Dickens | last post by:
hi, i'm sure this has come up before but havn't managed to find an answer. if i have the following xslt <?xml version="1.0" encoding="ISO-8859-1"?> <xsl:stylesheet method="xml" version="1.0" xmlns:ns1="abc" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"> <xsl:output indent="yes" media-type="text/xml" standalone="yes" version="1.0"/>...
1
1412
by: Howard | last post by:
Hi, I am using a very simple xslt file to get info from an xml document. The problem seems to me to be that the xml doc uses a namespace, and I don't know how to set up my xslt to recognize it correctly. If I remove the namespace specification from the xml, I can query the node I want perfectly. But with that namespace in there, it fails. ...
6
2561
by: Martin | last post by:
Hi, I have a xml file like the one below <?xml version="1.0" encoding="utf-8"?><e1 xmlns:e1="http://tempuri.org/Source1.xsd" e1:att1="1" e1:att2="2" e1:rest="345"/> If I try to create a schema for it with Visual Studio, I get the error "Failed to create a schema for this data file because:
2
6809
by: Rick | last post by:
I have an XML document that is generated from Infopath, I need to change the value of a namespace that is defined in a node in the form: <xsf:xDocumentClass "xmlns:my=valuehere">. when i navigate to the namespace value it is read only and cannot be changed. Can anyone tell me how to change this value? My Code: Dim sSingleNode As XmlNode...
1
1872
by: Rajesh | last post by:
I am trying to pass the namespace, which is in my Original Message, to a Java method for further processing. In the original message the xmlns:xenc namespace is present. I make a call to Java function and pass the whole XML message along with tags and values. In my Java function when I tried to print the XML message which is receieved by the...
4
4296
by: =?Utf-8?B?REZC?= | last post by:
Within an XSLT transformation, I'm trying to switch the default namespace within a section of the generated XML document to a shared namespace. This way, the content of this section does not have to use a prefix for the shared namespace, thus making the document smaller and easier to read. This worked in .NET 1.1 with no problem, but now...
4
4323
by: pc.candy | last post by:
Hi there I'm having some difficulty with transforming xml data with more than one namespace defined in the xml. I'm able to bring back some values of the xml but not others in another namespace? For example from the following xml data I can bring bring back the value for <addressbut I can't seem to figure out how to bring back the...
0
7347
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language...
0
7590
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. ...
0
7733
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that...
0
7684
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the...
0
5883
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then...
1
5264
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes...
0
3388
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 last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in...
1
1814
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 we have to send another system
1
963
muto222
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.