Re: [xsl] How do I pass the mode as a string?

Subject: Re: [xsl] How do I pass the mode as a string?
From: "Graydon graydon@xxxxxxxxx" <xsl-list-service@xxxxxxxxxxxxxxxxxxxxxx>
Date: Tue, 3 Mar 2020 15:54:12 -0000
On Tue, Mar 03, 2020 at 03:37:51PM -0000, Kerry, Richard richard.kerry@xxxxxxxx scripsit:
> What I am actually trying to do is to get a number of XML files processed.  The files are in similar folders, called 'input' and 'output'.  The files' names follow a couple of name patterns, acq_(\d{4}) and out_(\d{4}). There is identical code to scan through the folders and identify the files I want to process (and extract the numbers from the filenames).  They are then passed to apply-templates with the different modes as mentioned.
> So the file scanning, while not especially complicated, is not entirely trivial and I'd like to have it written just once.  And then, because the contents of the files differs in structure, they are handled by different templates, with different modes.

If you have a sequence of document nodes in a variable, $inputFiles,

<xsl:apply-templates mode="AsAppropriate"
select="$inputFiles[local:selectFunction(.)]" />

will let you filter $inputFiles on the basis of your locally
defined selectFunction returning true or false. (or some other
predicate; you might not even need to define a function,
could be all you need.)

You can do this sequentially in the main template with repeated
apply-templates using different select functions in the predicates.

At least with Saxon, this kind of pattern is reasonably efficient.

-- Graydon

Current Thread