Using dynamic href in XSLT import/include?

后端 未结 2 1789
醉酒成梦
醉酒成梦 2021-01-23 03:59

The and elements seem to behave quite specific. What I am trying to do:



        
相关标签:
2条回答
  • 2021-01-23 04:44

    What I am trying to do:

    <xsl:import href="{$base}/themes/{/settings/active_theme}/styles.xsl" />
    

    This isn't allowed in any version (1.0, 2.0, or 3.0) of XSLT.

    In XSLT 2.0 (and up) one may use the use-when attribute, but the conditions that may be specified are very limited.

    One non-XSLT solution is to load the importing XSLT stylesheet as an XmlDocument and use the DOM API to set href attribute to the really wanted value -- only then invoke the transformation.

    0 讨论(0)
  • 2021-01-23 04:47

    xsl:import assembles the stylesheet prior to execution. The stylesheet can't modify itself while it is executing, which is what you are trying to achieve.

    If you have three variants of a stylesheet for use in different circumstances, represented by three modules A.xsl, B.xsl, and C.xsl, then instead of trying to import one of these into the module common.xsl that contains all the common code, you need to invert the structure: each of A.xsl, B.xsl, and C.xsl should import common.xsl, and you should select A.xsl, B.xsl, or C.xsl as the principal stylesheet module when initiating the transformation.

    0 讨论(0)
提交回复
热议问题