[Top] [All Lists]

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

2020-03-03 10:20:47
Ok, that's a possibility then.
If I understand it you mean I could do the search/filter as a completely 
separate action, storing the resultant list of files as a variable, then pass 
the list of files variable to apply-template.
I might try that.

Richard Kerry
BNCS Engineer, SI SOL Telco & Media Vertical Practice
M: +44 (0)7812 325518
2nd Floor, MidCity Place, 71 High Holborn, London, WC1V 6EA

This e-mail and the documents attached are confidential and intended solely for 
the addressee; it may also be privileged. If you receive this e-mail in error, 
please notify the sender immediately and destroy it. As its integrity cannot be 
secured on the Internet, the Atos group liability cannot be triggered for the 
message content. Although the sender endeavours to maintain a computer 
virus-free network, the sender does not warrant that this transmission is 
virus-free and will not be liable for any damages resulting from any virus 

From: Graydon graydon(_at_)marost(_dot_)ca 
Sent: 03 March 2020 15:54
To: xsl-list(_at_)lists(_dot_)mulberrytech(_dot_)com 
Subject: Re: [xsl] How do I pass the mode as a string?

Caution! Atos External email. Do not open attachments or click links, unless 
this email comes from a known sender and you know the content is safe.

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>