开发者

xslt namspace related to copying some elements

开发者 https://www.devze.com 2023-02-18 20:07 出处:网络
So, I have a stylesheet that spends most of its time transforming elements from \'namespace a\' to the xhtml namespace.

So, I have a stylesheet that spends most of its time transforming elements from 'namespace a' to the xhtml namespace.

In one particular case, however, I want to allow the input vocabulary to include any xhtml element. From a schema standpoint, I've added an <xs:any namespace="...."/> for the xhtml namespace.

It looks like:

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

The stylesheet uses xsl:copy-of to copy the children 开发者_高级运维of the passthrough element into the output.

Saxon-B, which I am using (last release), seems sort of stupid about the namespaces. Even though the target namespace of the entire output document is the xhtml namespace, the output looks like:

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

Note the pointless prefixes, instead of just putting out <div ...>. Note that the document element of the whole business ('html') defines xmlns="ttp://www.w3.org/1999/xhtml".

Is there any way to neaten this up?


Try whether doing <xsl:copy-of select="node()" copy-namespaces="no"/> helps (see http://www.w3.org/TR/xslt20/#copy-of). If not then please post complete samples of XML input, and XSLT stylesheet allowing us to reproduce the problem, your snippets so far do not explain where for instance the xmlns:xhtml="..." in the result snippet on the div element comes from.


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

The scope of a namespace declaration declaring a prefix extends from the beginning of the start-tag in which it appears to the end of the corresponding end-tag, excluding the scope of any inner declarations with the same NSAttName part. In the case of an empty tag, the scope is the tag itself.

For your case, it means that "http://www.basistech.com/2010/btml/" and "http://www.w3.org/1999/xhtml" namespace URIs bound to btml an xhtml prefixes are in scope for your div element unther "http://www.w3.org/1999/xhtml" default namespace.

Of course, as suggested by @Martin Honnen's answer xsl:copy-of/@copy-namespaces with "no" as value will strip in scope namespace not actually used (i.e. in this element or its attribute's names).

0

精彩评论

暂无评论...
验证码 换一张
取 消