[XSL-LIST Mailing List Archive Home] [By Thread] [By Date] [Recent Entries] [Reply To This Message]

Re: Is it possible to set the mode dynamically?

Subject: Re: Is it possible to set the mode dynamically?
From: "Michael Kay mike@xxxxxxxxxxxx" <xsl-list-service@xxxxxxxxxxxxxxxxxxxxxx>
Date: Tue, 7 Jan 2020 11:20:40 -0000
Re:  Is it possible to set the mode dynamically?
Another way would be to associate a function with each mode:

<xsl:function name="f:apply-pivot-table">
  <xsl:param name="select"/>
  <xsl:apply-templates select="$select" mode="pivot-table"/>
</xsl:function>

<xsl:function name="f:apply-default">
  <xsl:param name="select"/>
  <xsl:apply-templates select="$select" mode="#unnamed"/>
</xsl:function>

<xsl:variable name="apply" select="if ($table-name = 'pivot-table-payload')
then f:apply-pivot-table#1 else f:apply-default#1"/>

and then replace the <xsl:apply-templates select="X"/> instruction with
<xsl:sequence select="$apply(X)"/>

(But having introduced higher order functions, you might then find you can do
everything with higher order functions and don't need template rule matching
at all).

Michael Kay
Saxonica

> On 7 Jan 2020, at 11:01, Martin Honnen martin.honnen@xxxxxx
<xsl-list-service@xxxxxxxxxxxxxxxxxxxxxx> wrote:
>
> Am 07.01.2020 um 11:51 schrieb rus tle profrustyleafiii@xxxxxxxxxxx
<mailto:profrustyleafiii@xxxxxxxxxxx>:
>> Is it possible to set the mode dynamically?
>>
>> The use case:
>>
>> 1. Setting a variable to a file name
>>
>> <xsl:variable name="PayloadName" select="/POM/Netflix/@payload" />
>>
>> 2. Using that variable to load the file dynamically into another variable
>>
>> <xsl:variable name="payload" select="document(concat($PayloadName,
'.xml'))/payloadb/>
>>
>> 3. Calling a template and passing the file name as as a param to be used in
that called template as the mode.
>>
>>  <xsl:call-template name="create-html-tables">
>>       <xsl:with-param name="PayloadName" select="$PayloadNameb/>
>> </xsl:call-template>
>>
>>  <xsl:template name="create-html-tables">
>>         <xsl:param name=bPayloadName"/>
>>        <xsl:apply-templates select="$pom//Event" mode=b$payloadNameb/>
>> </xsl:template>
>>
>> Is that a possibility in anyway shape or formb&? Otherwise I am thinking
the only alternative would be to use a choose and then hardcode the mode -
which works, but just wondering if there was a cleaner way?
>>
>> <xsl:choose>
>>     <xsl:when test="$PayloadName = 'pivot-table-payload'">
>>         <xsl:apply-templates select="$pom//Event" mode="pivot-table"/>
>>     </xsl:when>
>>     <xsl:otherwise>
>>         <xsl:apply-templates select="$pom//Event" mode="default"/>
>>     </xsl:otherwise>
>> </xsl:choose>
>>
>> Many thanks,
>>
>> Rusty
>
> Using a shadow attribute in XSLT 3 it might work:
https://www.w3.org/TR/xslt-30/#shadow-attributes
<https://www.w3.org/TR/xslt-30/#shadow-attributes>
>
> The variable/param would need to be global and static.
>
>
> Additionally there is fn:transform to run on the fly generated XSLT.
>
> XSL-List info and archive <http://www.mulberrytech.com/xsl/xsl-list>
> EasyUnsubscribe <http://lists.mulberrytech.com/unsub/xsl-list/293509> (by
email <>)

Current Thread

PURCHASE STYLUS STUDIO ONLINE TODAY!

Purchasing Stylus Studio from our online shop is Easy, Secure and Value Priced!

Buy Stylus Studio Now

Download The World's Best XML IDE!

Accelerate XML development with our award-winning XML IDE - Download a free trial today!

Don't miss another message! Subscribe to this list today.
Email
First Name
Last Name
Company
Subscribe in XML format
RSS 2.0
Atom 0.3
Site Map | Privacy Policy | Terms of Use | Trademarks
Free Stylus Studio XML Training:
W3C Member
Stylus Studio® and DataDirect XQuery ™are products from DataDirect Technologies, is a registered trademark of Progress Software Corporation, in the U.S. and other countries. © 2004-2013 All Rights Reserved.