bit-masking in xslt is easy

2007-08-09 @ 12:55#

i've been working on a long-running project that does almost all rendering via XSLT. one of the tasks that came up today was server-side transformation of XML data that requires suppressing certain information based on the passed-in auth-level bit-mask (in integer form).

i did some digging and was a bit concerned about the complexity (and sheer size) of several of the solutions. but i found one that had a nice *kernel* of wisdom that finally tripped a light-bulb over my head. it's simple modulo math![Doh!]

<xsl:if test="(($auth mod ($download * 2) ) - ($auth mod $download))=$download"> <!-- show download options --> </xsl:if>

for most, this might seem fundamental, but for me (having successfully avoided most math throughout my school years) this is a bright light.

code