排除对结果的前缀 [英] exclude-result-prefixes

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

问题描述

我正在努力理解''排除结果前缀''的作用,并且

for;标准的语言
http://www.zvon.org/xxl/XSLTreferenc...result-element


并不容易理解。我认为它应该做的是标记

特定的前缀,因为不能在生成的文档中打印,但是

不适用于任何XSL工具我我目前正在与(Xalan

1.2.2和2.7.0,xsltproc 1.1.19)合作。具体来说,以下样式表:


<?xml version =" 1.0" encoding =" UTF-8"?>

< xsl:stylesheet version =" 1.0"

xmlns:xsl =" http:// www .w3.org / 1999 / XSL / Transform"

xmlns:xhtml =" http://www.w3.org/1999/xhtml"

exclude-result -prefixes =" xhtml">


< xsl:output indent =" yes" method =" html"

doctype-public =" - // W3C // DTD XHTML 1.0 Transitional // EN"

doctype-system =" http: //www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"/>


< xsl:template match =" xhtml:html">

< xhtml:html>< xhtml:body> Hello world!< / xhtml:body>< / xhtml:html>

< / xsl:模板>


< xsl:template match =" *">

<! - nothing - >

< / xsl:template>

< / xsl:stylesheet>


生成


<!DOCTYPE html PUBLIC" - // W3C // DTD XHTML 1.0

Transitional // EN" http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

< xhtml:html xmlns:xhtml =" http:// www .w3.org / 1999 / xhtml">

< xhtml:body> Hello world!< / xhtml:body>

< / xhtml:html>

来自任何HTML页面的
使用我可以访问的任何当前XSL处理器。


我解决此问题的具体原因是


(1)较早的浏览器barf在''xhtml:html''和其他类似的标记名;并且

(2)W3C验证器barf''xmlns''


总而言之,如果有人能教育我什么

排除结果前缀真的应该做(以及为什么),而且,除了

之外,我怎么能做我认为它应该做的事情,我'' d真的很好

感激不尽。

-
si *** @ jasmine.org.uk (Simon Brooke) http:// www.jasmine.org.uk/~simon/

;;如果上帝不写LISP,上帝写的代码与

相似; LISP没有任何区别。

I''m struggling to understand what ''exclude-result-prefixes'' does and is
for; the language of the standard

http://www.zvon.org/xxl/XSLTreferenc...result-element

is not exactly easy to follow. What I assumed it was supposed to do is mark
specific prefixes as not to be printed in the generated document, but that
does not work with any of the XSL tools I''m currently working with (Xalan
1.2.2 and 2.7.0, xsltproc 1.1.19). Specifically, the following stylesheet:

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

<xsl:output indent="yes" method="html"
doctype-public="-//W3C//DTD XHTML 1.0 Transitional//EN"
doctype-system="http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"/>

<xsl:template match="xhtml:html">
<xhtml:html><xhtml:body>Hello world!</xhtml:body></xhtml:html>
</xsl:template>

<xsl:template match="*">
<!-- nothing -->
</xsl:template>
</xsl:stylesheet>

generates

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0
Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<xhtml:html xmlns:xhtml="http://www.w3.org/1999/xhtml">
<xhtml:body>Hello world!</xhtml:body>
</xhtml:html>

from any HTML page using any current XSL processor that I have access to.

The specific reason I attacking this problem is that

(1) Older browsers barf at ''xhtml:html'' and other such tagnames; and
(2) The W3C validator barfs at ''xmlns''

So, in summary, if anyone could educate me as to what
exclude-result-prefixes is really supposed to do (and why), and, as an
aside, how I can do what I thought it was meant to do, I''d be really
grateful.
--
si***@jasmine.org.uk (Simon Brooke) http://www.jasmine.org.uk/~simon/
;; If God does not write LISP, God writes some code so similar to
;; LISP as to make no difference.

推荐答案

Simon Brooke写道:
Simon Brooke wrote:

所以,总之,如果有人能够教育我什么

排除结果前缀真的应该做(以及为什么),并且,作为一个

,我怎么样可以做我认为应该做的事情,我真的会感激不尽。
感激不尽。
So, in summary, if anyone could educate me as to what
exclude-result-prefixes is really supposed to do (and why), and, as an
aside, how I can do what I thought it was meant to do, I''d be really
grateful.



对于您的XSLT匹配模式和/或XPath表达式,您经常需要

声明绑定到名称空间URI的前缀以在匹配中使用这些前缀

模式和/或XPath表达式虽然你可能不需要/需要这个

前缀在结果文档中,因为你没有任何结果元素

在那些名称空间中。在那种情况下,exclude-result-prefixes会有帮助,它会阻止结果文档中的名称空间声明,但只有在这些名称空间中没有结果元素时才会这样做。


