XML to WordML using XSLT 1.0 - replace html tags within xml content with wordML formatting tags

前端 未结 4 605
[愿得一人]
[愿得一人] 2021-01-16 05:21

I am creating a WordML document from an xml file whose elements sometimes contain html-formatted text.


  
     html forma         


        
4条回答
  •  借酒劲吻你
    2021-01-16 05:39

    Working with WordML is tricky. One tip when converting arbitrary XML to WordML using XSLT is to not worry about the text runs when processing blocks, but to instead create a template that matches text() nodes directly, and create the text runs there. It turns out that Word doesn't care if you nest text runs, which makes the problem much easier to solve.

       
             
                
                   
                
              
       
    
       
           
       
    
       
          
             
          
       
    
       
          
             
                
             
             
          
       
    

    This avoids the bad XSLT technique of inserting tags directly as escaped text. You'll end up with the bold tag as a nested text run, but as I said, Word couldn't care less. If you use this technique, you'll need to be careful to not apply templates to the empty space between paragraphs, since it will trigger the text template and create an out-of-context run.

提交回复
热议问题