Converting Operators into Hexadecimal

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...


Who is Participating?
zc2Connect With a Mentor Commented:
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

if you use MSXML processor, you can embed a JavaScript section to convert your input data to the hex form.
ShaileshShindeAuthor Commented:
Hello Experts,

Can you pls show some sample for this?

Is this possible using xslt 2.0 only?

Cloud Class® Course: Python 3 Fundamentals

This course will teach participants about installing and configuring Python, syntax, importing, statements, types, strings, booleans, files, lists, tuples, comprehensions, functions, and classes.

ShaileshShindeAuthor Commented:
Hello Experts,

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

ShaileshShindeAuthor Commented:
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?

Geert BormansInformation ArchitectCommented:
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
the sample I provided works only in MSXML implementation
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.