Altova Mailing List Archives>Archive Index >microsoft.public.xml Archive Home >Recent entries >Thread Prev - Re: data conversion in xslt? >Thread Next - Re: data conversion in xslt? Re: data conversion in xslt?To: NULL Date: 9/1/2005 5:58:00 PM Hi guys, being interrested int he topic, i was reading this and checking the solution found on the mentioned link. After seeying that i had something like... MMhhh, don't think 4 or 5 XSLT's are really needed... Lets see if I can figure something out here. So, this is the resulting XSLT i made. It works using a stack mechanism, so to high a values for the "Hex" will eventually break the XSLT transformation with a Stack overflow (1 stack level per character). I also saw that moving beyond the "12 character hexadecimal figure" makes the result unreliable (rounding issues on large numbers) 488df73faa9d = 79774575733405 still worked correctly. ;============== XSLT STARTS HERE ================ <?xml version="1.0" encoding="UTF-8"?> <!-- Hex 2 Dec converter in XSLT without extensions --> <!-- The following XSLT has been written for educational purposes only --> <!-- If you would like to use this template as-is in a commercial product, please contact me first --> <!-- Marvin Smit, marvin.smit@g... --> <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"> <xsl:output method="xml" version="1.0" encoding="UTF-8" indent="yes"/> <xsl:template match="hex"> <xsl:variable name="HexStr" select="translate(text(),'abcdef','ABCDEF')"/> <xsl:call-template name="Hex2Dec"> <xsl:with-param name="HexVal" select="$HexStr"/> <xsl:with-param name="Multiplier" select="'1'"/> </xsl:call-template> </xsl:template> <xsl:template name="Hex2Dec"> <xsl:param name="HexVal"/> <xsl:param name="Multiplier"/> <xsl:variable name="HexCharVal"> <xsl:call-template name="HexChar2Dec"> <xsl:with-param name="HexChar" select="substring($HexVal, string-length($HexVal), 1)"/> </xsl:call-template> </xsl:variable> <xsl:variable name="HexRest"> <xsl:if test="string-length($HexVal) > 1"> <xsl:call-template name="Hex2Dec"> <xsl:with-param name="HexVal" select="substring($HexVal, 1, string-length($HexVal) - 1)"/> <xsl:with-param name="Multiplier" select="$Multiplier * 16"/> </xsl:call-template> </xsl:if> <xsl:if test="string-length($HexVal) <= 1"> <xsl:value-of select="0"/> </xsl:if> </xsl:variable> <xsl:value-of select="($HexCharVal * $Multiplier) + $HexRest"/> </xsl:template> <xsl:template name="HexChar2Dec"> <xsl:param name="HexChar"/> <xsl:choose> <xsl:when test="$HexChar = 'A'">10</xsl:when> <xsl:when test="$HexChar = 'B'">11</xsl:when> <xsl:when test="$HexChar = 'C'">12</xsl:when> <xsl:when test="$HexChar = 'D'">13</xsl:when> <xsl:when test="$HexChar = 'E'">14</xsl:when> <xsl:when test="$HexChar = 'F'">15</xsl:when> <xsl:otherwise><xsl:value-of select="$HexChar"/></xsl:otherwise> </xsl:choose> </xsl:template> </xsl:stylesheet> ;============== XSLT ENDS HERE ================ ;============== XML SAMPLE STARTS HERE ================ <?xml version="1.0" encoding="UTF-8"?> <hex>488df73faa9d</hex> ;============== XML SAMPLE ENDS HERE ================ Hope this helps, Marvin Smit On Thu, 1 Sep 2005 06:58:15 +1000, "Dimitre Novatchev" <x@y...> wrote: > >"Illustris" <Illustris@d...> wrote in message >news:F173103B-2B85-4C78-B7A9-B5A9D10F2BDC@m...... >> Hello, >> >> I am attempting to convert a hexidecimal value to decimal value from an >> XML >> file. Can this be done in XSLT for output to HTML? > >Yes. > > http://www.biglist.com/lists/xsl-list/archives/200111/msg00835.html > > >Cheers, >Dimitre Novatchev > | ||||||
| Company | Legal | Press | Partners | Careers | Sitemap | Contact Us | Altova Blog | Mobile | Full Site | |||
|
