Preserving entity references when transforming XML with XSLT?

后端 未结 5 679
旧巷少年郎
旧巷少年郎 2020-11-30 15:06

How can I preserve entity references when transforming XML with XSLT (2.0)? With all of the processors I\'ve tried, the entity gets resolved by default. I can use xsl:

5条回答
  •  失恋的感觉
    2020-11-30 15:56

    If you know what entities will be used and how they are defined, you can do the following (quite primitive and error-prone, but still better than nothing):

    
     
    
     
      
     
    
     
    
     
    
     
      
       
      
     
    
     
      
     ]>
    ]]>
      
    
      
     
    
     
      
     
    
     
      
      
      
      
    
      
     
    
    

    when applied on the provided XML document:

    
     ]>
    
        Hello &so;!
        &question;
    
    

    the wanted result is produced:

    
     ]>
    
      
          Hello &so;!
          &question;
    
    

    Do note:

    1. The special (RegEx) characters in the replacements must be escaped.

    2. We needed to resolve to DOE, which isn't recommended, because it violates the principles of the XSLT architecture and processing model -- in other words this solution is a nasty hack.

提交回复
热议问题