Solved

XSLT: Convert Character entity to hex

Posted on 2006-11-02
9
926 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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
Webinar: Aligning, Automating, Winning

Join Dan Russo, Senior Manager of Operations Intelligence, for an in-depth discussion on how Dealertrack, leading provider of integrated digital solutions for the automotive industry, transformed their DevOps processes to increase collaboration and move with greater velocity.

 
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

Space-Age Communications Transitions to DevOps

ViaSat, a global provider of satellite and wireless communications, securely connects businesses, governments, and organizations to the Internet. Learn how ViaSat’s Network Solutions Engineer, drove the transition from a traditional network support to a DevOps-centric model.

Question has a verified solution.

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

I will show you how to create a ASP.NET Captcha control without using any HTTP HANDELRS or what so ever. you can easily plug it into your web pages. For Example a = 2 + 3 (where 2 and 3 are 2 random numbers) Session("Answer") = 5 then we…
I found this questions asking how to do this in many different forums, so I will describe here how to implement a solution using PHP and AJAX. The logical flow for the problem should be: Write an event handler for the first drop down box to get …
Viewers will learn one way to get user input in Java. Introduce the Scanner object: Declare the variable that stores the user input: An example prompting the user for input: Methods you need to invoke in order to properly get  user input:
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)

752 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