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

Subject: Re: [xsl] How do I pass the mode as a string?
From: "Martin Honnen martin.honnen@xxxxxx" <xsl-list-service@xxxxxxxxxxxxxxxxxxxxxx>
Date: Tue, 3 Mar 2020 12:17:57 -0000
Am 03.03.2020 um 12:21 schrieb Kerry, Richard richard.kerry@xxxxxxxx:

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.

Current Thread