Condition in XSLT 1.0?

前端 未结 3 1575
半阙折子戏
半阙折子戏 2021-01-19 08:14

I have an XSLT 1.0 (2.0 is not an option) stylesheet which produces XHTML. It can, depending on a parameter, produce a full XHTML validable document or just a

3条回答
  •  自闭症患者
    2021-01-19 08:22

    Another option, which I recently had to employ, is to:

    1. Omit the XML declaration in all cases.
    2. Conditionally, output the declaration as unescaped text.

    This only works in XSLT 1.0 and 2.0 if you're outputting to a file -- this won't work if you need to process the output as XML in the same pass, such as when storing in a variable.

    (Note that XSLT 2.0 extension functions might make it possible to take this output and treat it as XML in one go, and XSLT 3.0 has a built-in function to parse an input string as XML.)

    Example snippet:

    
    
    
    
    
        
            
                <?xml version="1.0" encoding="UTF-8"?>
            
            
                <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
            
            
                
            
        
        
        
    
    
    
    ... [ other code ] ...
    

提交回复
热议问题