Subject: [xsl] How do I pass the mode as a string? From: "Kerry, Richard richard.kerry@xxxxxxxx" <xsl-list-service@xxxxxxxxxxxxxxxxxxxxxx> Date: Tue, 3 Mar 2020 11:42:15 -0000 |
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. PS Sorry if this comes through twice, I forgot it needs to be plain text. 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.kerry@xxxxxxxx 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.
Current Thread |
---|
|
<- Previous | Index | Next -> |
---|---|---|
Re: [xsl] How do I pass the mode as, Kerry, Richard richa | Thread | Re: [xsl] How do I pass the mode as, David Carlisle d.p.c |
[xsl] How do I pass the mode as a s, Kerry, Richard richa | Date | Re: [xsl] How do I pass the mode as, Michael Kay mike@xxx |
Month |