how to fill text templates using xslt

后端 未结 4 830
梦如初夏
梦如初夏 2020-12-19 23:29

I have an XML file with information, for example:


  Test
  20
  Me
         


        
4条回答
  •  醉酒成梦
    2020-12-19 23:45

    One possible solution would be to change your template file to be an XML configuration, like this:

    
    
    

    Assuming that the above XML template is named template.xml and in the same directory as the XSLT below:

    
    
    
    
    
    
        
        
    
        
    
        
    
    
     
    
        
        
        
        
    
    
    
        
            
                
            
        
    
    
    

    When the XSLT is run against the sample XML file, it produces the following output:

    Dear Test,
    
    some text with other variables like 20 or Test again
    
    greatings Me
    

    As @Tomalak pointed out, unmatched placeholder elements would be removed from the output. If you wanted to preserve them, to make it apparent that the XML file did not have a match for placeholder items in the template, you could change the template that matches on the template placeholder elements like this:

     
    
        
        
        
        
        
            
                
            
            
                $
                
            
        
    
    

    If there was an unmatched placeholder element, for example, then it would appear in the text output as $foo.

提交回复
热议问题