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 / F20152_genericMath.minmax.template.xsl < prev    next >
Encoding:
Extensible Markup Language  |  2001-06-06  |  4.4 KB  |  130 lines

  1. <xsl:stylesheet version="1.0"
  2. xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
  3. xmlns:exsl-default-relation-gt="exsl-default-relation-gt"
  4. xmlns:exsl-default-relation-lt="exsl-default-relation-lt"
  5. >
  6.  
  7. <exsl-default-relation-gt:node/>
  8. <exsl-default-relation-lt:node/>
  9.  
  10.  <xsl:variable name="defaultGT"
  11.                select="document('')/*/exsl-default-relation-gt:*[1]"/>
  12.  
  13.  <xsl:variable name="defaultLT"
  14.                select="document('')/*/exsl-default-relation-lt:*[1]"/>
  15.  
  16.  <xsl:template name="min">
  17.    <xsl:param name="nodes" select="/.." />
  18.    <xsl:param name="lessThanTemplateUID" select="$defaultLT" />
  19.  
  20.    <xsl:variable name="minPos">
  21.     <xsl:call-template name="pMin">
  22.       <xsl:with-param name="nodes" select="$nodes" />
  23.       <xsl:with-param name="start" select="1" />
  24.       <xsl:with-param name="end" select="count($nodes)" />
  25.       <xsl:with-param name="lessThanTemplateUID" select="$lessThanTemplateUID" />
  26.     </xsl:call-template>
  27.    </xsl:variable>
  28.  
  29.    <!-- Important: this will not return the node - impossible in XSLT
  30.         The node can be returned in EXSLT using exslt:result -->
  31.    <xsl:value-of select="$nodes[position()=$minPos]"/>
  32.  
  33.  </xsl:template>
  34.  
  35.  <xsl:template name="max">
  36.    <xsl:param name="nodes" select="/.." />
  37.    <xsl:param name="greaterTemplateUID" select="$defaultGT" />
  38.  
  39.    <xsl:variable name="maxPos">
  40.     <xsl:call-template name="pMax">
  41.       <xsl:with-param name="nodes" select="$nodes" />
  42.       <xsl:with-param name="start" select="1" />
  43.       <xsl:with-param name="end" select="count($nodes)" />
  44.       <xsl:with-param name="greaterTemplateUID" select="$greaterTemplateUID" />
  45.     </xsl:call-template>
  46.    </xsl:variable>
  47.  
  48.    <xsl:value-of select="$nodes[position()=$maxPos]"/>
  49.  
  50.  </xsl:template>
  51.  
  52.   <xsl:template name="pMin">
  53.     <xsl:param name="nodes" select="/.." />
  54.     <xsl:param name="start" select="0" />
  55.     <xsl:param name="end" select="0" />
  56.     <xsl:param name="lessThanTemplateUID" select="$defaultLT" />
  57.  
  58.     <xsl:call-template name="pMax">
  59.       <xsl:with-param name="nodes" select="$nodes" />
  60.       <xsl:with-param name="start" select="$start" />
  61.       <xsl:with-param name="end" select="$end" />
  62.       <xsl:with-param name="greaterTemplateUID" select="$lessThanTemplateUID" />
  63.     </xsl:call-template>
  64.   </xsl:template>
  65.  
  66.   <xsl:template name="pMax">
  67.   <xsl:param name="nodes" select="/.." />
  68.   <xsl:param name="start" select="0" />
  69.   <xsl:param name="end" select="0" />
  70.   <xsl:param name="greaterTemplateUID" select="$defaultGT" />
  71.   <xsl:choose>
  72.      <xsl:when test="$start = $end">
  73.         <xsl:value-of select="$start" />
  74.      </xsl:when>
  75.      <xsl:otherwise>
  76.         <xsl:variable name="max-of-rest">
  77.            <xsl:call-template name="pMax">
  78.               <xsl:with-param name="nodes" select="$nodes" />
  79.               <xsl:with-param name="start" select="$start + 1" />
  80.               <xsl:with-param name="end"   select="$end" />
  81.               <xsl:with-param name="greaterTemplateUID"
  82.                               select="$greaterTemplateUID" />
  83.            </xsl:call-template>
  84.         </xsl:variable>
  85.  
  86. <!--
  87.          <xsl:apply-templates select="$greaterTemplateUID">
  88.                          <xsl:with-param name="nodes" select="$nodes"/>
  89.                         <xsl:with-param name="n1-pos" select="$max-of-rest"/>
  90.                         <xsl:with-param name="n2-pos" select="$start"/>
  91.          </xsl:apply-templates>
  92. -->
  93.         <xsl:variable name="isGreater">
  94.          <xsl:apply-templates select="$greaterTemplateUID">
  95.                         <xsl:with-param name="n1" select="$nodes[position()=$max-of-rest]"/>
  96.                         <xsl:with-param name="n2" select="$nodes[position()=$start]"/>
  97.          </xsl:apply-templates>
  98.         </xsl:variable>
  99.  
  100.         <xsl:choose>
  101.           <xsl:when test="$isGreater = 'true'">
  102.              <xsl:value-of select="$max-of-rest" />
  103.           </xsl:when>
  104.           <xsl:otherwise>
  105.              <xsl:value-of select="$start" />
  106.           </xsl:otherwise>
  107.         </xsl:choose>
  108.      </xsl:otherwise>
  109.   </xsl:choose>
  110. </xsl:template>
  111.  
  112. <xsl:template match="*[namespace-uri() = 'exsl-default-relation-gt']">
  113.     <xsl:param name="n1" select="/.."/>
  114.     <xsl:param name="n2" select="/.."/>
  115.  
  116.     <xsl:value-of select="$n1 > $n2"/>
  117.   </xsl:template>
  118.  
  119. <xsl:template match="*[namespace-uri() = 'exsl-default-relation-lt']">
  120.     <xsl:param name="n1" select="/.."/>
  121.     <xsl:param name="n2" select="/.."/>
  122.  
  123.     <xsl:value-of select="$n1 < $n2"/>
  124.   </xsl:template>
  125.  
  126.  
  127. </xsl:stylesheet>
  128.  
  129.  
  130.