Hi Everyone,

I have an interesting problem: I need to convert a 16-digit (64-bit)
Hex value in a database to an Base-10 number. I had first tried ECMA
script but it would give incorrect results for such large numbers, so I
made an XSLT stylesheet that uses the BigInteger Java class.


Code:
--------------------
<?xml version="1.0" encoding="UTF-8"?><xsl:stylesheet exclude-result-prefixes="query cmd dncv" version="1.0" xmlns:cmd="http://www.novell.com/nxsl/java/com.novell.nds.dirxml.driver.XdsCommandProcessor" xmlns:dncv="http://www.novell.com/nxsl/java/com.novell.nds.dirxml.driver.DNConverter" xmlns:query="http://www.novell.com/nxsl/java/com.novell.nds.dirxml.driver.XdsQueryProcessor" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"><!-- parameters passed in from the DirXML engine -->
<xslaram name="srcQueryProcessor"/>
<xslaram name="destQueryProcessor"/>
<xslaram name="srcCommandProcessor"/>
<xslaram name="destCommandProcessor"/>
<xslaram name="dnConverter"/>
<xslaram name="fromNds"/>
<!-- identity transformation template -->
<xsl:template match="node()|@*">
<xsl:copy>
<xsl:apply-templates select="@*|node()"/>
</xsl:copy>
</xsl:template>
<!-- This template converts value of PIN from Base-16 to Base-10 using Java's BigInteger class -->

<xsl:template match="*[@attr-name='PIN']//value" xmlns:intClass="http://www.novell.com/nxsl/java/java.math.BigInteger">
<xsl:copy>
<xsl:value-of select="intClass:new(./text(),16)"/>
</xsl:copy>
</xsl:template>
</xsl:stylesheet>
--------------------


This should be similar to what happens in the following snipped of Java
code:

Code:
--------------------
BigInteger i= new BigInteger(str,16);
--------------------



This seemed to work great at first with the test data I threw at it.
However, I have found there are some values that do not convert
correctly, as I have seen in both the trace and in the Simulator in
Designer.

Example:
Input:

Code:
--------------------
<?xml version="1.0" encoding="UTF-8"?><nds dtdversion="3.5" ndsversion="8.x">
<source>
<product version="?.?.?.?">DirXML</product>
<contact>Novell, Inc.</contact>
</source>
<input>
<modify class-name="CARD">
<modify-attr attr-name="PIN">
<add-value>
<value type="string">FFFFFFFFFFFFFFFF</value>
</add-value>
</modify-attr>
</modify>
</input>
</nds>
--------------------


Output:
Code:
--------------------

<?xml version="1.0" encoding="UTF-8"?><nds dtdversion="3.5" ndsversion="8.x">
<source>
<product version="?.?.?.?">DirXML</product>
<contact>Novell, Inc.</contact>
</source>
<input>
<modify class-name="CARD">
<modify-attr attr-name="PIN">
<add-value>
<value type="string">18446744073709551616</value>
</add-value>
</modify-attr>
</modify>
</input>
</nds>
--------------------


FFFFFFFFFFFFFFFF = 18446744073709551615, not 18446744073709551616.
There are other values which fail as well and are off by differing
amounts. For example, 42CE0A00FCFF12E0 becomes 4813796051066491904
(correct value: 4813796051066491616). My compiled java test code works
correctly for all values I have tried.

Am I missing something? Is this a known issue? Any possible
workarounds?

This is on Designer 3.0.1, IDM 3.6 on eDir 8.8 SP5

Thanks!


--
ibutler
------------------------------------------------------------------------
ibutler's Profile: http://forums.novell.com/member.php?userid=8203
View this thread: http://forums.novell.com/showthread.php?t=388753