XSLT的命名空间问题 [英] namespace problem with XSLT

查看:76
本文介绍了XSLT的命名空间问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

嗨!


我在使用一些简单的愚蠢的XSLT时遇到了一些麻烦。


我的样式表:

-------------

<?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"

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>已插入< / p>

< / xsl:template>


< / xsl :stylesheet>

-------------

我的XML文档:

----- --------

<?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>

-------------


这种转变的结果是:

---- ---------

<?xml version =" 1.0" encoding =" iso-8859-1"?>

-------------



-------------

<?xml version =" 1.0" encoding =" iso-8859-1"?>


无论什么

-------------


显然结果应该是......喜欢<?xml ...>< p>已插入< / p>和$ / b $ b现在真正奇怪的事情:将样式表更改为:

------------

< ;?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="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>已插入< / p>

< / xsl:template>


< / xsl:stylesheet>

--------- ---

结果为:

------------

<?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">已插入< / p>

- -----------


为什么?为什么更改命名空间声明会改变

XSLT处理器的行为(尝试过Saxon(7.6.5)和Xalan(带Xerxes 2.3.0的1.6.0))

以这种方式?不应该匹配=sometag表示default-xmlns:sometag?


如果xmlns:xhtml-Namespace是必要的:有没有办法保持xslt-processors(撒克逊人)
或xalan)从插入未使用的,因此

不必要的命名空间声明干扰W3C XHTML

验证器?


提前致谢

Bernd Fuhrmann



<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

推荐答案

这是一个非常常见的问题。


请参阅:

http:/ /www.topxml.com/people/bosley/defaultns.asp

=====

干杯,


Dimitre Novatchev。
http://fxsl.sourceforge.net/ - FXSL的所在地

" Bernd Fuhrmann" < SI ********** @ gmx.de>在消息中写道

news:bl ************* @ news.t-online.com ...
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...
嗨!

我遇到一些简单的愚蠢的XSLT问题。

我的样式表:
-------------
<?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"
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>已插入< / p>
< / xsl:template>

< / xsl:stylesheet>
-------------
我的XML文档:
--------- ----
<?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>
-------------

这种转变的结果是:
-------------
<?xml version =" 1.0" encoding =" iso-8859-1"?>
-------------

----------- -
<?xml version =" 1.0" encoding =" iso-8859-1"?>

无论什么
-------------

显然结果应该是......喜欢<?xml ...>< p>已插入< / p>现在,对于真正奇怪的事情:将样式表更改为:
------------
<?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="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 ="脚本
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>已插入< / p>
< / xsl:template>

< / xsl:stylesheet>
--------- ---
结果:
------------
<?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">已插入< / p>
------------

为什么?为什么更改命名空间声明会以这种方式改变
XSLT处理器(尝试Saxon(7.6.5)和Xalan(1.6.0 with Xerxes 2.3.0))的行为?不应该匹配=sometag意味着default-xmlns:sometag?

如果xmlns:xhtml-Namespace是必要的:有没有办法让xslt-processors(saxon或xalan)不插入未使用的,因此
不必要的名称空间声明会干扰W3C XHTML
验证器吗?

提前致谢
Bernd Fuhrmann



<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



Dimitre Novatchev写道:
Dimitre Novatchev wrote:
参见:
http://www.topxml.com/people/bosley/defaultns.asp
阅读。然而,从阅读标准来看并不明显。至少我没有在XSLT / XPath / ... 1.0中找到任何关于这个问题的部分。

这是一个非常常见的问题。
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.




可能。到目前为止,我只阅读了一些例子,并自己完成了一些事情

。所以我必须写< xsl:template match =" xhtml:sometag"> ....但是

我怎么能避免在他们的DTD中破坏XHTML的验证时

Xalan和Saxon(也很可能是其他一些XSLT处理器)插入

他们的冗余xmlns:xhtml =" ..."在结果中?


再次提前感谢,

Bernd Fuhrmann



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


>所以我必须写< xsl:template match =" xhtml:sometag"> ....但是
> So I must write <xsl:template match="xhtml:sometag">... . But
当Xalan和Saxon(以及其他一些其他XSLT处理器)插入多余的xmlns时,我怎么能避免破坏XHTML的DTD验证:xhtml =" ..."在结果?
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?



你能举个例子吗?

=====

干杯,


Dimitre Novatchev。
http://fxsl.sourceforge.net / - FXSL的主页


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

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


这篇关于XSLT的命名空间问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