my xml document looks somewhat like that (Values are both xsl:hexBinary
):
<Offsets>
<Offset>
<Name>ErrorOffset</Name>
<Value>DD</Value>
</Offset>
<Offset>
<Name>OtherOffset</Name>
<Value>FF</Value>
</Offset>
</Offsets>
<Value>
<Name>Error1</Name>
<Code>01</Code>
</Value>
<Value>
<Name>Error2</Name>
<Code>02</Code>
<Offset>ErrorOffset</Offset>
</Value>
now i want to transform this to a new xml file:
<Value>
<Name>Error1</Name>
<Code>01</Code>
</Value>
<Value>
<Name>Error2</Name>
<Code>DF</Code>
</Value>
All that should happen is adding <Offset>
to the basic <Value>
. But plain +
returns NaN
and sum()
expects only one parameter. XSLT and XPATH are quite nice, but it goes on my nerves that easy operations like adding two hex values just dont work as easy as it should.
This is how I do it without using XSLT:
Hex to number
The reverse function is simpler:
Both assume your hex digits always have two digits.
Here is a solution, which combines the conversion of hex to decimal values as present in FXSL with a borrowed non-FXSL template for convertion of decimal to hex.
This transformation:
when applied on this XML document:
produces the correct, wanted result:
I never developed a conersión function for hex numbers. This is an example of a function that is reverse to the example of Dimitre. I think it would be possible to further reduce the stylesheet. It is also worth noting that the conversion function can be parameterized and generalized to any base.
Edit: Recently I just realized here is cross references. Therefore keys should be used.