XSLT (2.0) format number binary or hex

Discussion in 'XML' started by RolfK, Jan 8, 2008.

  1. RolfK

    RolfK Guest

    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
    RolfK, Jan 8, 2008
    #1
    1. Advertising

  2. RolfK

    Pavel Lepin Guest

    RolfK <> wrote in
    <>:
    > 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.

    --
    ....also, I submit that we all must honourably commit seppuku
    right now rather than serve the Dark Side by producing the
    HTML 5 spec.
    Pavel Lepin, Jan 8, 2008
    #2
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Replies:
    10
    Views:
    6,181
    Neredbojias
    Aug 19, 2005
  2. Bengt Richter
    Replies:
    6
    Views:
    461
    Juha Autero
    Aug 19, 2003
  3. Chris Rebert
    Replies:
    1
    Views:
    382
    Grant Edwards
    Nov 5, 2010
  4. Tim Chase
    Replies:
    2
    Views:
    549
    Tim Chase
    Nov 6, 2010
  5. chirs
    Replies:
    3
    Views:
    159
    Dr John Stockton
    Dec 1, 2003
Loading...

Share This Page