tags:

views:

140

answers:

3

Is there a way to apply import for a particular imported file and not all the files imported?

Basically only want to do apply import for a certain import based on some value evaluated.

For example in pseudo,

If value = "Medical" then Do Medical Imported File apply imports Else If value = "Transport" Then Do Transport Imported File apply Imports

Cheers

+1  A: 

For XSLT 1.0 the answer is negative. However you may use modes to simulate similar behavior.

In XSLT 2.0 there is the xsl:use-when attribute that may be present on any XSLT instruction, including <xsl:import>, however the conditions that may be tested in it are severely limited. To quote the Spec:

"There are no syntactic constraints on the XPath expression that can be used as the value of the use-when attribute. However, there are severe constraints on the information provided in its evaluation context. These constraints are designed to ensure that the expression can be evaluated at the earliest possible stage of stylesheet processing, without any dependency on information contained in the stylesheet itself or in any source document"

Dimitre Novatchev
Maybe I'm not understanding the question right. Wouldn't the templates themselves decide which elements they they run on, even if they come from an imported stylesheet? So in 1.0, couldn't I just say <xsl:template match="element[@value='medical']"> to denote a template designed for medical elements?
Tomalak
@Tomalak The templates from imported stylesheets will first have to be selected by the XSLT processor. There is a strict process defined for this based on the so called "import precedence" of any imported stylesheet. There may be several matching templates in more than one imported stylesheets.
Dimitre Novatchev
OIC where my logic went wrong. The OP is not thinking "@value", but "$value". So it's not a property of the input, but rather a parameter or variable meant to control the output. D'oh.
Tomalak
A: 

I think that maybe using a mode on apply-imports would help you out? But if you want to indicate templates from a specific source, you could maybe do this using modes.

Teun D
A: 

Solved - Instead of doing apply import used include and call template and allow the include files dictate whether to process or not.

c00ke