Solved

XSLT: Convert Character entity to hex

Posted on 2006-11-02
9
908 Views
Last Modified: 2013-11-18
Hello,
I am trying to use  XSLT to convert character entities to hex. I am using Xalan/Xerces.

Example:-  ’ -> ’

Please suggest.

Thanks,
Kanishk.
0
Comment
Question by:kanishkpanwar
  • 2
  • 2
  • 2
  • +1
9 Comments
 
LVL 11

Expert Comment

by:kmartin7
ID: 17858953
Hmm, I don't think it can be done with pure XSLT, but I am interested to hear what others have to say.
0
 
LVL 7

Expert Comment

by:CraigHarris
ID: 17862027
I'm pretty certain you can't do that in XSLT ... though Xerces does allow for callback functions which you might be able to use.

If you treat the XML as a string you could iterate over every character and easily replace those which need replacing though.
0
 

Author Comment

by:kanishkpanwar
ID: 17862075
ohk.
I can use java's replaceAll method to get the job done. but I wanted a bit more scalable approach so that we don't have to rebuild the code incase a new special character is needed.
Any other suggestions? :)
0
Find Ransomware Secrets With All-Source Analysis

Ransomware has become a major concern for organizations; its prevalence has grown due to past successes achieved by threat actors. While each ransomware variant is different, we’ve seen some common tactics and trends used among the authors of the malware.

 
LVL 7

Accepted Solution

by:
CraigHarris earned 250 total points
ID: 17862165
Use a generic replacement method that will replace any char over #159 with &#ord(char);
0
 
LVL 60

Expert Comment

by:Geert Bormans
ID: 17862202
Stream through your text nodes using a java function is about the best option you have
you can implement the entire character map in your java function,
then it would be scalable

If XSLT2.0 and Saxon instead of Xalan were an option,
it might be worthwhile looking at xsl:character-map

don't go recursing through your data using XSLT1 named templates.
You could do that... but here is the time that you should step outside with an extension function
0
 

Author Comment

by:kanishkpanwar
ID: 17908482
I can use XSLT 2.0 and Saxon, if needed. Can I get some directions on that?
0
 
LVL 60

Assisted Solution

by:Geert Bormans
Geert Bormans earned 250 total points
ID: 17908563
first you need to create a character map

<xsl:output use-character-maps="my_map"/>

<xsl:character-map name="my_map">
     <xsl:output-character char="’" string="&amp;#8217;"/>
     <xsl:output-character char="......
</character-map>

you can add as many output characters as you please

character maps apply to the whole document

That is all there is to it

cheers

Geert
0

Featured Post

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

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.
JavaScript has plenty of pieces of code people often just copy/paste from somewhere but never quite fully understand. Self-Executing functions are just one good example that I'll try to demystify here.
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)
The viewer will learn the basics of jQuery including how to code hide show and toggles. 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…

743 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

14 Experts available now in Live!

Get 1:1 Help Now