您现在的位置: 启天网 >> 技术中心 >> XML >> 正文
今天是:
XSL中几个封装的函数            【字体:
XSL中几个封装的函数
作者:未知    文章来源:转载    点击数:    更新时间:2007-3-23
     布尔操作函数
  
  <!-- ======================================================== -->
  <!-- Function: BooleanOR(<value1>,<value2>) => number -->
  <!-- Parameters:- -->
  <!-- <value1> - the first number to be ORed -->
  <!-- <value2> - the second number to be ORed -->
  <!-- NB. Only works with unsigned ints! -->
  <xsl:template name="BooleanOR">
   <xsl:param name="value1" select="number(0)"/>
   <xsl:param name="value2" select="number(0)"/>
   <!-- recurse parameters -->
   <xsl:param name="bitval" select="number(2147483648)"/>
   <xsl:param name="accum" select="number(0)"/>
   <!-- calc bits present on values -->
   <xsl:variable name="bit1" select="floor($value1 div $bitval)"/>
   <xsl:variable name="bit2" select="floor($value2 div $bitval)"/>
   <!-- do the OR on the bits -->
   <xsl:variable name="thisbit">
   <xsl:choose>
   <xsl:when test="($bit1 != 0) or ($bit2 != 0)"><xsl:value-of select="$bitval"/></xsl:when>
   <xsl:otherwise>0</xsl:otherwise>
   </xsl:choose>
   </xsl:variable>
   <!-- if last recurse then output the value -->
   <xsl:choose>
   <xsl:when test="$bitval = 1"><xsl:value-of select="$accum + $thisbit"/></xsl:when>
   <xsl:otherwise>
   <!-- recurse required -->
   <xsl:call-template name="BooleanOR">
   <xsl:with-param name="value1" select="$value1 mod $bitval"/>
   <xsl:with-param name="value2" select="$value2 mod $bitval"/>
   <xsl:with-param name="bitval" select="$bitval div 2"/>
   <xsl:with-param name="accum" select="$accum + $thisbit"/>
   </xsl:call-template>
   </xsl:otherwise>
   </xsl:choose>
  </xsl:template>
  
  <!-- ======================================================== -->
  <!-- Function: BooleanAND(<value1>,<value2>) => number -->
  <!-- Parameters:- -->
  <!-- <value1> - the first number to be ANDed -->
  <!-- <value2> - the second number to be ANDed -->
  <!-- NB. Only works with unsigned ints! -->
  <xsl:template name="BooleanAND">
   <xsl:param name="value1" select="number(0)"/>
   <xsl:param name="value2" select="number(0)"/>
   <!-- recurse parameters -->
   <xsl:param name="bitval" select="number(2147483648)"/>
   <xsl:param name="accum" select="number(0)"/>
   <!-- calc bits present on values -->
   <xsl:variable name="bit1" select="floor($value1 div $bitval)"/>
   <xsl:variable name="bit2" select="floor($value2 div $bitval)"/>
   <!-- do the AND on the bits -->
   <xsl:variable name="thisbit">
   <xsl:choose>
   <xsl:when test="($bit1 != 0) and ($bit2 != 0)"><xsl:value-of select="$bitval"/></xsl:when>
   <xsl:otherwise>0</xsl:otherwise>
   </xsl:choose>
   </xsl:variable>
   <!-- if last recurse then output the value -->
   <xsl:choose>
   <xsl:when test="$bitval = 1"><xsl:value-of select="$accum + $thisbit"/></xsl:when>
   <xsl:otherwise>
   <!-- recurse required -->
   <xsl:call-template name="BooleanAND">
   <xsl:with-param name="value1" select="$value1 mod $bitval"/>
   <xsl:with-param name="value2" select="$value2 mod $bitval"/>
   <xsl:with-param name="bitval" select="$bitval div 2"/>
   <xsl:with-param name="accum" select="$accum + $thisbit"/>
   </xsl:call-template>
   </xsl:otherwise>
   </xsl:choose>
  </xsl:template>
  
  <!-- ======================================================== -->
  <!-- Function: BooleanXOR(<value1>,<value2>) => number -->
  <!-- Parameters:- -->
  <!-- <value1> - the first number to be XORed -->
  <!-- <value2> - the second number to be XORed -->
  <!-- NB. Only works with unsigned ints! -->
  <xsl:template name="BooleanXOR">
   <xsl:param name="value1" select="number(0)"/>
   <xsl:param name="value2" select="number(0)"/>
   <!-- recurse parameters -->
   <xsl:param name="bitval" select="number(2147483648)"/>
   <xsl:param name="accum" select="number(0)"/>
   <!-- calc bits present on values -->
   <xsl:variable name="bit1" select="floor($value1 div $bitval)"/>
   <xsl:variable name="bit2" select="floor($value2 div $bitval)"/>
   <!-- do the XOR on the bits -->
   <xsl:variable name="thisbit">
   <xsl:choose>
   <xsl:when test="(($bit1 != 0) and ($bit2 = 0)) or (($bit1 = 0) and ($bit2
  != 0))"><xsl:value-of select="$bitval"/></xsl:when>
   <xsl:otherwise>0</xsl:otherwise>
   </xsl:choose>
   </xsl:variable>
   <!-- if last recurse then output the value -->
   <xsl:choose>
   <xsl:when test="$bitval = 1"><xsl:value-of select="$accum + $thisbit"/></xsl:when>
   <xsl:otherwise>
   <!-- recurse required -->
   <xsl:call-template name="BooleanXOR">
   <xsl:with-param name="value1" select="$value1 mod $bitval"/>
   <xsl:with-param name="value2" select="$value2 mod $bitval"/>
   <xsl:with-param name="bitval" select="$bitval div 2"/>
   <xsl:with-param name="accum" select="$accum + $thisbit"/>
   </xsl:call-template>
   </xsl:otherwise>
   </xsl:choose>
  </xsl:template>
  
  
  
    
文章录入:junsan    责任编辑:junsan 
  • 上一篇文章:
  • 下一篇文章:
  • 最新热点 最新推荐 相关文章
    Java中的XML解析器
    xml反序列化时,如何生成与之对应的类文件一…
    SQLXML系列之一:SQLXML初体验——用XML代替…
    利用Digester把XML转换为Java对象
    Ajax程序设计入门 3
    Ajax程序设计入门 2
    Ajax程序设计入门 1
    Java XML文件处理
    浅析Eclipse建模框架(EMF)及其动态能力
    构建基于Web/XML的信息集成研究2
     网友评论:(最新10条。只代表网友观点,与本站立场无关!)