Converting Operators into Hexadecimal

Posted on 2009-02-09
Last Modified: 2013-11-18
Hello Experts,

I have an input xml file which contains Operators like below....

<test symbol=","/>
<test symbol=":"/>
<test symbol="!"/>
<test symbol="!="/>
<test symbol="!=="/>
<test symbol="?:"/>
<test symbol="//"/>
<test symbol="/"/>
<test symbol="/*..*/"/>
<test symbol="/="/>
<test symbol="."/>
<test symbol="^"/>
<test symbol="^="/>
<test symbol="~"/>
<test symbol="&quot;"/>
<test symbol="()"/>
<test symbol="--"/>
<test symbol="-"/>
<test symbol="[]"/>
<test symbol="{}"/>
<test symbol="*"/>
<test symbol="*="/>
<test symbol="&amp;"/>
<test symbol="&amp;&amp;"/>
<test symbol="&amp;&amp;="/>
<test symbol="&amp;="/>
<test symbol="%"/>
<test symbol="%="/>
<test symbol="+"/>
<test symbol="++"/>
<test symbol="+="/>
<test symbol="&lt;"/>
<test symbol="&lt;&lt;"/>
<test symbol="&lt;&lt;="/>
<test symbol="&lt;="/>
<test symbol="="/>
<test symbol="-="/>
<test symbol="=="/>
<test symbol="==="/>
<test symbol="&gt;"/>
<test symbol="&gt;="/>
<test symbol="&gt;&gt;"/>
<test symbol="&gt;&gt;="/>
<test symbol="&gt;&gt;&gt;"/>
<test symbol="&gt;&gt;&gt;="/>
<test symbol="|"/>
<test symbol="|="/>
<test symbol="||"/>
<test symbol="||="/>
<test symbol="/"/>
<test symbol=".."/>
<test symbol="@"/>
<test symbol="{ }"/>
<test symbol="[ ]"/>
<test symbol="&lt; &gt;"/>
<test symbol=".."/>
<test symbol="( )"/>
<test symbol="+"/>
<test symbol="+="/>
<test symbol="::"/>

I would like to output xml file which will contains these operators hexadecimal values like below for example...


Question by:ShaileshShinde
    LVL 18

    Expert Comment

    if you use MSXML processor, you can embed a JavaScript section to convert your input data to the hex form.
    LVL 1

    Author Comment

    Hello Experts,

    Can you pls show some sample for this?

    Is this possible using xslt 2.0 only?

    LVL 18

    Accepted Solution

    I'm sorry, I don't know is it possible to do that in XSLT 2.0
    If you still interested in a MSXML based script implementation, then below you can find a sample:
    <xsl:stylesheet exclude-result-prefixes="msxsl js"
          xmlns:js="" version="1.0">
    <xsl:output method="xml" indent="yes" encoding="iso-8859-1"/>
    <msxsl:script language="JScript" implements-prefix="js">
       function convert( c ) {
          var h="";
          for(var i=0;i<c.length;i++) h+="&#x"+c.charCodeAt(i).toString(0x10)+";";
          return h;
    <xsl:template match="test">
    <xsl:value-of disable-output-escaping="yes" select="js:convert(string(@symbol))"/>

    Open in new window

    LVL 1

    Author Comment

    Hello Experts,

    This looks good for me. I will test it and let you know.

    LVL 1

    Author Comment

    Hello Experts,

    While transforming I am getting following errors....

    Error at xsl:value-of on line 291 of file:/D:/parse.xslt:
      XPST0017: XPath syntax error at char 27 on line 291 in {js:convert(string(@symbol))}:
        Cannot find a matching 1-argument function named {}convert()
    Failed to compile stylesheet. 1 error detected.

    Can you please suggest what's wrong with this or do I missed something?

    LVL 60

    Expert Comment

    by:Geert Bormans
    There is no XSLT2 implementation in msxml.
    The javascript solution will not work for you

    You can in XSLT2 create a lookup table as some XML in a variable
    and use XPath to access the correct Hex value

    In XSLT2 it is worthwhile to evaluate character maps to do what you need
    LVL 18

    Expert Comment

    the sample I provided works only in MSXML implementation

    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    What Security Threats Are You Missing?

    Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

    Browsers only know CSS so your awesome SASS code needs to be translated into normal CSS. Here I'll try to explain what you should aim for in order to take full advantage of SASS.
    SASS allows you to treat your CSS code in a more OOP way. Let's have a look on how you can structure your code in order for it to be easily maintained and reused.
    The viewer will learn how to dynamically set the form action using jQuery.
    The viewer will learn how to count occurrences of each item in an array.

    794 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    16 Experts available now in Live!

    Get 1:1 Help Now