Open eah13 opened 12 years ago
@eah13 - did you see this: http://stackoverflow.com/questions/4471992/how-to-import-stylesheets-in-xslt-conditionally Not really a solution (unless you are using XSLT 2.0?), but good to know there isn't an obvious one you're overlooking.
Thanks for this Hilmar. Good thinking.
Unfortunately, <<use-when>>
takes any XPath expression, but unfortunately it doesn't have access to a context, even in XSLT 2.0. I gave it a try anyways, adding
<xsl:import href="template.xsl" use-when="not(function-available('local:imported'))"/>
to study.xsl
, along with a blank function
<xsl:function name="local:imported"/>
to template.xsl
. It didn't work (i.e. template.xsl
was not imported to study.xsl
), because it couldn't access local:imported
. The expression would have to have access to context to see whether the function had been imported, and <<use-when>>
doesn't allow that (I assume this is for a good back-end reason in the language).
I'll keep looking, but it seems that an Oxygen parameter, if one exists, will be the best way to go. Other XSLT IDEs may also have solutions for this.
Maybe XSLT 3.0 will add context to <<use-when>>
one day. :)
Currently, many variables are defined in template.xsl. This stylesheet should only be imported once, in nexml-isatab.xsl. But for debugging assay.xsl, investigation.xsl, and study.xsl, it's convenient to have the template imported in each of these. Doing so multiple times throws up a distracting warning from SAXON, because it's bad practice (though in this case there's no consequences).
In my dev branches I will import templates.xsl in each stylesheet and then hopefully remember to remove them before committing to master.
A better solution would be to somehow conditionally import template.xsl, depending on whether it is already imported in the transformation.
Alternately, Oxygen likely has some sort of parameter to throw at the Transform config.