频道直达 - 专题 - 新闻 - 技巧 - 组网 - 开发 - 安全 - web编程 - 图像 - 操作系统 - 数据库 - 教育 - 旅游 - 健康 - 时尚 - 驱动 - 软件 - 游戏 - 多媒体 - ERP - 讨论组

XSL中几个封装的函数

来源:aspcool 作者: 出处:巧巧读书 2007-01-30 进入讨论组
  • 关 键 词:
     布尔操作函数
  
  <!-- ======================================================== -->
  <!-- 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>请保留地址 http://www.qqread.com/dotnet/k295784.html进入讨论组讨论。
收藏此文】【 】【打印】【关闭
相关图文阅读
频道图文推荐
健 康 咨 询
时 尚 咨 询
巧巧读书宗旨
相关专题
讨论组问题推荐
站内各频道最新更新文档
站内最新制作专题
热门关键字导读
Photoshop教 程照片处理 照片制作 PS快捷键 抠图
计 算 机 故 障XP系统修复
艺 术 与 设 计设计 流媒体 设计欣赏 边框
计 算 机 安 全ARP
站内频道文章精选
巧巧电脑频道编辑信箱  告诉我们您想看的专题或文章