xsl-list
[Top] [All Lists]

Create a bit mask ?

2004-11-09 14:54:09
I need to convert a number of elements into a single
element with a bit mask as its value. Here is a some
sample source XML snippet:

<Rule Name="Rule1">
        <Tag Name="Tag1"/>
        <Tag Name="Tag2"/>
</Rule>
<Rule Name="Rule2">
        <Tag Name="Tag1"/>
        <Tag Name="Tag3"/>
</Rule>

<Tags>
        <Tag Name="Tag1">
                <Id>0</Id>
        </Tag>
        <Tag Name="Tag2">
                <Id>1</Id>
        </Tag>
        <Tag Name="Tag3">
                <Id>2</Id>
        </Tag>
</Tags>


I need to convert this into:

<Rule Name="Rule1">
        <TagMap>-4</TagMap>
</Rule>
<Rule Name="Rule2">
        <TagMap>-6</TagMap>
</Rule>

The value in TagMap is a 32 bit bit-mask which
contains a 0 if the Tag applies to the rule and a 1 if
it does not. The bit position for a tag is determined
by the Tag's ID value (Starting from the right most
bit)

So the map for Rule1 is -4 which is
11111111111111111111111111111100 in binary. The two
zeros correspond to Tag1 (Id 0) and Tag2 (Id 1).
Map value for Rule2 is -6 which is 
11111111111111111111111111111010 corresponding to Tag1
(Id 0) and Tag3 (Id 2).

Can anyone help with this? I feel handicapped without
a processing loop construct and being able to redefine
the value of a variable! I am limited to using XSLT
1.0

Thanks in advance.
-Saba


<Prev in Thread] Current Thread [Next in Thread>