xsl-list
[Top] [All Lists]

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

2020-03-03 09:55:38
While this is not allowed in XSLT, one can accomplish the passing functions
as parameters.

For XSLT 1.0, 2.0 see the FXSL library.

The XSLT 3.0 / XPath 3.0 and 3.1 standards support higher order functions.

Cheers,
Dimitre

On Tue, Mar 3, 2020 at 3:20 AM Kerry, Richard 
richard(_dot_)kerry(_at_)atos(_dot_)net <
xsl-list-service(_at_)lists(_dot_)mulberrytech(_dot_)com> wrote:


Normally I would specify apply-template's mode as a literal, eg:
<x:apply-templates mode="inputs" />

I have a number of instances of similar code which need to have different
modes, eg:
<x:apply-templates mode="outputs" />

I'd like to extract all of this into a separate block that I will call
with these two values.

<x:variable name="match-mode" >inputs</x:variable>
<x:apply-templates mode="$match-mode" />

Doesn't work.  Saxon reports:
Static error at x:apply-templates on line 47 column 74 of xxx.xsl:
  XTSE0020: Mode name {$match-mode} is not a valid QName

OK, so it's a QName, not a string.

So I try:
<x:variable name="match-mode" as="xs:QName" >inputs</x:variable>
<x:apply-templates mode="$match-mode" />

Again giving:
Static error at x:apply-templates on line 47 column 74 of
AlarmsAllToDot.xsl:
  XTSE0020: Mode name {$match-mode} is not a valid QName

(xs is defined as xmlns:xs="http://www.w3.org/2001/XMLSchema"; )

So just telling it to be a QName doesn't seem to work.
I think this syntax for variable means 'inputs' is a text node, so what
about:
<x:variable name="match-mode" as="xs:QName" select="'inputs'" />
<x:apply-templates mode="$match-mode" />

So do I need to do something more actively to generate a QName?
There is a QName function, so how about:

<x:variable name="match-mode" as="xs:QName" select="QName('', 'inputs')" />
<x:apply-templates mode="$match-mode" />

Giving me the same error.

So, where am I gong wrong?
The QName function takes two strings, the first being the namespace.  So
is that wrong to be blank?
Is "inputs" in my namespace?  Or is it XSLT's?
Given that this will be fed directly to apply-templates, presumably it
needs to be in XSLT's, so how about:

<x:variable name="match-mode" as="xs:QName" select="QName('x', 'inputs')"
/>
<x:apply-templates mode="$match-mode" />

(x is defined as   xmlns:x="http://www.w3.org/1999/XSL/Transform";)

Giving the same error.

Or is this about how it is presented to apply-templates?
Am I right to use mode="$match-mode", or should that be done differently?


So, I've tried a few options but I suspect there's something important I'm
missing about QNames and the mode attribute.
Please can someone advise.

Regards,
Richard.





*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>


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.[image: Atos logo]

XSL-List info and archive <http://www.mulberrytech.com/xsl/xsl-list>
EasyUnsubscribe <http://lists.mulberrytech.com/unsub/xsl-list/782854> (by
email <>)



-- 
Cheers,
Dimitre Novatchev
---------------------------------------
Truly great madness cannot be achieved without significant intelligence.
---------------------------------------
To invent, you need a good imagination and a pile of junk
-------------------------------------
Never fight an inanimate object
-------------------------------------
To avoid situations in which you might make mistakes may be the
biggest mistake of all
------------------------------------
Quality means doing it right when no one is looking.
-------------------------------------
You've achieved success in your field when you don't know whether what
you're doing is work or play
-------------------------------------
To achieve the impossible dream, try going to sleep.
-------------------------------------
Facts do not cease to exist because they are ignored.
-------------------------------------
Typing monkeys will write all Shakespeare's works in 200yrs.Will they write
all patents, too? :)
-------------------------------------
Sanity is madness put to good use.
-------------------------------------
I finally figured out the only reason to be alive is to enjoy it.
--~----------------------------------------------------------------
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>