Ureader.com  
Microsoft software help and Community
   home   |   control panel login   |   archive   |  
 
XML
data.xmlanalysis
mappoint.webservice
msf
msxml-webrelease
netmyservices.sdk
passport.sdk
soap
soapsdk
uddi.general
uddi.programming
uddi.specification
xml
xmlsqlwebrelease
xsl
  
 
date: Tue, 12 Feb 2008 11:37:54 +0000,    group: microsoft.public.xsl        back       


Is it possible to format a number as hexadecimal?   
Is there any way in XSLT to convert a numerical value into a
hexadecimal representation?

Something like a format-number-hex() function perhaps?

Dave Lowndes
date: Tue, 12 Feb 2008 11:37:54 +0000   author:   David Lowndes lid

Re: Is it possible to format a number as hexadecimal?   
David Lowndes wrote:
> Is there any way in XSLT to convert a numerical value into a
> hexadecimal representation?
> 
> Something like a format-number-hex() function perhaps?

It should be possible to implement a named template to perform the 
conversion 
<URL:http://www.google.de/search?hl=en&q=XSLT+decimal+to+hex+conversion&btnG=Google+Search&meta=>. 
Or use an extension function.
Which XSLT processor are you targetting?



-- 

	Martin Honnen --- MVP XML
	http://JavaScript.FAQTs.com/
date: Tue, 12 Feb 2008 14:09:07 +0100   author:   Martin Honnen

Re: Is it possible to format a number as hexadecimal?   
>It should be possible to implement a named template to perform the 
>conversion 
><URL:http://www.google.de/search?hl=en&q=XSLT+decimal+to+hex+conversion&btnG=Google+Search&meta=>. 

Ah, something like this maybe?:

http://www.stylusstudio.com/xsllist/200303/post80360.html

>Or use an extension function.
>Which XSLT processor are you targetting?

I'm currently using the MS .Net XSLT facilities but I'm considering
switching to another engine for V2 facilities.

Dave
date: Tue, 12 Feb 2008 13:59:28 +0000   author:   David Lowndes lid

Re: Is it possible to format a number as hexadecimal?   
David Lowndes wrote:

>> Or use an extension function.
>> Which XSLT processor are you targetting?
> 
> I'm currently using the MS .Net XSLT facilities 


You could use an extension function then implemented in C# e.g.

   <msxsl:script implements-prefix="mf" language="C#">
     public string toHex (double n)
     {
       return ((int)n).ToString("X");
     }
   </msxsl:script>

   <xsl:template match="some-element"
     xmlns:mf="http://example.com/2008/functions">

       <xsl:value-of select="mf:toHex(number(.))"/>

   </xsl:template>

-- 

	Martin Honnen --- MVP XML
	http://JavaScript.FAQTs.com/
date: Tue, 12 Feb 2008 15:34:32 +0100   author:   Martin Honnen

Re: Is it possible to format a number as hexadecimal?   
>You could use an extension function then implemented in C# e.g.

That's the first I've ever heard of such things - that looks much more
elegant :) - I'll give that a go.

I'm considering using a different XSLT processor because of a bug
(https://connect.microsoft.com/VisualStudio/feedback/ViewFeedback.aspx?FeedbackID=314173).
Is there an elegant way of doing the hex output in XSLT 2?

Dave
date: Tue, 12 Feb 2008 15:35:23 +0000   author:   David Lowndes lid

Re: Is it possible to format a number as hexadecimal?   
David Lowndes wrote:

> Is there an elegant way of doing the hex output in XSLT 2?

Instead of using a named template and xsl:call-template in XSLT 1.0 you 
can write a named function in XSLT 2.0 and call it with XPath function 
call syntax everywhere you need it.


-- 

	Martin Honnen --- MVP XML
	http://JavaScript.FAQTs.com/
date: Tue, 12 Feb 2008 17:52:34 +0100   author:   Martin Honnen

Re: Is it possible to format a number as hexadecimal?   
>Instead of using a named template and xsl:call-template in XSLT 1.0 you 
>can write a named function in XSLT 2.0 and call it with XPath function 
>call syntax everywhere you need it.

Thanks once again for all the help Martin.

I've tried the named template & the C# script methods, and I'll go
with the C# script for now as it provides better (easy) control over
the formatting (the result looks better presented with 8 fixed
characters - "X8").

Cheers
Dave
date: Wed, 13 Feb 2008 16:59:40 +0000   author:   David Lowndes lid

Google
 
Web ureader.com


    COPYRIGHT 2007, YARDI TECHNOLOGY LIMITED, ALL RIGHT RESERVE  |   contact us