Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Conditionally <xsl:import> for dev convenience #1

Open
eah13 opened this issue Jul 18, 2012 · 2 comments
Open

Conditionally <xsl:import> for dev convenience #1

eah13 opened this issue Jul 18, 2012 · 2 comments

Comments

@eah13
Copy link
Contributor

eah13 commented Jul 18, 2012

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.

@hlapp
Copy link
Contributor

hlapp commented Jul 18, 2012

@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.

@eah13
Copy link
Contributor Author

eah13 commented Jul 19, 2012

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. :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants