布爾操作函數
<!
========================================================
>
<!
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:value
of 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:value
of select=
$accum + $thisbit
/></xsl:when>
<xsl:otherwise>
<!
recurse required
>
<xsl:call
template name=
BooleanOR
>
<xsl:with
param name=
value
select=
$value
mod $bitval
/>
<xsl:with
param name=
value
select=
$value
mod $bitval
/>
<xsl:with
param name=
bitval
select=
$bitval div
/>
<xsl:with
param name=
accum
select=
$accum + $thisbit
/>
</xsl:call
template>
</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:value
of 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:value
of select=
$accum + $thisbit
/></xsl:when>
<xsl:otherwise>
<!
recurse required
>
<xsl:call
template name=
BooleanAND
>
<xsl:with
param name=
value
select=
$value
mod $bitval
/>
<xsl:with
param name=
value
select=
$value
mod $bitval
/>
<xsl:with
param name=
bitval
select=
$bitval div
/>
<xsl:with
param name=
accum
select=
$accum + $thisbit
/>
</xsl:call
template>
</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:value
of 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:value
of select=
$accum + $thisbit
/></xsl:when>
<xsl:otherwise>
<!
recurse required
>
<xsl:call
template name=
BooleanXOR
>
<xsl:with
param name=
value
select=
$value
mod $bitval
/>
<xsl:with
param name=
value
select=
$value
mod $bitval
/>
<xsl:with
param name=
bitval
select=
$bitval div
/>
<xsl:with
param name=
accum
select=
$accum + $thisbit
/>
</xsl:call
template>
</xsl:otherwise>
</xsl:choose>
</xsl:template>
From:http://tw.wingwit.com/Article/program/net/201311/13884.html