home *** CD-ROM | disk | FTP | other *** search
/ Programmer Plus 2007 / Programmer-Plus-2007.iso / Programming / XML Utilities / Professional Programmer XSL IDE / Xselerator25.msi / Data.Cab / F35268_PartialSumsList.xsl < prev    next >
Encoding:
Extensible Markup Language  |  2002-01-20  |  6.1 KB  |  170 lines

  1. <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
  2. xmlns:saxon="http://icl.com/saxon"
  3. xmlns:pGenerator="pGenerator"
  4. xmlns:pController="pController"
  5. xmlns:IntervalParams="IntervalParams"
  6. xmlns:mapEasyIntegrate="mapEasyIntegrate"
  7. xmlns:easy-integrate="easy-integrate"
  8. exclude-result-prefixes="xsl saxon pGenerator pController IntervalParams easy-integrate"
  9. >
  10.   <xsl:import href="buildListWhileMap.xsl"/>
  11.   <xsl:import href="foldl.xsl"/>
  12.  
  13.   
  14.   <xsl:output indent="yes" omit-xml-declaration="yes"/>
  15.   
  16.   <pGenerator:pGenerator/>
  17.   <pController:pController/>
  18.   <mapEasyIntegrate:mapEasyIntegrate/>
  19.   <easy-integrate:easy-integrate/>
  20.  
  21.  
  22.   <xsl:template name="partialSumsList">
  23.     <xsl:param name="pFun" select="/.."/>
  24.     <xsl:param name="pA"/>
  25.     <xsl:param name="pB"/>
  26.     <xsl:param name="pEps" select="0.001"/>
  27.  
  28.   <xsl:variable name="vMyGenerator" select="document('')/*/pGenerator:*[1]"/>
  29.   <xsl:variable name="vMyController" select="document('')/*/pController:*[1]"/>
  30.   <xsl:variable name="vmyEasyIntegrateMap" select="document('')/*/mapEasyIntegrate:*[1]"/>
  31.  
  32.     <xsl:variable name="vrtfvIntervalParams">
  33.       <IntervalParams:IntervalParams>
  34.         <Interval>
  35.           <el><xsl:value-of select="$pA"/></el>
  36.           <el><xsl:value-of select="$pB"/></el>
  37.         </Interval>
  38.         <xsl:copy-of select="$pFun"/>
  39.       </IntervalParams:IntervalParams>
  40.     </xsl:variable>
  41.  
  42.     <xsl:variable name="vIntervalParams" select="saxon:node-set($vrtfvIntervalParams)/*"/>
  43.  
  44.  
  45.     <xsl:variable name="vrtfResultIntervalList">
  46.       <xsl:call-template name="buildListWhileMap">
  47.         <xsl:with-param name="pGenerator" select="$vMyGenerator"/>
  48.         <xsl:with-param name="pController" select="$vMyController"/>
  49.         <xsl:with-param name="pParam0" select="$vIntervalParams"/>
  50.         <xsl:with-param name="pContollerParam" select="$pEps"/>
  51.         <xsl:with-param name="pMap" select="$vmyEasyIntegrateMap"/>
  52.       </xsl:call-template>
  53.     </xsl:variable>
  54.  
  55.     <xsl:copy-of select="saxon:node-set($vrtfResultIntervalList)"/>
  56.  
  57.     <xsl:variable name="vResultIntervalList"
  58.        select="saxon:node-set($vrtfResultIntervalList)/*[last()]/*"/>
  59.  
  60.   </xsl:template>
  61.  
  62.   <xsl:template name="listGenerator" match="*[namespace-uri()='pGenerator']">
  63.      <xsl:param name="pList" select="/.."/>
  64.      <xsl:param name="pParams"/>
  65.  
  66.      <xsl:variable name="pA0" select="string($pParams/*[1]/*[1])"/>
  67.      <xsl:variable name="pB0" select="string($pParams/*[1]/*[2])"/>
  68.      <xsl:variable name="pFun" select="$pParams/*[2]"/>
  69.  
  70.      <xsl:choose>
  71.        <xsl:when test="not($pList)">
  72.          <xsl:variable name="vFa">
  73.            <xsl:apply-templates select="$pFun">
  74.              <xsl:with-param name="pX" select="$pA0"/>
  75.            </xsl:apply-templates>
  76.          </xsl:variable>
  77.  
  78.          <xsl:variable name="vFb">
  79.            <xsl:apply-templates select="$pFun">
  80.              <xsl:with-param name="pX" select="$pB0"/>
  81.            </xsl:apply-templates>
  82.          </xsl:variable>
  83.  
  84.          <e><xsl:value-of select="$pB0 - $pA0"/></e>
  85.          <e><xsl:value-of select="$vFa"/></e>
  86.          <e><xsl:value-of select="$vFb"/></e>
  87.        </xsl:when>
  88.        <xsl:otherwise>
  89.           <xsl:variable name="vprevH" select="$pList[last()]/*[1]"/>
  90.           <xsl:variable name="vH" select="$vprevH div 2"/>
  91.           <e><xsl:value-of select="$vH"/></e>
  92.           <xsl:for-each select="$pList[last()]/*[position() > 1
  93.                                              and position() != last()]">
  94.            <xsl:variable name="vA" select="$pA0 + (position() - 1) * $vprevH"/>
  95.  
  96.            <xsl:variable name="vMid" select="$vA + $vH"/>
  97.  
  98.            <xsl:variable name="vF_mid">
  99.              <xsl:apply-templates select="$pFun">
  100.                <xsl:with-param name="pX" select="$vMid"/>
  101.              </xsl:apply-templates>
  102.            </xsl:variable>
  103.  
  104.            <xsl:copy-of select="."/>
  105.            <e><xsl:value-of select="$vF_mid"/></e>
  106.          </xsl:for-each>
  107.          <xsl:copy-of select="$pList[last()]/*[last()]"/>
  108.        </xsl:otherwise>
  109.      </xsl:choose>
  110.  
  111.   </xsl:template>
  112.  
  113.   <xsl:template name="listController" match="*[namespace-uri()='pController']">
  114.      <xsl:param name="pList" select="/.."/>
  115.      <xsl:param name="pParams"/>
  116.  
  117.      <xsl:choose>
  118.          <xsl:when test="count($pList) < 2">1</xsl:when>
  119.          <xsl:otherwise>
  120.              <xsl:variable name="vLastDiff" select="$pList[last()]
  121.                                                   - $pList[last() - 1]"/>
  122.  
  123.              <xsl:if test="not($vLastDiff < $pParams
  124.                        and $vLastDiff > (0 - $pParams))">1</xsl:if>
  125.          </xsl:otherwise>
  126.      </xsl:choose>
  127.   </xsl:template>
  128.  
  129.   <xsl:template name="mapEasyIntegrate" match="*[namespace-uri()='mapEasyIntegrate']">
  130.      <xsl:param name="pParams" select="/.."/> <!-- pMapParams -->
  131.      <xsl:param name="pDynParams" select="/.."/> <!-- NewBaseListElement -->
  132.      <xsl:param name="pList" select="/.."/>
  133.  
  134.      <xsl:variable name="vResult">
  135.          <xsl:call-template name="multiIntegrate">
  136.           <xsl:with-param name="pList" select="$pDynParams/*"/>
  137.         </xsl:call-template>
  138.      </xsl:variable>
  139.  
  140.      <xsl:copy-of select="saxon:node-set($vResult)"/>
  141.   </xsl:template>
  142.  
  143.   <xsl:template name="multiIntegrate">
  144.     <xsl:param name="pList" select="/*/*"/>
  145.  
  146.     <xsl:variable name="vmyeasyIntegrateFn" select="document('')/*/easy-integrate:*[1]"/>
  147.  
  148.       <xsl:call-template name="foldl">
  149.         <xsl:with-param name="pFunc" select="$vmyeasyIntegrateFn"/>
  150.         <xsl:with-param name="pList" select="$pList[position() > 1
  151.                                               and position() < last()]"/>
  152.         <xsl:with-param name="pA0" select="0"/>
  153.       </xsl:call-template>
  154.  
  155.   </xsl:template>
  156.  
  157.   <xsl:template name="myEasyIntegrateFn" match="*[namespace-uri()='easy-integrate']">
  158.     <xsl:param name="arg1" select="0"/> <!-- pA0 -->
  159.     <xsl:param name="arg2" select="0"/> <!-- node -->
  160.  
  161.     <xsl:value-of
  162.        select="$arg1
  163.              +
  164.                (($arg2 + $arg2/following-sibling::*[1])
  165.                  div 2
  166.                 ) * $arg2/../*[1]"/>
  167.  
  168.   </xsl:template>
  169.  
  170. </xsl:stylesheet>