熱點推薦:
您现在的位置: 電腦知識網 >> 編程 >> .NET編程 >> 正文

XSL中幾個封裝的函數

2022-06-13   來源: .NET編程 
     布爾操作函數
  
  <! ======================================================== >
  <! Function: BooleanOR(<value><value>) => number >
  <! Parameters: >
  <! <value> the first number to be ORed >
  <! <value> the second number to be ORed >
  <! NB Only works with unsigned ints! >
  <xsl:template name=BooleanOR>
   <xsl:param name=value select=number()/>
   <xsl:param name=value select=number()/>
   <! recurse parameters >
   <xsl:param name=bitval select=number()/>
   <xsl:param name=accum select=number()/>
   <! calc bits present on values >
   <xsl:variable name=bit select=floor($value div $bitval)/>
   <xsl:variable name=bit select=floor($value div $bitval)/>
   <! do the OR on the bits >
   <xsl:variable name=thisbit>
   <xsl:choose>
   <xsl:when test=($bit != ) or ($bit != )><xsl:valueof select=$bitval/></xsl:when>
   <xsl:otherwise></xsl:otherwise>
   </xsl:choose>
   </xsl:variable>
   <! if last recurse then output the value >
   <xsl:choose>
   <xsl:when test=$bitval = ><xsl:valueof select=$accum + $thisbit/></xsl:when>
   <xsl:otherwise>
   <! recurse required >
   <xsl:calltemplate name=BooleanOR>
   <xsl:withparam name=value select=$value mod $bitval/>
   <xsl:withparam name=value select=$value mod $bitval/>
   <xsl:withparam name=bitval select=$bitval div />
   <xsl:withparam name=accum select=$accum + $thisbit/>
   </xsl:calltemplate>
   </xsl:otherwise>
   </xsl:choose>
  </xsl:template>
  
  <! ======================================================== >
  <! Function: BooleanAND(<value><value>) => number >
  <! Parameters: >
  <! <value> the first number to be ANDed >
  <! <value> the second number to be ANDed >
  <! NB Only works with unsigned ints! >
  <xsl:template name=BooleanAND>
   <xsl:param name=value select=number()/>
   <xsl:param name=value select=number()/>
   <! recurse parameters >
   <xsl:param name=bitval select=number()/>
   <xsl:param name=accum select=number()/>
   <! calc bits present on values >
   <xsl:variable name=bit select=floor($value div $bitval)/>
   <xsl:variable name=bit select=floor($value div $bitval)/>
   <! do the AND on the bits >
   <xsl:variable name=thisbit>
   <xsl:choose>
   <xsl:when test=($bit != ) and ($bit != )><xsl:valueof select=$bitval/></xsl:when>
   <xsl:otherwise></xsl:otherwise>
   </xsl:choose>
   </xsl:variable>
   <! if last recurse then output the value >
   <xsl:choose>
   <xsl:when test=$bitval = ><xsl:valueof select=$accum + $thisbit/></xsl:when>
   <xsl:otherwise>
   <! recurse required >
   <xsl:calltemplate name=BooleanAND>
   <xsl:withparam name=value select=$value mod $bitval/>
   <xsl:withparam name=value select=$value mod $bitval/>
   <xsl:withparam name=bitval select=$bitval div />
   <xsl:withparam name=accum select=$accum + $thisbit/>
   </xsl:calltemplate>
   </xsl:otherwise>
   </xsl:choose>
  </xsl:template>
  
  <! ======================================================== >
  <! Function: BooleanXOR(<value><value>) => number >
  <! Parameters: >
  <! <value> the first number to be XORed >
  <! <value> the second number to be XORed >
  <! NB Only works with unsigned ints! >
  <xsl:template name=BooleanXOR>
   <xsl:param name=value select=number()/>
   <xsl:param name=value select=number()/>
   <! recurse parameters >
   <xsl:param name=bitval select=number()/>
   <xsl:param name=accum select=number()/>
   <! calc bits present on values >
   <xsl:variable name=bit select=floor($value div $bitval)/>
   <xsl:variable name=bit select=floor($value div $bitval)/>
   <! do the XOR on the bits >
   <xsl:variable name=thisbit>
   <xsl:choose>
   <xsl:when test=(($bit != ) and ($bit = )) or (($bit = ) and ($bit
  != ))><xsl:valueof select=$bitval/></xsl:when>
   <xsl:otherwise></xsl:otherwise>
   </xsl:choose>
   </xsl:variable>
   <! if last recurse then output the value >
   <xsl:choose>
   <xsl:when test=$bitval = ><xsl:valueof select=$accum + $thisbit/></xsl:when>
   <xsl:otherwise>
   <! recurse required >
   <xsl:calltemplate name=BooleanXOR>
   <xsl:withparam name=value select=$value mod $bitval/>
   <xsl:withparam name=value select=$value mod $bitval/>
   <xsl:withparam name=bitval select=$bitval div />
   <xsl:withparam name=accum select=$accum + $thisbit/>
   </xsl:calltemplate>
   </xsl:otherwise>
   </xsl:choose>
  </xsl:template>
From:http://tw.wingwit.com/Article/program/net/201311/13884.html
    推薦文章
    Copyright © 2005-2022 電腦知識網 Computer Knowledge   All rights reserved.