OASIS Mailing List ArchivesView the OASIS mailing list archive below
or browse/search using MarkMail.

 


Help: OASIS Mailing Lists Help | MarkMail Help

tamie message

[Date Prev] | [Thread Prev] | [Thread Next] | [Date Next] -- [Date Index] | [Thread Index] | [List Home]


Subject: RE: [tamie] The case for CTL Functions


Title: The case for CTL Functions
Yes.  XSLT 2.0 stylesheet functions are top-level elements written in XSLT and they can be used in XPath expressions.  The only restriction I can find is that in a function, the context item is initially undefined.  There is no problem with a function calling a template.  (I tried it - it works).  The code for translating eTSM constructs to XSLT should be the same whether the eTSM code is in a function or a scriplet.
 
- Chuck
 

From: Jacques R. Durand [mailto:JDurand@us.fujitsu.com]
Sent: Wednesday, March 11, 2009 7:45 PM
To: Morris, Chuck E (IS); tamie@lists.oasis-open.org
Subject: RE: [tamie] The case for CTL Functions

Chuck:
 
That sounds good, but are you confident that we can translate in XSLT the *use* of these eTSM functions? (i.e. their references in XPath expressions).
I guess we would have to generate user-defined XSLT functions for these - will that allow for the same XSLT translation of internal eTSM constructs (loops, conditional stmt...) given that we will likely use named templates?
 
-Jacques


From: Morris, Chuck E (IS) [mailto:chuck.morris@ngc.com]
Sent: Wednesday, March 11, 2009 8:24 AM
To: tamie@lists.oasis-open.org
Subject: [tamie] The case for CTL Functions

There has been some question about whether we need functions written in CTL, since scriptlets can also produce effects.  I think they are still desirable.  Here's why.

Suppose you have a complicated business rule.  I'll illustrate with one that determines the discount an order is elligible for.  The logic can be placed in a scriptlet.

<scriptlet name="get-discount">
  <param name="order">
  <decide>
    <if expr="$order/type='TypeA'">
       <if expr="$order/total &gt; 1000">15%</if>
       <if expr="$order/total &gt; 100">2%</if>
    </if>
    <elseif expr="$order/type='TypeB'">
       <if expr="$order/total &gt; 500">5%</if>
       <if expr="$order/total &gt; 200">1%</if>
    </elseif>
    <else>0%</else>
  </decide>
</scriptlet>

If you need to call this logic from inside another scriptlet, it's relatively straightforward.

<var name="discount">
  <start scriptlet="get-discount">
    <with-param name="order" expr="$order"/>
  </start>
</var>

If the logic were placed in a function instead, it could be expressed more compactly.

<var name="discount" expr="get-discount($order)"/>

But the real benefit is that it allows you to use this logic inside more complicated Xpath expressions.  For example, iterating through orders that get a 15% discount.

<loop expr="$orders/order[get-discount(.) = '15%']">
</loop>

Or catching order events that get a 15% discount.

<var name="order">
  <catch pattern="content/order[get-discount(.) = '15%']"/>
</var>

Without the function, you would have to catch all order events in a loop until you found one that got the discount.



[Date Prev] | [Thread Prev] | [Thread Next] | [Date Next] -- [Date Index] | [Thread Index] | [List Home]