Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > XML > XSLT (2.0) format number binary or hex

Reply
Thread Tools

XSLT (2.0) format number binary or hex

 
 
RolfK
Guest
Posts: n/a
 
      01-08-2008
Dear All,

can anyone help me with a peace of xslt which converts a number to a
binary or hex string ?

I even can not find a power operator in xslt / xpath 2.0.

Any help is highly welcome as I ned to solve this quickly.

Thanks

Rolf
 
Reply With Quote
 
 
 
 
Pavel Lepin
Guest
Posts: n/a
 
      01-08-2008

RolfK <(E-Mail Removed)> wrote in
<(E-Mail Removed)>:
> can anyone help me with a peace of xslt which converts a
> number to a binary or hex string ?
>
> I even can not find a power operator in xslt / xpath 2.0.


Why would you need a power operator? And if you need it, why
not write one yourself?

Anyway,

<xsl:function
xmlnss="http://www.w3.org/2001/XMLSchema"
xmlns:rsl="http://ranselett.net/xslt2lib"
name="rsl:conv-dec-to-numsys"
as="xs:string">
<xslaram name="dec" as="xs:integer"/>
<xslaram name="base" as="xs:integer"/>
<xsl:variable name="chr" as="xs:string"
select="'0123456789abcdef'"/>
<xsl:if
test=
"
(1 gt $base) or (string-length($chr) lt $base)
">
<xsl:message terminate="yes">OOPS.</xsl:message>
</xsl:if>
<xsl:variable name="car" as="xs:integer"
select="$dec mod $base"/>
<xsl:variable name="cdr" as="xs:integer"
select="($dec div $base) cast as xs:integer"/>
<xsl:value-of
select=
"
concat
(
if ($base lt $dec)
then rsl:conv-dec-to-numsys($cdr,$base)
else '',
substring($chr,1+$car,1)
)
"/>
</xsl:function>

I have a dark suspicion Dimitre Novatchev already has
something functionally similar but better in that FXSL lib
of his.

--
....also, I submit that we all must honourably commit seppuku
right now rather than serve the Dark Side by producing the
HTML 5 spec.
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Re: Using %x to format number to hex and number of digits Tim Chase Python 2 11-06-2010 01:22 AM
Re: Using %x to format number to hex and number of digits Chris Rebert Python 1 11-05-2010 07:05 PM
Hex Color Codes - Hex 6 <=> Hex 3 lucanos@gmail.com HTML 10 08-18-2005 11:21 PM
How to convert an hex string to a Hex number chirs Javascript 3 12-01-2003 10:06 PM
hex(-5) => Futurewarning: ugh, can't we have a better hex than '-'[:n<0]+hex(abs(n)) ?? Bengt Richter Python 6 08-19-2003 07:33 AM



Advertisments