Core Use Case 1:

eTSM script:

<!-- ============== Core Use Case: 1 ================= -->
<!--
   - synchronous scriplet invocation, passing parameters.
   - compose effects of several scriplets.
   - use the "eval" operator for expression evaluation.

   NOTE: the "effect" of the entire execution is supposed to go on the standard output.

   EXPECTED OUTPUT:

   <report:totalUpdate>
     <report:previous>1000</report:previous>
     <report:new>1330</report:new>
   </report:totalUpdate>

   -->

<etsm:monitoringScript name="CUC-1">

  <etsm:executionContext>
    <!-- some namespaces to be used in XML fragments generated as effect -->
    <etsm:nmsbinding prefix="myapp">http://www.abc.com/TBD/myapp</etsm:nmsbinding>
    <etsm:nmsbinding prefix="report">http://www.abc.com/TBD/report</etsm:nmsbinding>
    <!-- starting point -->
    <etsm:startwith scriplet="test1"/> 
    <!-- a global variable -->
    <etsm:var name="currentTotal" type="double">1000</etsm:var> 
  </etsm:executionContext>

  <!-- ======= scriplet: test1 ======= -->
  <etsm:scriplet name="test1">

    <etsm:var name="totalpos" type="double" expr="$currentTotal"/>
    <etsm:var name="mynewpo" type="xml">
      <myapp:po>
        <myapp:ref>123456</myapp:ref>
        <myapp:product>greenbike</myapp:product>
        <myapp:qty>2</myapp:qty>
        <myapp:price>165</myapp:price>
      </myapp:po>
    </etsm:var>

    <report:totalUpdate>

      <etsm:start scriplet="addpo">
        <etsm:with-param name="mypo" expr="$mynewpo"/> 
        <etsm:with-param name="previoustotal" expr="$totalpos"/>
      </etsm:start>

    </report:totalUpdate>

  </etsm:scriplet> <!-- test1 -->

  <!-- ======= scriplet: addpo ======= -->
  <etsm:scriplet name="addpo">
    <etsm:param name="mypo"/>
    <etsm:param name="previoustotal"/>
    
    <report:previous><etsm:eval expr="$previoustotal"/></report:previous>
    <report:new><etsm:eval expr="$previoustotal + ($mypo/myapp:po/myapp:price * $mypo/myapp:po/myapp:qty)"/></report:new>
    
  </etsm:scriplet> <!-- addpo -->

</etsm:monitoringScript>

XSLT translation:

<?xml version="1.0" ?>
<!-- ?xml-stylesheet href="mergetaids.xsl" type="text/xsl"? -->

<!--
    @author Jacques Durand (Fujitsu)
  -->

<xsl:stylesheet 
   version="2.0" 
   xmlns="http://www.ws-i.org/testing/2007/03/test/" 
   xmlns:xsl="http://www.w3.org/1999/XSL/Transform" 
   xmlns:etsm="http://www.oasis-open.org/tamie/"
   xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
   xmlns:xsd="http://www.w3.org/2001/XMLSchema"
   xmlns:xs="http://www.w3.org/2001/XMLSchema"
   xmlns:fn="http://www.w3.org/2005/xpath-functions" 
   xmlns:myapp="http://www.abc.com/TBD/myapp"
   xmlns:report="http://www.abc.com/TBD/report"
   >

  <xsl:output method="xml" indent="yes"/>

  <xsl:variable name="currentTotal" >1000</xsl:variable> 

  <xsl:template match="/"> 
    <xsl:call-template name="scriplet_test1">
      <!-- xsl:with-param name="totalpos" select="$currentTotal"/ -->
    </xsl:call-template> 
  </xsl:template> 

  <!-- ================== scriplet: test1 ===================== -->
  <xsl:template name="scriplet_test1">
    <!-- xsl:param name="totalpos"/ -->

    <xsl:variable name="totalpos"  select="$currentTotal"/> 
    <xsl:variable name="mynewpo"> 
      <myapp:po>
        <myapp:ref>123456</myapp:ref>
        <myapp:product>greenbike</myapp:product>
        <myapp:qty>2</myapp:qty>
        <myapp:price>165</myapp:price>
      </myapp:po>
    </xsl:variable> 

    <report:totalUpdate>

      <xsl:call-template name="scriplet_addpo">
        <xsl:with-param name="mypo" select="$mynewpo"/> 
        <xsl:with-param name="previoustotal" select="$totalpos"/>
      </xsl:call-template>

    </report:totalUpdate>

  </xsl:template> <!--  name="scriplet_test1" -->

  <!-- ================== scriplet: addpo ===================== -->

  <xsl:template name="scriplet_addpo">

    <xsl:param name="mypo"/> 
    <xsl:param name="previoustotal"/> 

    <report:previous>
      <xsl:copy-of select="$previoustotal"/>
    </report:previous>
    <report:new>
      <!-- xsl:copy-of select="xs:double($previoustotal) + (xs:double($mypo/myapp:po/myapp:price) * xs:double($mypo/myapp:po/myapp:qty))"/ -->
      <xsl:copy-of select="$previoustotal + ($mypo/myapp:po/myapp:price * $mypo/myapp:po/myapp:qty)"/>
    </report:new>

  </xsl:template> <!--  name="scriplet_addpo" -->

  <!-- ================== end Core-1 ===================== -->

</xsl:stylesheet>

CUC1 (last edited 2009-08-12 18:06:01 by localhost)