[Top] [All Lists]

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

2020-03-03 06:18:03
Am 03.03.2020 um 12:21 schrieb Kerry, Richard 

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

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.

The only option do do have in XSLT 3 to set a mode dynamically is to use
a static parameter or variable and a shadow attribute so if you have a
top level

<xsl:param name="match-mode" static="yes" as="xs:string" select="'inputs'"/>

then you can use a shadow attribute _mode

<xsl:apply-templates _mode="{$match-mode}"/>

Of course this only helps if you want to set that parameter before
running the complete XSLT.

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>