I would like to have an xsl:include/import that will satisfy 2 requirements
- Error safe: e.g. if the template doesn’t exist, do nothing
- Dynamic: e.g. the value of the included XSL is an value in the XML
e.g.
<xsl:import href="<xsl:value-of select='/root/@additionalFormattingXSL' />.xsl"/>
Is any way to get some or all of the above requirements? (no Java allowed) in any existing XSLT version?
One way to do it is to perform the input yourself using an additional XSL stylesheet. This import-processing stylesheet takes your original stylesheet as input, and outputs an expanded stylesheet that contains the original one plus all the successfully imported stylesheets.
That way, you have complete control over requirements 1 and 2. Regarding requirement 1, you can use doc-available() in your import-processing stylesheet.
FYI, in general the way to incorporate dynamic values into an attribute value is to use an Attribute Value Template, e.g.
However this only works on attributes that are designated as AVTs, such as an attribute of a literal result element. I’m pretty sure this is not the case for the
hrefattribute of<xsl:import>.