Craig D.
2004-11-10 05:32:02 UTC
I need to process a large number of combinations of nodes, testing whether or
not a certain bit is set in a number of key positions. It is possible,
though not desirable to div and mod to strip away the superfluous bits......
I have tried using the following (assuing x is a variable which contains the
flag.....)
<xsl:if test="($x and 1) = 1">
<!-- we know that bit 0 is set.......
</xsl:test>
This doesn't seem to return the answer I was expecting. For example, if the
flag has a value of 3, this means that bit 0 and 1 are both on....
I have written a small javascript function which works fine when using xslt,
function flag(a, b) {
return((a & (1<<b)) == (1<<b));
}
This correctly returns true or false depending on whether the bit
(zero-based) is set.
In my situation, however, I am dynamically selecting nodes using another
javascript function
function selectNodes(doc, xpath) {
return (doc[0].selectNodes(xpath));
}
This leaves me with the option to either:
(a) find a pure xpath equivalent to execute the bitwise comparison; or
(b) find a way to call an XSLT extension function from the selectNodes
method of the IXMLDOMNode object listed above (doc[0]).
Any help would be most appreciated.
Regards
not a certain bit is set in a number of key positions. It is possible,
though not desirable to div and mod to strip away the superfluous bits......
I have tried using the following (assuing x is a variable which contains the
flag.....)
<xsl:if test="($x and 1) = 1">
<!-- we know that bit 0 is set.......
</xsl:test>
This doesn't seem to return the answer I was expecting. For example, if the
flag has a value of 3, this means that bit 0 and 1 are both on....
I have written a small javascript function which works fine when using xslt,
function flag(a, b) {
return((a & (1<<b)) == (1<<b));
}
This correctly returns true or false depending on whether the bit
(zero-based) is set.
In my situation, however, I am dynamically selecting nodes using another
javascript function
function selectNodes(doc, xpath) {
return (doc[0].selectNodes(xpath));
}
This leaves me with the option to either:
(a) find a pure xpath equivalent to execute the bitwise comparison; or
(b) find a way to call an XSLT extension function from the selectNodes
method of the IXMLDOMNode object listed above (doc[0]).
Any help would be most appreciated.
Regards