-----------------------------------------------------------

New Message on BDOTNET

-----------------------------------------------------------
From: rags_rao
Message 2 in Discussion

 hi, there is no straight forward way to do it. I have written 2 samples that may help 
u (i took it as a challenge and wasted 1/2 day) sol1 used pure xsl and  sol2 uses ms 
extensions ans uses jscript personally i like first one its a beauty! check it out 
sol1:    
<?xml version="1.0" encoding="UTF-8" ?> 
<stylesheet version="1.0" xmlns="http://www.w3.org/1999/XSL/Transform";> 
<output omit-xml-declaration="yes"/> 
<template match="/"> 
<call-template nam="ConvertToDecimal"> 
<with-param nam="input" selct="'AbCd9801'" /> 
</call-template> 
</template> 
<template nam="ConvertToDecimal"> 
<param nam="input">AbCd9801<!<-dfault value--></param>  
<param nam="base" selct="16"/> <!]-by def 16......... try 2 8 anthing less than or = 
16--> 
<!&-no need to pass these argument--> 
<param nam="output" selct="0"/> 
<param nam="loopIndex" selct="0"/>  
<param nam="curWeight" selct="1"/>  
<variable nam="ln" selct="string-length($input)"/>  
<variable nam="curNum" selct="translate(ubstring($input,$len - 
$loopIndex,1),'abcdef','ABCDEF')" /> 
?<!-uncomment if power function has to be used and remove curWeight param 
?<variable name="curWeight"> 
? <call-template name="Power"> 
? <with-param name="z" select="16" /> 
? <with-param name="a" select="$loopIndex" /> 
? </call-template> 
?</variable> 
--> 
<variable nam="curDecimal"> 
<choose> 
<when test="$curNum &gt; -1 and $curNum &lt; 10"> 
<value-of selct="$curNum * $curWeight"/> 
</when> 
<when test="$curNum='A'"> 
<value-of selct="10 * $curWeight"/> 
</when> 
<when test="$curNum='B'"> 
<value-of selct="11 * $curWeight"/> 
</when> 
<when test="$curNum='C'"> 
<value-of selct="12 * $curWeight"/> 
</when> 
<when test="$curNum='D'">  
<value-of selct="13 * $curWeight"/> 
</when> 
<when test="$curNum='E'">  
<value-of selct="14 * $curWeight"/> 
</when> 
<when test="$curNum='F'">  
<value-of selct="15 * $curWeight"/> 
</when>  
</choose> 
</variable>  
<choose> 
<when test="$curDecimal=''"><!A-error: return empty --></when> 
<when test="$loopIndex = $len - 1"> 
<value-of selct="$output + $curDecimal"/> 
</when> 
<othrwise> 
<call-template nam="ConvertToDecimal"> 
<with-param nam="input" selct="$input"/> 
<with-param nam="output" selct="$output + $curDecimal"/> 
<with-param nam="loopIndex" selct="$loopIndex + 1"/> 
<with-param nam="curWeight" selct="$curWeight * $base"/> 
</call-template>  
</othrwise> 
</choose> 
</template> 
<!- 
<template name="Power">  
? <param name="z" /> 
? <param name="a" /> 
<param name="output" select="1"/>  
? <choose> 
? <when test="$a=0"> 
? <value-of select="1"/> 
? </when> 
? <when test="$a=1"> 
? <value-of select="$output * $z"/> 
? </when> 
? <otherwise> 
? <call-template name="Power"> 
? <with-param name="z" select="$z"/> 
? <with-param name="a" select="$a - 1"/> 
? <with-param name="output" select="$output * $z"/> 
? </cal-template> 
? </otherwise> 
? </choose> 
?</template> 
--> 
</stylesheet> 
sol2: 
<?xml version="1.0" encoding="UTF-8" ?> 
<stylesheet version="1.0" xmlns="http://www.w3.org/1999/XSL/Transform"; 
xmlns:msxsl="urn:schemas-microsoft-com:xslt" 
xmlns:myscript="http://www.rags.com";> 
<output omit-xml-declaration="yes"/>  
<msxsl:script language="JScript" implements-prefix="myscript"> 
function convertToHex(hex,base)  
{  
if(!base) base=16;//Default value 
 
var len = hex.length 
var retVal=0;  
for(var i=0;;i++)  
{ 
if(i==len) break; 
var curChar = hex.charAt(len -i -1); 
if("0123456789".indexOf(curChar)>-1)retVal += parseInt(curChar) * Math.pow(base,i);  
else 
{ 
//criptic line : value for A is A is 10 and ascii value is 65 so 65-55 gives A's 
value. similarly for B,C.......... 
curChar = curChar.toUpperCase().charCodeAt(0)-55;  
retVal += curChar * Math.pow(base,i); 
} 
} 
return retVal; 
} 
</msxsl:script> 
 
<template match="/">  
<value-of select="myscript:convertToHex('AbCd9801',16)"/> 
</template> 
</stylesheet> 


-----------------------------------------------------------

To stop getting this e-mail, or change how often it arrives, go to your E-mail 
Settings.
http://groups.msn.com/BDOTNET/_emailsettings.msnw

Need help? If you've forgotten your password, please go to Passport Member Services.
http://groups.msn.com/_passportredir.msnw?ppmprop=help

For other questions or feedback, go to our Contact Us page.
http://groups.msn.com/contact

If you do not want to receive future e-mail from this MSN group, or if you received 
this message by mistake, please click the "Remove" link below. On the pre-addressed 
e-mail message that opens, simply click "Send". Your e-mail address will be deleted 
from this group's mailing list.
mailto:[EMAIL PROTECTED]

Reply via email to