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.
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.
I know this post is old, but I want to share my opinion.
Each display could use one template instead of two. The value display will be change with a VB application.
breakfast_menu.xml
:In this file, I imported my displays and with a condition I tell the template what I need.
conditionDisplay.xsl
display1.xsl
:display2.xsl
:I genuinely apologize for my terrible English. It will be better to the next post and I hope will help someone as I think it's not the best solution.
No, the
<xsl:import>
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<xsl:import>
declaration before the transformation is invoked:Parse the xsl stylesheet as an XML file
Evaluate the condition that determines which stylesheet should be imported.
Set the value of the
href
attribute of the<xsl:import>
declaration to the URI of the dynamically determined stylesheet-to-be-imported.Invoke the transformation with the in-memory xsl stylesheet that was just modified.