Ok,
Thanks all for the explanations. I'll look at the alternatives.
If this was C++, which is what I use most of the time (XSL is infrequent, just
when I want to manipulate some XML) I would use some kind of polymorphism to
achieve this. I'd define a couple of one-line functions with the different
variables, or calls, and pass the appropriate one to the outer function so they
could be run on its results (somewhat garbled, abbreviated explanation, sorry).
I'm not aware of anything in XSL that looks like polymorphism, but I would be
interested to know if there was a construct that might be similar, or usable
for cases like this one.
Granted I can't construct variable names dynamically, but I can have a number
of variables existing simultaneously and select one and pass it around by
address if I need to. I don't see an analogous construct in XSL, except to use
choose/when to select a line of code based on an actual variable.
I could send my examples if that would be best, but I think that would provide
a lot of unnecessary code just to show a small bit of context.
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.
[Blue line]
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
richard(_dot_)kerry(_at_)atos(_dot_)net<https://webmail.siemens-it-solutions.com/owa/redir.aspx?C=9fb20d019e3e4cb99344d708709a3177&URL=mailto%3arichard.kerry%40atos.net>
[Atos logo]
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
transmitted.
________________________________
From: Michael Kay mike(_at_)saxonica(_dot_)com
<xsl-list-service(_at_)lists(_dot_)mulberrytech(_dot_)com>
Sent: 03 March 2020 11:48
To: xsl-list(_at_)lists(_dot_)mulberrytech(_dot_)com
<xsl-list(_at_)lists(_dot_)mulberrytech(_dot_)com>
Subject: Re: [xsl] How do I pass the mode as a string?
Section §6.6.2 in the XSLT 3.0 spec states:
The
xsl:apply-templates<https://eur01.safelinks.protection.outlook.com/?url=https%3A%2F%2Fwww.w3.org%2FTR%2Fxslt-30%2F%23element-apply-templates&data=02%7C01%7Crichard.kerry%40atos.net%7Cf54e291885cc4d7f604408d7bf68dcd8%7C33440fc6b7c7412cbb730e70b0198d5a%7C0%7C0%7C637188329424694875&sdata=eSQdcCjN4EO8jORS463GpcDU2L9K0dGwwHP6wU9zJ3o%3D&reserved=0>
element also has an optional mode attribute. The value of this attribute must
be one of the following:
*
an
EQName<https://eur01.safelinks.protection.outlook.com/?url=https%3A%2F%2Fwww.w3.org%2FTR%2Fxslt-30%2F%23dt-eqname&data=02%7C01%7Crichard.kerry%40atos.net%7Cf54e291885cc4d7f604408d7bf68dcd8%7C33440fc6b7c7412cbb730e70b0198d5a%7C0%7C0%7C637188329424694875&sdata=Fk%2FK%2FfJKIe1TdwQmwpizrP8xMug12fJUDBRGLfJG17g%3D&reserved=0>,
which is expanded as described in 5.1.1 Qualified
Names<https://eur01.safelinks.protection.outlook.com/?url=https%3A%2F%2Fwww.w3.org%2FTR%2Fxslt-30%2F%23qname&data=02%7C01%7Crichard.kerry%40atos.net%7Cf54e291885cc4d7f604408d7bf68dcd8%7C33440fc6b7c7412cbb730e70b0198d5a%7C0%7C0%7C637188329424704871&sdata=J9K12tJfdfAz4JxbQAcj9II%2FfTDTxabxPgUUSo5aHv0%3D&reserved=0>
to define the name of a mode
*
the token #default, to indicate that the default mode for the stylesheet
module<https://eur01.safelinks.protection.outlook.com/?url=https%3A%2F%2Fwww.w3.org%2FTR%2Fxslt-30%2F%23dt-stylesheet-module&data=02%7C01%7Crichard.kerry%40atos.net%7Cf54e291885cc4d7f604408d7bf68dcd8%7C33440fc6b7c7412cbb730e70b0198d5a%7C0%7C0%7C637188329424704871&sdata=a6iW12SrGH06RlMcl2h9b8dJI3REzfkYOrO5Au8g9z4%3D&reserved=0>
is to be used
*
the token #unnamed, to indicate that the unnamed
mode<https://eur01.safelinks.protection.outlook.com/?url=https%3A%2F%2Fwww.w3.org%2FTR%2Fxslt-30%2F%23dt-unnamed-mode&data=02%7C01%7Crichard.kerry%40atos.net%7Cf54e291885cc4d7f604408d7bf68dcd8%7C33440fc6b7c7412cbb730e70b0198d5a%7C0%7C0%7C637188329424714867&sdata=i6lQizANc28QMchUjq6CdLldwmM57L1PNleISc%2F%2BDHo%3D&reserved=0>
is to be used
*
the token #current, to indicate that the current
mode<https://eur01.safelinks.protection.outlook.com/?url=https%3A%2F%2Fwww.w3.org%2FTR%2Fxslt-30%2F%23dt-current-mode&data=02%7C01%7Crichard.kerry%40atos.net%7Cf54e291885cc4d7f604408d7bf68dcd8%7C33440fc6b7c7412cbb730e70b0198d5a%7C0%7C0%7C637188329424714867&sdata=%2FSSYYInob%2BrZ3Jj5CQK2mqWdJgtpzkoGFsBxM%2FDihKs%3D&reserved=0>
is to be used
It does not allow an expression, and it does not allow an attribute value
template.
It's similar to trying to refer to a variable by name: you can't construct
variable names dynamically either, however much you feel it would make your
life easier.
You haven't described your problem so it's difficult to suggest a different
approach to solving it. Higher-order functions might be the right way.
Michael Kay
Saxonica
--~----------------------------------------------------------------
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
--~--