XSLT transform with source containing < and>

前端 未结 1 1549
无人及你
无人及你 2021-01-22 08:50

I have an input XML in the format below:


   msoft, Version=5.0, Culture=neutral, PublicKeyToken=null
            


        
1条回答
  •  遇见更好的自我
    2021-01-22 09:26

    I'll work with the example you provided, and assume it is well-formed. For that I added four extra lines to your source, which is now:

    
        msoft, Version=5.0, Culture=neutral, PublicKeyToken=null
        BT
        ?
        
            <AppData xmlns="http://tempuri.org/AppData.xsd">
              <Readers>
                <Id>1234</Id>
                <Port>6500</Port>
                <Type>M200</Type>
                <Active>Yes</Active>
              </Readers>
              <Readers>
              </Readers>
            </AppData>
        
    
    

    You will need either an XSLT 2.0 processor or an XSLT 1.0 extension. Here is a solution using XSLT 2.0:

    
    
        
        
            
            
        
    
        
    
        
            
                
            
        
        
            
                
            
            
        
    
        
                
                    
                    
                    
                    
                
        
    
    

    It actually processes your data twice. The angle-brackets inside the contents of Configuration are converted using the character-map. The result is placed inside a variable $input which is converted to a node using the document() function.

    Since your data is in a namespace, it's necessary to prefix the XPath expressions with it. The namespace declaration was removed from the result using exclude-result-prefixes="tempuri".

    0 讨论(0)
提交回复
热议问题