[Top] [All Lists]

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

2020-03-03 09:54:16
On Tue, Mar 03, 2020 at 03:37:51PM -0000, Kerry, Richard 
richard(_dot_)kerry(_at_)atos(_dot_)net 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
XSL-List info and archive: http://www.mulberrytech.com/xsl/xsl-list
EasyUnsubscribe: http://lists.mulberrytech.com/unsub/xsl-list/1167547
or by email: xsl-list-unsub(_at_)lists(_dot_)mulberrytech(_dot_)com

<Prev in Thread] Current Thread [Next in Thread>