xslt命名空间与复制某些元素有关

时间:2011-03-22 16:02:27

标签: xslt-2.0 saxon

所以,我有一个样式表,大部分时间都将元素从'namespace a'转换为xhtml名称空间。

但是,在某个特定情况下,我希望允许输入词汇表包含任何xhtml元素。从架构的角度来看,我为xhtml命名空间添加了<xs:any namespace="...."/>

看起来像:

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

有没有办法解决这个问题?

2 个答案:

答案 0 :(得分:1)

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

答案 1 :(得分:0)

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

  

命名空间声明的范围   声明前缀从   它的开始标记的开头   似乎到了最后   相应的结束标记,不包括   任何内部声明的范围   相同的NSAttName部分。在这种情况下   空标记,范围是标记   本身。

对于您的情况,这意味着绑定到"http://www.basistech.com/2010/btml/""http://www.w3.org/1999/xhtml"前缀的btmlxhtml名称空间URI属于您的div元素的范围{ {1}}默认命名空间。

当然,正如@Martin Honnen answer "http://www.w3.org/1999/xhtml" xsl:copy-of/@copy-namespaces所建议的那样,值将在范围命名空间中实际使用(即在此元素中)或其属性的名称。)

相关问题