XSLT (2.0) format number binary or hex

R

RolfK

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
 
P

Pavel Lepin

RolfK said:
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
xmlns:xs="http://www.w3.org/2001/XMLSchema"
xmlns:rsl="http://ranselett.net/xslt2lib"
name="rsl:conv-dec-to-numsys"
as="xs:string">
<xsl:param name="dec" as="xs:integer"/>
<xsl:param 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.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,994
Messages
2,570,223
Members
46,810
Latest member
Kassie0918

Latest Threads

Top