在您的示例中,您在XHTML命名空间中有结果元素
http://www.w3.org/1999/xhtml ,在这种情况下,XSLT处理器不能

排除前缀,因为结果文档不是这样的更长的

带有名称空间的格式良好的XML。


你可以做的是例如


< xsl: stylesheet version =" 1.0"

xmlns:xsl =" http://www.w3.org/1999/XSL/Transform"

xmlns:xhtml = http://www.w3.org/1999/xhtml"

xmlns =" http://www.w3.org/1999/xhtml"

exclude-result-prefixes =" xhtml">


< xsl:output indent =" yes" method =" html"

doctype-public =" - // W3C // DTD XHTML 1.0 Transitional // EN"

doctype-system =" http: //www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"/>


< xsl:template match =" xhtml:html">

< html>< body> Hello world!< / body>< / html>

< / xsl:template>


这样你的结果元素应该在默认的

命名空间中序列化,例如

< html xmlns =" http://www.w3。 org / 1999 / xhtml">

,因为XHTML 1.0 DTD想要它。


-


Martin Honnen
http://JavaScript.FAQTs.com/

For your XSLT match patterns and/or XPath expressions you often need to
declare prefixes bound to namespace URIs to use those prefixes in match
patterns and/or XPath expressions while you might not want/need this
prefixes in the result document as you do not have any result elements
in those namespaces. In that case exclude-result-prefixes helps, it
prevents the namespace declaration in the result document, but only if
there are no result elements in those namespaces.

In your example you however have result elements in the XHTML namespace
http://www.w3.org/1999/xhtml and in that case the XSLT processor cannot
exlude the prefix as that way the result document were no longer
well-formed XML with namespaces.

What you could do is e.g.

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

<xsl:output indent="yes" method="html"
doctype-public="-//W3C//DTD XHTML 1.0 Transitional//EN"
doctype-system="http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"/>

<xsl:template match="xhtml:html">
<html><body>Hello world!</body></html>
</xsl:template>

that way your result elements should be serialized in the default
namespace e.g.
<html xmlns="http://www.w3.org/1999/xhtml">
as the XHTML 1.0 DTD wants it.

--

Martin Honnen
http://JavaScript.FAQTs.com/


Simon Brooke< si *** @ jasmine.org.ukwrites:
Simon Brooke <si***@jasmine.org.ukwrites:

我很难理解什么''排除结果前缀''做什么,并且是/ b $ b for;标准的语言
http://www.zvon.org/xxl/XSLTreferenc...result-element



