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

Re: Data-driven XSLT code using dynamic mode values?

Subject: Re: Data-driven XSLT code using dynamic mode values?
From: Dimitre Novatchev <dnovatchev@xxxxxxxxx>
Date: Fri, 2 Aug 2013 08:40:43 -0700
Re:  Data-driven XSLT code using dynamic mode values?
Seems like you want to use FXSL (for either XSLT 1.0 or 2.0) and HOFs
for XSLT 3.0.

As for "data-driven", maybe the "fill-in-the-blanks" (forms with
variables replacement) technique would be useful.

Cheers,
Dimitre

On Fri, Aug 2, 2013 at 7:26 AM, Costello, Roger L. <costello@xxxxxxxxx> wrote:
> 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
>



-- 
Cheers,
Dimitre Novatchev
---------------------------------------
Truly great madness cannot be achieved without significant intelligence.
---------------------------------------
To invent, you need a good imagination and a pile of junk
-------------------------------------
Never fight an inanimate object
-------------------------------------
To avoid situations in which you might make mistakes may be the
biggest mistake of all
------------------------------------
Quality means doing it right when no one is looking.
-------------------------------------
You've achieved success in your field when you don't know whether what
you're doing is work or play
-------------------------------------
Facts do not cease to exist because they are ignored.
-------------------------------------
Typing monkeys will write all Shakespeare's works in 200yrs.Will they
write all patents, too? :)
-------------------------------------
I finally figured out the only reason to be alive is to enjoy it.

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.