xsl-list
[Top] [All Lists]

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

2020-03-03 05:20:53

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