0

因此,我有一个样式表,它大部分时间都在将元素从“命名空间 a”转换为 xhtml 命名空间。

然而,在一种特殊情况下,我希望允许输入词汇表包含任何 xhtml 元素。从模式的角度来看,我<xs:any namespace="...."/>为 xhtml 命名空间添加了一个。

看起来像:

<btml:html-noscript xmlns="http://www.w3.org/1999/xhtml">
    <div style="display:inline;">
        <img height="1" 
             width="1" 
             style="border-style:none;" 
             alt="" 
             src="http://www.googleadservices.com/pagead/conversion/1070015830/?label=FoKlCKDxiAIQ1sqc_gM&amp;guid=ON&amp;script=0"/>
    </div>
</btml:html-noscript>

样式表用于xsl:copy-of将 passthrough 元素的子元素复制到输出中。

我正在使用的 Saxon-B(最新版本)似乎对命名空间有点愚蠢。尽管整个输出文档的目标命名空间是 xhtml 命名空间,但输出看起来像:

<noscript>
    <div xmlns:btml="http://www.basistech.com/2010/btml/"
         xmlns:xhtml="http://www.w3.org/1999/xhtml"
         style="display:inline;">
    <img height="1" 
              width="1" 
              style="border-style:none;" 
              alt="" 
              src="http://www.googleadservices.com/pagead/conversion/1070015830/?label=FoKlCKDxiAIQ1sqc_gM&amp;guid=ON&amp;script=0"></img>
    </div>
</noscript>

注意无意义的前缀,而不是仅仅放出<div ...>. 请注意,整个业务的文档元素 ('html') 定义了xmlns="ttp://www.w3.org/1999/xhtml".

有什么办法可以整理一下吗?

4

2 回答 2

1

尝试做是否有<xsl:copy-of select="node()" copy-namespaces="no"/>帮助(请参阅http://www.w3.org/TR/xslt20/#copy-of)。如果没有,那么请发布完整的 XML 输入示例,以及允许我们重现问题的 XSLT 样式表,到目前为止,您的代码段没有解释例如元素xmlns:xhtml="..."结果代码段中的div来源。

于 2011-03-22T17:13:34.693 回答
0

来自http://www.w3.org/TR/xml-names/#scoping

声明前缀的命名空间声明的范围从它出现的开始标记的开头延伸到相应的结束标记的结尾,不包括具有相同 NSAttName 部分的任何内部声明的范围。在空标签的情况下,范围是标签本身。

对于您的情况,这意味着绑定到前缀的命名空间 URI 在您的元素的范围内,而"http://www.basistech.com/2010/btml/" 不是"http://www.w3.org/1999/xhtml"默认命名空间。btmlxhtmldiv"http://www.w3.org/1999/xhtml"

当然,正如@Martin Honnen's answer xsl:copy-of/@copy-namespaces with as value 所建议的那样,将在未实际使用"no"的范围命名空间中剥离(即在此元素或其属性的名称中)。

于 2011-03-22T21:34:27.890 回答