Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 856359
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 15, 20262026-05-15T08:13:19+00:00 2026-05-15T08:13:19+00:00

my xml document looks somewhat like that (Values are both xsl:hexBinary ): <Offsets> <Offset>

  • 0

my xml document looks somewhat like that (Values are both xsl:hexBinary):

<Offsets>  
    <Offset>  
        <Name>ErrorOffset</Name>  
        <Value>DD</Value>  
    </Offset>  
    <Offset>  
        <Name>OtherOffset</Name>  
        <Value>FF</Value>  
    </Offset>  
</Offsets>  
<Value>  
    <Name>Error1</Name>  
    <Code>01</Code>  
</Value>
<Value>  
    <Name>Error2</Name>  
    <Code>02</Code>  
    <Offset>ErrorOffset</Offset>  
</Value>

now i want to transform this to a new xml file:

<Value>  
    <Name>Error1</Name>  
    <Code>01</Code>  
</Value>
<Value>  
    <Name>Error2</Name>  
    <Code>DF</Code>  
</Value>

All that should happen is adding <Offset> to the basic <Value>. But plain + returns NaN and sum() expects only one parameter. XSLT and XPATH are quite nice, but it goes on my nerves that easy operations like adding two hex values just dont work as easy as it should.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-15T08:13:19+00:00Added an answer on May 15, 2026 at 8:13 am

    I never developed a conersión function for hex numbers. This is an example of a function that is reverse to the example of Dimitre. I think it would be possible to further reduce the stylesheet. It is also worth noting that the conversion function can be parameterized and generalized to any base.

    <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"> 
    
    <xsl:key name="offset" match="Offset/Value" use="../Name" />     
    
    <xsl:template match="@*|node()"> 
        <xsl:copy> 
            <xsl:apply-templates select="@*|node()"/> 
        </xsl:copy> 
    </xsl:template> 
    
    <xsl:template match="Offsets|Offset" />
    
    <xsl:template match="Code/text()[../../Offset]" >
        <xsl:variable name="code">
            <xsl:call-template name="hex2dec">
                <xsl:with-param name="num" select="." />
            </xsl:call-template>
        </xsl:variable>
        <xsl:variable name="offset">
            <xsl:call-template name="hex2dec">
                <xsl:with-param name="num" select="key('offset',../../Offset)" />
            </xsl:call-template>
        </xsl:variable>
        <xsl:call-template name="dec2hex">
            <xsl:with-param name="dec" select="$code + $offset" />
        </xsl:call-template>
    </xsl:template>
    
    <xsl:template name="hex2dec">
        <xsl:param name="num" />
        <xsl:param name="hex" select="translate($num,'abcdef','ABCDEF')"/>
        <xsl:param name="acc" select="0" />
        <xsl:choose>
            <xsl:when test="string-length($hex)">
                <xsl:call-template name="hex2dec">
                    <xsl:with-param name="hex" select="substring($hex,2,string-length($hex))" />
                    <xsl:with-param name="acc" select="$acc * 16 + string-length(substring-before('0123456789ABCDEF',substring($hex,1,1)))" />
                </xsl:call-template>
            </xsl:when>
            <xsl:otherwise>
                <xsl:value-of select="$acc" />
            </xsl:otherwise>
        </xsl:choose>
    </xsl:template>
    
    <xsl:template name="dec2hex">
        <xsl:param name="dec" />
        <xsl:if test="$dec >= 16">
            <xsl:call-template name="dec2hex">
                <xsl:with-param name="dec" select="floor($dec div 16)" />
            </xsl:call-template>
        </xsl:if>
        <xsl:value-of select="substring('0123456789ABCDEF', ($dec mod 16) + 1, 1)" />
    </xsl:template>
    
    </xsl:stylesheet> 
    

    Edit: Recently I just realized here is cross references. Therefore keys should be used.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Ask A Question

Stats

  • Questions 467k
  • Answers 467k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer settimeofday() takes a struct timeval * as first argument, so… May 16, 2026 at 1:54 am
  • Editorial Team
    Editorial Team added an answer A bundle is a structure used for packaging software on… May 16, 2026 at 1:54 am
  • Editorial Team
    Editorial Team added an answer A token would be fine, I would use an MD5… May 16, 2026 at 1:54 am

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.