How to Import stylesheets in xslt conditionally?

前端 未结 2 839
遥遥无期
遥遥无期 2021-01-19 00:37

Is there any way to import stylesheets after checking some conditions?

Like,if the value of variable $a=\"1\" then import 1.xsl or else import 2.xsl.

2条回答
  •  有刺的猬
    2021-01-19 01:27

    Hi All, Is there any way to import stylesheets after checking some conditions?

    Like,if the value of variable $a="1" then import 1.xsl or else import 2.xsl.

    No, the directive is only compile-time.

    In XSLT 2.0 one can use the use-when attribute for a limited conditional compilation.

    For example:

    
    

    The limitations of the use-when attribute are that there is no dynamic context when the attribute is evaluated -- in particular that means that there are no in-scope variables defined.

    A non-XSLT solution is to dynamically change the href attribute of the declaration before the transformation is invoked:

    1. Parse the xsl stylesheet as an XML file

    2. Evaluate the condition that determines which stylesheet should be imported.

    3. Set the value of the href attribute of the declaration to the URI of the dynamically determined stylesheet-to-be-imported.

    4. Invoke the transformation with the in-memory xsl stylesheet that was just modified.

提交回复
热议问题