472,342 Members | 1,324 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 472,342 software developers and data experts.

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:stylesheet
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="script"
doctype-public="-//W3C//DTD XHTML 1.0 Transitional//EN"
doctype-system="http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"
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.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head><title>Whatever</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:stylesheet
version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns="http://www.w3.org/1999/xhtml"
xmlns:xhtml="http://www.w3.org/1999/xhtml"


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

<xsl:template match="xhtml:html">
<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.dtd">
<p xmlns="http://www.w3.org/1999/xhtml"
xmlns:xhtml="http://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 6566
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**********@gmx.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:stylesheet
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="script"
doctype-public="-//W3C//DTD XHTML 1.0 Transitional//EN"
doctype-system="http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"
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.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head><title>Whatever</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:stylesheet
version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns="http://www.w3.org/1999/xhtml"
xmlns:xhtml="http://www.w3.org/1999/xhtml"
>


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

<xsl:template match="xhtml:html">
<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.dtd">
<p xmlns="http://www.w3.org/1999/xhtml"
xmlns:xhtml="http://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:sometag">... . 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:sometag">... . 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:stylesheet
version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns="http://www.w3.org/1999/xhtml"
xmlns:xhtml="http://www.w3.org/1999/xhtml"


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

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

<xsl:template match="xhtml:html/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.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head><title>Whatever</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.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head><title xmlns:xhtml="http://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>Some 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:sometag">... . 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**********@gmx.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:stylesheet
version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns="http://www.w3.org/1999/xhtml"
xmlns:xhtml="http://www.w3.org/1999/xhtml"
>


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

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

<xsl:template match="xhtml:html/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.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head><title>Whatever</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.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head><title xmlns:xhtml="http://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>Some 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="http://www.mywords.com"
xmlns="http://www.w3.org/1999/xhtml">

<myml:translation xml:lang="fr">
<p>
Tu es <em>belle</em>.
</p>
</myml:translation>

</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:stylesheet
version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:myml="http://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="application/xhtml+xml"
/>

<xsl:template match="myml:thought">
<html>
<head>
<title></title>
</head>
<body>
<xsl:apply-templates select="myml:translation"/>
</body>
</html>
</xsl:template>

<xsl:template match="myml:translation">
<div>
<xsl:attribute name="xml:lang">
<xsl:value-of select="@xml:lang"/>
</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="http://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
> I have an unwanted "xmlns" attribute showing up in my otherwise-valid
XHTML result document from an XSLT transformation.

Hi,

it's actually quite simple:
just add the 'exclude-result-prefixes' attribute to the 'xsl:stylesheet' element:

<xsl:stylesheet exclude-result-prefixes="myml"/>

