How to preserve XML namespace in XSLT output?

后端 未结 2 1639
失恋的感觉
失恋的感觉 2021-01-23 06:45

XSL stylesheet should output following code to Internet Explorer:


Bu

2条回答
  •  伪装坚强ぢ
    2021-01-23 07:22

    If you literally want the result as shown in the question, this is very simple to achieve:

    
     
    
     
      
     
    
    

    This transformation, when applied on any XML document (not used), produces the wanted result:

    
    

    However, it seems to me that you want to add a namespace node to every element of a given XML document (if this isn't so, just let me know via a commentand I'll delete this answer).

    If so, here is a simple and efficient way:

    
        
        
    
        
    
     
         
           
         
     
    
     
         
           
           
         
     
    
    

    when applied to any document, for example this one:

    
        
            
        
    
    

    the wanted result is produced:

    
       
          
       
    
    

    This may be confusing at first sight as only the top element of the result visibly has the desired namespace node. However, by definition (look at the XML Namespace spec) if an element at the root of a (sub) tree has a given namespace node, then all of its descendent elements also have this namespace node. Even if you copy the namespace to every element, the XSLT serializer will strip it off from the serialized (text) representation of all but the top element.

    In XSLT 2.0 you may simply use the instruction:

    
    

提交回复
热议问题