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