regards,
--
Joris Gillis (http://www.ticalc.org/cgi-bin/acct-v...i?userid=38041)
Spread the wiki (http://en.wikipedia.org)
Jul 20 '05 #10

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:translation">
<div>
<xsl:copy-of select="@xml:lang"/>
<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 #11

me: <xsl:template mode="h">

should be

<xsl:template mode="h" match="*">
^^^^^^^^
of course, sorry.
Jul 20 '05 #12
"Joris Gillis" <ro**@pandora.be> writes:
I have an unwanted "xmlns" attribute showing up in my otherwise-valid
XHTML result document from an XSLT transformation.

Hi,

it's actually quite simple:
just add the 'exclude-result-prefixes' attribute to the 'xsl:stylesheet' element:

<xsl:stylesheet exclude-result-prefixes="myml"/>

regards,

that stops namespaces escaping from the stylesheet, but not from being
copied from the source.

David
Jul 20 '05 #13
>> just add the 'exclude-result-prefixes' attribute to the 'xsl:stylesheet' element

that stops namespaces escaping from the stylesheet, but not from being
copied from the source.

Hi,

I'm not sure I understand that; it gives the desired output with me, but I'm probably not reading very well.. I have the nasty tendancy to skip just the essential parts of one's posting:-)
btw,
<xsl:element name="{name()}">
<xsl:copy-of select="@"/>
<xsl:apply-templates mode="h"/>
</xsl:element>

couldn't that be written as this way?
<xsl:copy>
<xsl:copy-of select="@*"/>
<xsl:apply-templates mode="h"/>
</xsl:copy>
regards,
--
Joris Gillis (http://www.ticalc.org/cgi-bin/acct-v...i?userid=38041)
Spread the wiki (http://en.wikipedia.org)
Jul 20 '05 #14
"Joris Gillis" <ro**@pandora.be> writes:
just add the 'exclude-result-prefixes' attribute to the 'xsl:stylesheet' element


that stops namespaces escaping from the stylesheet, but not from being
copied from the source.

Hi,

I'm not sure I understand that; it gives the desired output with me, but I'm probably not reading very well.. I have the nasty tendancy to skip just the essential parts of one's posting:-)
btw,
<xsl:element name="{name()}">
<xsl:copy-of select="@"/>
<xsl:apply-templates mode="h"/>
</xsl:element>

couldn't that be written as this way?
<xsl:copy>
<xsl:copy-of select="@*"/>
<xsl:apply-templates mode="h"/>
</xsl:copy>


no,xsl:copy, like xsl:copy-of copies namespace nodes as well as the
element.

David
Jul 20 '05 #15
>
Add

exclude-result-prefixes="xhtml"

as an attribute of xsl:stylesheet.
Right. Given that it's the "myml" prefix I want to exclude from the
result document, I've added . . .

exclude-result-prefixes="myml"

.. . . to the opening tag of my style sheet. See below:

<xsl:stylesheet
version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:myml="http://www.mywords.com"
xmlns="http://www.w3.org/1999/xhtml"
exclude-result-prefixes="myml"


The effect seems to be that the "myml" prefix does get excluded from
the result document, as a prefix. (I.e. it doesn't prefix anything in
the result document.) But the "http://www.mywords.com" namespace gets
added to the result document nonetheless (exactly as it is declared in
the source document, tied to the "myml" prefix) in any content that is
copied from the source document with the XSLT "copy-of".

The result now looks like this:

<?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 xmlns:myml="http://www.mywords.com">
Tu es <em>belle</em>.
</p>
</div>
</body>
</html>

Which, with a "p" element that has a "xmlns:myml" attribute, is still
not valid XHTML 1.0 Strict.
Hmmmmmm.

Any further ideas on how I can make this valid?

Thanks.

Jul 20 '05 #16
The effect seems to be that the "myml" prefix does get excluded from
the result document, as a prefix. (I.e. it doesn't prefix anything in
the result document.)
No, exclude-result-prefixes has no effect on wheneter any elements are
prefixed or not it stops any namespace node with namespace uRI
http://www.mywords.com being copied from the stylesheet uless it is
needed to generate an element or attribute name in that namespaace.

But the "http://www.mywords.com" namespace gets
added to the result document nonetheless

In that case namespace nodes from that namespace must have been copied
from the source tree (exclude-result-prefixes has _no_ effect on nodes
copied from the source) see earlier recursove template posted which can
be used to avoid copying namespace nodes.

David
Jul 20 '05 #17
In article <11**********************@z14g2000cwz.googlegroups .com>,
Greg <sa**********@hotmail.com> wrote:
But the "http://www.mywords.com" namespace gets
added to the result document nonetheless (exactly as it is declared in
the source document, tied to the "myml" prefix) in any content that is
copied from the source document with the XSLT "copy-of".


exclude-result-prefixes just stops namespace nodes being copied from
literal result elements in the stylesheet. The rationale is that you
may need to bind prefixes in the stylesheet just to address the source
document, when they have no relevance to the output.

But if you copy nodes from the source document that have namespace
bindings in scope, it's up to you to remove any that you don't want.
Since xsl:copy copies an element's namespace nodes, to get rid of them
you will have to *not* use xsl:copy for elements. You can instead use
a template that matches elements, and which creates an element with
the same namespace-uri and local-name. You may also want to copy the
namespace nodes except the myml: one, but you can probably get away
without doing this (because if they are required for element or
attribute names they will get inserted anyway).

-- Richard
Jul 20 '05 #18
I didn't see David's earlier post with the recursive template.

In my style sheet, I tried . . .

<xsl:template match="myml:translation">
<div>
<xsl:copy-of select="@xml:lang"/>
<xsl:apply-templates mode="h"/>
</div>
</xsl:template>

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

.. . . but Ant complained about the line:

<xsl:copy-of select="@"/>

Saying:

[xslt] Unknown file:39:38: Fatal Error! A node test that matches either
NCNam:* or QName was expected.

So I replaced the "@" with "attribute::*", and no complaints - just an
XHTML 1.0 Strict web page that is . . . valid! I have found peace and
oneness with the world again. Thankyou.

For the benefit of others find this thread and want to include XHTML in
their own namespace-using XML document and then transform that XML
document into valid XHTML . . .

The source XML document:

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

<myml:translation xml:lang="fr">
<p>
Tu es <em title="Hot!">belle</em>.
</p>
</myml:translation>

</myml:thought>
The XSLT style sheet:

<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet
version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns="http://www.w3.org/1999/xhtml"
xmlns:myml="http://www.mywords.com"
exclude-result-prefixes="myml"


<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="application/xhtml+xml"
/>

<xsl:template match="myml:thought">
<html>
<head>
<title>Thought</title>
</head>
<body>
<xsl:apply-templates select="myml:translation"/>
</body>
</html>
</xsl:template>

<xsl:template match="myml:translation">
<div>
<xsl:copy-of select="@xml:lang"/>
<xsl:apply-templates mode="h"/>
</div>
</xsl:template>

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

</xsl:stylesheet>
And the resulting document, transformed with Ant 1.6.2's "xslt" task:

<?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>Thought</title>
</head>
<body>
<div xml:lang="fr">
<p>
Tu es <em title="Hot!">belle</em>.
</p>
</div>
</body>
</html>

Valid according to http://validator.w3.org/
Thank you all. And thank you David for the recursive template.

Jul 20 '05 #19


me: <xsl:copy-of select="@"/>

oops sorry: do what I mean not what I write,
@* or as you say, attribute::* not just @

David

PS the xsl-list faq lists more or less the same thing here:

http://www.dpawson.co.uk/xsl/sect2/N...tml#d6408e1750
Jul 20 '05 #20
I didn't see David's earlier post with the recursive template.

In my style sheet, I tried . . .

<xsl:template match="myml:translation">
<div>
<xsl:copy-of select="@xml:lang"/>
<xsl:apply-templates mode="h"/>
</div>
</xsl:template>

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

.. . . but Ant complained about the line:

<xsl:copy-of select="@"/>

Saying:

[xslt] Unknown file:39:38: Fatal Error! A node test that matches either
NCNam:* or QName was expected.

So I replaced the "@" with "attribute::*", and no complaints - just an
XHTML 1.0 Strict web page that is . . . valid! I have found peace and
oneness with the world again. Thankyou.

For the benefit of others find this thread and want to include XHTML in
their own namespace-using XML document and then transform that XML
document into valid XHTML . . .

The source XML document:

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

<myml:translation xml:lang="fr">
<p>
Tu es <em title="Hot!">belle</em>.
</p>
</myml:translation>

</myml:thought>
The XSLT style sheet:

<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet
version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns="http://www.w3.org/1999/xhtml"
xmlns:myml="http://www.mywords.com"
exclude-result-prefixes="myml"


<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="application/xhtml+xml"
/>

<xsl:template match="myml:thought">
<html>
<head>
<title>Thought</title>
</head>
<body>
<xsl:apply-templates select="myml:translation"/>
</body>
</html>
</xsl:template>

<xsl:template match="myml:translation">
<div>
<xsl:copy-of select="@xml:lang"/>
<xsl:apply-templates mode="h"/>
</div>
</xsl:template>

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

</xsl:stylesheet>
And the resulting document, transformed with Ant 1.6.2's "xslt" task:

<?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>Thought</title>
</head>
<body>
<div xml:lang="fr">
<p>
Tu es <em title="Hot!">belle</em>.
</p>
</div>
</body>
</html>

Valid according to http://validator.w3.org/

Thank you all. And thank you David for the recursive template. Clever
trick.

(P.S. I would have done it with XHTML 1.1 instead of XHTML 1.0, but I
wrote the definition for my own XML document with XML Schema and,
afaik, there is no XML Schema document defining XHTML 1.1--just a
DTD--and I don't yet know how to validate an XML document against an
XML Schema for some (my) parts and also against a DTD for other (XHTML
1.1) parts. For XHTML 1.0 Strict, though, I have found an XML Schema
document (at http://www.w3.org/2002/08/xhtml/xhtml1-strict.xsd) so my
XML document can be validated against the two definitions (mine and
XHTML 1.0's) because both are XML Schema documents. But that is another
story, perhaps for another thread.)

Jul 20 '05 #21

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

Similar topics

6
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"...
4
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...
1
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...
3
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"...
1
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...
6
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"...
2
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:...
1
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...
4
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....
4
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...
0
by: Kemmylinns12 | last post by:
Blockchain technology has emerged as a transformative force in the business world, offering unprecedented opportunities for innovation and...
0
by: CD Tom | last post by:
This only shows up in access runtime. When a user select a report from my report menu when they close the report they get a menu I've called Add-ins...
0
by: Naresh1 | last post by:
What is WebLogic Admin Training? WebLogic Admin Training is a specialized program designed to equip individuals with the skills and knowledge...
0
jalbright99669
by: jalbright99669 | last post by:
Am having a bit of a time with URL Rewrite. I need to incorporate http to https redirect with a reverse proxy. I have the URL Rewrite rules made...
0
by: antdb | last post by:
Ⅰ. Advantage of AntDB: hyper-convergence + streaming processing engine In the overall architecture, a new "hyper-convergence" concept was...
0
by: Matthew3360 | last post by:
Hi there. I have been struggling to find out how to use a variable as my location in my header redirect function. Here is my code. ...
0
by: Arjunsri | last post by:
I have a Redshift database that I need to use as an import data source. I have configured the DSN connection using the server, port, database, and...
0
hi
by: WisdomUfot | last post by:
It's an interesting question you've got about how Gmail hides the HTTP referrer when a link in an email is clicked. While I don't have the specific...
0
by: Matthew3360 | last post by:
Hi, I have been trying to connect to a local host using php curl. But I am finding it hard to do this. I am doing the curl get request from my web...

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.