Convert a hexadecimal number to an integer in XSLT

后端 未结 2 1870
星月不相逢
星月不相逢 2021-01-14 04:21

I need to convert a hexadecimal value to an integer value, how can I do that using XSLT?

For example, if the input is hexadecimal FF, my output should b

2条回答
  •  伪装坚强ぢ
    2021-01-14 04:38

    Edit: Sorry, my bad I just noted the OP asked for hex to decimal and not the other way around.

    hexToDecimal template for XSLT-1.0:

    
        
        
        
            0
            
                
                    
                        
                            
                        
                    
                
                
            
        
    
    

    This needs math:power from exslt http://exslt.org/math/


    hexToDecimal function for XSLT-2.0:

    
        
        
        
            
                
            
            
                Provided value is not hexadecimal...
                
            
        
    
    
    
        
        
        
    
    

    Leaving this here, also it was not asked for, it might still be useful.

    There is no directly implemented function in xslt, so you would have to write it yourself.

    Here's a template for XSLT 1.0:

    
        
        
            
                
            
            
        
    
    

    You call it like this:

    
        4095
    
    

    And a function for XSLT 2.0:

    
        
        
            
        
    
    

    Which you can call like this:

    
    

    Be aware that you have to declare the namespace for the function in you stylesheet.

提交回复
热议问题