?
Solved

Converting Operators into Hexadecimal

Posted on 2009-02-09
7
Medium Priority
?
440 Views
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...

<conv>&#x2C;</conv>
<conv>&#x3A;</conv>
<conv>&#x21;</conv>


0
Comment
Question by:ShaileshShinde
  • 3
  • 3
7 Comments
 
LVL 19

Expert Comment

by:zc2
ID: 23591065
if you use MSXML processor, you can embed a JavaScript section to convert your input data to the hex form.
0
 
LVL 1

Author Comment

by:ShaileshShinde
ID: 23597416
Hello Experts,

Can you pls show some sample for this?

Is this possible using xslt 2.0 only?

Thanks,
Shailesh
0
 
LVL 19

Accepted Solution

by:
zc2 earned 750 total points
ID: 23601922
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:xsl="http://www.w3.org/1999/XSL/Transform" 
      xmlns:msxsl="urn:schemas-microsoft-com:xslt"
      xmlns:js="http://mycompany.com/mynamespace" version="1.0">
      
<xsl:output method="xml" indent="yes" encoding="iso-8859-1"/>
<msxsl:script language="JScript" implements-prefix="js">
<![CDATA[
 
   function convert( c ) {
      var h="";
      for(var i=0;i<c.length;i++) h+="&#x"+c.charCodeAt(i).toString(0x10)+";";
      return h;
   }
 
]]>
</msxsl:script>
 
<xsl:template match="test">
<conv>
<xsl:value-of disable-output-escaping="yes" select="js:convert(string(@symbol))"/>
</conv>
</xsl:template>
    
</xsl:stylesheet>

Open in new window

0
Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

 
LVL 1

Author Comment

by:ShaileshShinde
ID: 23609010
Hello Experts,

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

Thanks,
Shailesh
0
 
LVL 1

Author Comment

by:ShaileshShinde
ID: 23609052
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 {http://mycompany.com/mynamespace}convert()
Failed to compile stylesheet. 1 error detected.

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

Thanks,
Shailesh
0
 
LVL 60

Expert Comment

by:Geert Bormans
ID: 23609447
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
0
 
LVL 19

Expert Comment

by:zc2
ID: 23611961
the sample I provided works only in MSXML implementation
0

Featured Post

Vote for the Most Valuable Expert

It’s time to recognize experts that go above and beyond with helpful solutions and engagement on site. Choose from the top experts in the Hall of Fame or on the right rail of your favorite topic page. Look for the blue “Nominate” button on their profile to vote.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction Since I wrote the original article about Handling Date and Time in PHP and MySQL several years ago, it seemed like now was a good time to update it for object-oriented PHP.  This article does that, replacing as much as possible the pr…
CSS is a visual language used to classify objects and define rules about how they should be displayed. CSS skills aren’t restricted to developers anymore, there is a big benefit to having a basic understanding of the language, regardless of your occ…
This tutorial will teach you the core code needed to finalize the addition of a watermark to your image. The viewer will use a small PHP class to learn and create a watermark.
The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)
Suggested Courses

850 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