Solved

XSLT: Convert Character entity to hex

Posted on 2006-11-02
9
918 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
3 Use Cases for Connected Systems

Our Dev teams are like yours. They’re continually cranking out code for new features/bugs fixes, testing, deploying, testing some more, responding to production monitoring events and more. It’s complex. So, we thought you’d like to see what’s working for us.

 
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

3 Use Cases for Connected Systems

Our Dev teams are like yours. They’re continually cranking out code for new features/bugs fixes, testing, deploying, testing some more, responding to production monitoring events and more. It’s complex. So, we thought you’d like to see what’s working for us.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Create associate webpages / websites 3 80
WCAG audit tools 1 82
XSLT: how to increment number value if attribute present 4 43
parse convert xml feed to text (python) 2 83
Shoutout to Emily Plummer (http://www.experts-exchange.com/members/eplummer26.html) for giving me this article! She did most of it, I just finished it up and posted it for her :)    Introduction In a previous article (http://www.experts-exchang…
I was working on a PowerPoint add-in the other day and a client asked me "can you implement a feature which processes a chart when it's pasted into a slide from another deck?". It got me wondering how to hook into built-in ribbon events in Office.
The viewer will learn how to count occurrences of each item in an array.
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)

803 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