Altova Mailing List Archives>Archive Index >comp.text.xml Archive Home >Recent entries >Thread Prev - XSLT binary to decimal [Thread Next] Re: XSLT binary to decimalTo: NULL Date: 11/5/2008 6:49:00 PM RolfK wrote: > I have to convert a string of "10101010111"to a decimal number. > > What is the standard solution in XSLT2.0 ? http://www.dpawson.co.uk/xsl/rev2/functions2.html#d16818e694 has an example of hex to decimal conversion. I applied that to binary to decimal conversion as follows: <xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:mf="http://example.com/2008/mf" exclude-result-prefixes="xsd mf" version="2.0"> <xsl:function name="mf:bin2dec" as="xsd:integer"> <xsl:param name="input" as="xsd:string"/> <xsl:sequence select="if (string-length($input) eq 1) then xsd:integer($input) else 2 * mf:bin2dec(substring($input, 1, string-length($input) - 1)) + xsd:integer(substring($input, string-length($input)))"/> </xsl:function> <xsl:template match="/"> <xsl:value-of select="mf:bin2dec('10101010111')"/> </xsl:template> </xsl:stylesheet> but I have not tested in detail. -- Martin Honnen http://JavaScript.FAQTs.com/ | ||||||
| Company | Legal | Press | Partners | Careers | Sitemap | Contact Us | Altova Blog | Mobile | Full Site | |||
|
