xsl-list
[Top] [All Lists]

RE: [xsl] Data-driven XSLT code using dynamic mode values?

2013-08-02 09:56:24
Hi Hermann,

You did not specify which XSLT version 
you are interested in.

Ah, good point.

How about version 3.0? Given that, what's the best solution?

/Roger

-----Original Message-----
From: Hermann Stamm-Wilbrandt [mailto:STAMMW(_at_)de(_dot_)ibm(_dot_)com] 
Sent: Friday, August 02, 2013 10:52 AM
To: xsl-list(_at_)lists(_dot_)mulberrytech(_dot_)com
Subject: Re: [xsl] Data-driven XSLT code using dynamic mode values?

You did not specify which XSLT version you are interested in.

For XSLT 1.0 the <xsl:choose> solution you showed is the only solution.


Mit besten Gruessen / Best wishes,

Hermann Stamm-Wilbrandt
Level 3 support for XML Compiler team and Fixpack team lead
WebSphere DataPower SOA Appliances
https://www.ibm.com/developerworks/mydeveloperworks/blogs/HermannSW/
https://twitter.com/HermannSW/     http://www.stamm-wilbrandt.de/ce/
----------------------------------------------------------------------
IBM Deutschland Research & Development GmbH
Vorsitzende des Aufsichtsrats: Martina Koederitz
Geschaeftsfuehrung: Dirk Wittkopp
Sitz der Gesellschaft: Boeblingen
Registergericht: Amtsgericht Stuttgart, HRB 243294


|------------>
| From:      |
|------------>
  
--------------------------------------------------------------------------------------------------------------------------------------------------|
  |"Costello, Roger L." <costello(_at_)mitre(_dot_)org>                         
                                                                                
|
  
--------------------------------------------------------------------------------------------------------------------------------------------------|
|------------>
| To:        |
|------------>
  
--------------------------------------------------------------------------------------------------------------------------------------------------|
  |"xsl-list(_at_)lists(_dot_)mulberrytech(_dot_)com" 
<xsl-list(_at_)lists(_dot_)mulberrytech(_dot_)com>,                             
                                                 |
  
--------------------------------------------------------------------------------------------------------------------------------------------------|
|------------>
| Date:      |
|------------>
  
--------------------------------------------------------------------------------------------------------------------------------------------------|
  |08/02/2013 04:26 PM                                                          
                                                                     |
  
--------------------------------------------------------------------------------------------------------------------------------------------------|
|------------>
| Subject:   |
|------------>
  
--------------------------------------------------------------------------------------------------------------------------------------------------|
  |[xsl] Data-driven XSLT code using dynamic mode values?                       
                                                                     |
  
--------------------------------------------------------------------------------------------------------------------------------------------------|





Hi Folks,

I want to have multiple templates for the same element, each template
processes the element differently.

"Use modes," you say.

Okay, sounds good. So I will have multiple template rules:

    <xsl:template match="Header" mode="Remove">

    <xsl:template match="Header" mode="Replace">

    <xsl:template match="Header" mode="Reject">

Now let's turn to the problem of firing the appropriate template rule.

I have a variable which has a value that indicates whether I should do a
Remove, Replace, or Reject:

    <xsl:variable name="action" select="get the action from an XML file" />

I want to fire a template rule based on the value of $action.

Here's what I really, really want to do:

    <xsl:apply-templates select="." mode="$action" />

That would be so cool. That would truly be "data-driven code."

Unfortunately, using a variable as the value of @mode is not allowed.

Bummer.

Is my only solution to use xsl:choose:

          <xsl:choose>
              <xsl:when test="$action eq 'Remove'">
                  <xsl:apply-templates select="." mode="Remove" />
              </xsl:when>
              <xsl:when test="$action eq 'Replace'">
                  <xsl:apply-templates select="." mode="Replace" />
              </xsl:when>
              <xsl:when test="$action eq 'Reject'">
                  <xsl:apply-templates select="." mode="Reject" />
              </xsl:when>
          </xsl:choose>

That is an awful solution. It is brittle and not extensible code.

Please, please show me a better way than using xsl:choose.

/Roger


--~------------------------------------------------------------------
XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list
To unsubscribe, go to: http://lists.mulberrytech.com/xsl-list/
or e-mail: <mailto:xsl-list-unsubscribe(_at_)lists(_dot_)mulberrytech(_dot_)com>
--~--





--~------------------------------------------------------------------
XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list
To unsubscribe, go to: http://lists.mulberrytech.com/xsl-list/
or e-mail: <mailto:xsl-list-unsubscribe(_at_)lists(_dot_)mulberrytech(_dot_)com>
--~--


--~------------------------------------------------------------------
XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list
To unsubscribe, go to: http://lists.mulberrytech.com/xsl-list/
or e-mail: <mailto:xsl-list-unsubscribe(_at_)lists(_dot_)mulberrytech(_dot_)com>
--~--


<Prev in Thread] Current Thread [Next in Thread>