• λ我爱Aspx >> Asp.Net >> XSL中几个封装的函数
  • XSL中几个封装的函数

  • :aspxer  Դ:internet  :2007-5-15 20:46:31  ؼ:
  • 布尔操作函数

    <!-- ======================================================== --> <!-- 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>

    上一篇: 在XSL中得到任意节点在DOM树中的深度

    下一篇: 利用XmlTextWriter类增强XML数据的可读性

    Ҷƪл˵?
  • һƪ利用XmlTextWriter类增强XML数据的可读性
    һƪ在XSL中得到任意节点在DOM树中的深度