(BTW,rec。也可通过 www.w3c.org


目的exclude-result-prefixes是为了避免输出

名称空间声明(xmlns:blah伪属性),它们出现在源文档的

中,但_never_出现在结果中文献。它是
意味着如果一个命名空间(如你的例子中的XHTML命名空间)

在结果文档中使用,它将在输出中声明

(因为它必须),无论exclude-result-prefixes的值是什么。

这是你观察到的,因为你在输出中使用了XHTML ns。


(原因是,如果你在

xsl:stylesheet元素中声明一个命名空间,所有文字结果元素都在范围内

命名空间声明的b,所以即使你没有使用那个命名空间,也会输出相应的命名空间

声明(可能)。

(BTW, the rec. is also available via www.w3c.org)

The purpose of exclude-result-prefixes is to avoid the output of
namespace declarations (xmlns:blah pseudo-attributes) that appear in
the source document but _never_ appear in the result document. It
means that if a namespace (like the XHTML namespace in your example)
is used in the result document, it will be declared in the output
(because it has to), whatever the value of exclude-result-prefixes is.
This is what you observe, since you use the XHTML ns in the output.

(The reason for this is that, if you declare a namespace in your
xsl:stylesheet element, all literal result elements are in the scope
of the namespace declaration, so a corresponding namespace
declaration is (may be) output, even if you do not use that namespace.)


< xsl:output indent =" yes" method =" html"

doctype-public =" - // W3C // DTD XHTML 1.0 Transitional // EN"

doctype-system =" http: //www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"/>


< xsl:template match =" xhtml:html">

< xhtml:html>< xhtml:body> Hello world!< / xhtml:body>< / xhtml:html>

< / xsl:模板>
<xsl:output indent="yes" method="html"
doctype-public="-//W3C//DTD XHTML 1.0 Transitional//EN"
doctype-system="http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"/>

<xsl:template match="xhtml:html">
<xhtml:html><xhtml:body>Hello world!</xhtml:body></xhtml:html>
</xsl:template>



这没有多大意义。您要求HTML输出,但提供仅限名称空间限定的XML文字输出

。 XSLT rec。指定

HTML输出方法不应该从xml输出方法输出不同的元素

,除非元素的扩展名称具有

a null namespace URI;扩展名具有非空的
名称空间URI的元素应该作为XML输出 (第16.2节)。这意味着您的

HTML输出请求被忽略,因为您的结果元素是

名称空间限定(我在谈论< xhtml:htmlelement,_not_

xhtml:html匹配模式。)


如果您需要HTML输出,为了符合浏览器要求,请使用

HTML输出方法和文本结果元素位于null

命名空间中(即,没有名称空间前缀,并且这样

< xsl:stylesheetdoesn''t声明默认名称空间)。如果您的

样式表输出多余的名称空间声明,请将那个

名称空间的前缀添加到exclude-result-prefixes。另外,更改

公共和系统ID以指向HTML(没有X)。


- Alain。

This doesn''t make much sense. You ask for HTML output, but provide
only namespace-qualified XML literal output. The XSLT rec. specifies
that the HTML output method "should not output an element differently
from the xml output method unless the expanded-name of the element has
a null namespace URI; an element whose expanded-name has a non-null
namespace URI should be output as XML" (sec 16.2). That means your
HTML-output request is ignored, because your result elements are
namespace-qualified (I''m talking about the <xhtml:htmlelement, _not_
the "xhtml:html" match pattern.)

If you need HTML output, to comply with browser requirements, use the
HTML output method and literal result elements that are in the null
namespace (i.e., have no namespace prefix, and such that
<xsl:stylesheetdoesn''t declare a default namespace). If your
stylesheet outputs superfluous namespace declarations, add that
namespaces'' prefixes to exclude-result-prefixes. Also, change the
public and system ids to point to HTML (no X).

-- Alain.

< br>

文章< 41 ************ @ gododdin.internal.jasmine.org.uk>,

Simon Brooke< si * **@jasmine.org.ukwrote:
In article <41************@gododdin.internal.jasmine.org.uk >,
Simon Brooke <si***@jasmine.org.ukwrote:

>总而言之,如果有人能够教育我什么
exclude-result-prefixes是真的应该做(以及为什么),而且,作为一个
,除了我怎么能做我认为它应该做的事情,我真的很感激。
>So, in summary, if anyone could educate me as to what
exclude-result-prefixes is really supposed to do (and why), and, as an
aside, how I can do what I thought it was meant to do, I''d be really
grateful.



尽管名称不同,但排除结果前缀指定*名称空间*用于

不需要前缀,而不是表达您选择的

前缀。它通过列出绑定到这些名称空间的前缀来实现这一点,

解释了名称。


有利于避免名称空间的前缀声明

在输出文档中没有使用。如果你的样式表声明了一个

前缀xmlns:foo =" http://example.org"要从该命名空间中的

源文档中访问元素,但是你的输出文件

没有来自该命名空间的任何内容,那么你可以使用

排除结果前缀以避免虚假声明(否则可能会出现
,因为

样式表中的任何文字结果元素都会有它范围内。


根据您的要求:

Despite its name, exclude-result-prefixes specifies *namespaces* for
which prefixes are not needed, rather than expressing your choice of
prefixes. It does this by listing prefixes bound to those namespaces,
which explains the name.

What it''s good for is avoiding prefix declarations for namespaces that
aren''t used in the output document. If your stylesheet declares a
prefix xmlns:foo="http://example.org" to access elements from the
source document which are in that namespace, but your output document
doesn''t have anything from that namespace, then you can use
exclude-result-prefixes to avoid the spurious declaration (which would
otherwise be likely to appear because any literal result elements in the
stylesheet would have it in-scope).

As to your requirements:


(1)旧版浏览器barf at''xhtml:html ''和其他类似的标记名;并且

(2)W3C验证器barf在''xmlns''
(1) Older browsers barf at ''xhtml:html'' and other such tagnames; and
(2) The W3C validator barfs at ''xmlns''



我很惊讶(2)。但是,DTD将html

元素声明为


<!ELEMENT html(head,body)>

< ;!ATTLIST html

%i18n;

id ID #IMPLIED

xmlns%URI; #FIXED''http://www.w3.org/1999/xhtml''

I''m very surprised by (2). However, the DTD declares the html
element as

<!ELEMENT html (head, body)>
<!ATTLIST html
%i18n;
id ID #IMPLIED
xmlns %URI; #FIXED ''http://www.w3.org/1999/xhtml''


>
>



因此它应该可以生成没有命名空间的输出,并且DTD中的FIXED

属性将使它在使用xhtml命名空间时这是

再次读回来。


- Richard

-

应考虑在一些字母表中需要多达32个字符

- 1963年的X3.4。

so it should work to generate output with no namespaces, and the FIXED
attribute in the DTD will make it use the xhtml namespace when it''s
read back in again.

-- Richard
--
"Consideration shall be given to the need for as many as 32 characters
in some alphabets" - X3.4, 1963.


这篇关于排除对结果的前缀的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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