XSLT stylesheet parameters in imported stylesheets

后端 未结 4 2132
爱一瞬间的悲伤
爱一瞬间的悲伤 2021-02-19 04:39

Is it possible to assign a value to a parameter of an imported stylesheet?

I was expecting something like


  

        
4条回答
  •  逝去的感伤
    2021-02-19 05:35

    A quick glance at the specs shows that no such construct is permitted:

    • XSLT 1.0: http://www.w3.org/TR/xslt#element-import
    • XSLT 2.0: http://www.w3.org/TR/xslt20/#element-import

    In short, href is the only allowed attribute and there is no content allowed in the element's body.

    However, if I understand your use case, then you should simply set the parameter in the normal way (using your host language). It shouldn't really matter that it was defined in the imported stylesheet. For example, assume you have this stylesheet:

    
        
        
            
        
    
    

    Which imports this:

    
        
    
    

    ...then setting the test parameter in the normal way should just work. Note that you can also "mask" the parameter from the imported sheet if you want to provide a new default value.

    So, adding this to the first stylesheet:

    
    

    ...would cause it to print default2 (overriding the default from the imported sheet).

提交回复
热议问题