How to avoid all namespace occurrence in output by writing a single statement in XSLT

前端 未结 4 1286
忘了有多久
忘了有多久 2021-02-20 04:09

I wrote \"exclude-result-prefixes\" and even then I see the name space occurrence appearance in output.



        
4条回答
  •  醉话见心
    2021-02-20 04:21

    The exclude-result-prefixes attribute of xsl:stylesheet, when specified as "yes" mandates the removal of any namespace nodes of a litreral result element (only) that are inherited and don't define both the namespace-uri and prefix of the literal result element.

    The following statement in the answer by Markus Jarderot is wrong:

    "exclude-result-prefixes just removes the xmlns:foo="" attributes on the root tag of the result."

    Here is a counter-example:

    
     
     
    
     
      
       
      
     
    
    

    When this transformation is applied on any XML document (not used), the result is:

    
       
    
    

    We see that:

    1. The namespace node (and definition) for the namespace with value (namespace-uri) "z:z" is not removed from the top element (what Markus Jarderot calls "root tag").

    2. The namespace with prefix "z" isn't removed from any literal element at all.

    That shows the simple fact that specifying exclude-result-prefixes="yes" cannot remove a namespace if it isn't on an LRE (Literal Result Element) and even if a namespace node is on an LRE but is defining the namespace to which the element belongs.

    In order to remove an element from the namespace it belongs to, or remove namespaces from non-LRE elements, we need to specify some additional processing.

    One example is a replacement of the traditional identity rule with the following:

    
     
     
    
     
         
           
         
     
    
     
      
       
      
     
    
     
      
       
      
     
    
    

    The above transformation replaces any element or attribute with a corresponding element or attribute that belongs to "no namespace". One potential use for it is to convert a document with a default namespace to a document without such.

    For example, when applied on the following source XML document:

    
        
    
    

    the result of the transformation is:

    
       
    
    

    Finally a warning:

    This transformation may be harmful if applied on documents that contains two elements (or two attributes) that have the same local name but belong to two different namespaces -- the transformation replaces these with elements (or attributes) that both belong to the same namespace (no namespace).

提交回复
热议问题