Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

XSLT: Convert Character entity to hex

Posted on 2006-11-02
9
Medium Priority
?
961 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
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 7

Accepted Solution

by:
CraigHarris earned 1000 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 1000 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

PowerShell Core for Advanced Linux Administrators

Understand advanced principals around Powershell Core with a focus on the Linux Administrator.  This course covers how to administer numerous environments across multiple platforms including Linux, Azure, AWS, and Google Cloud from a single shell instance.

Question has a verified solution.

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

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…
Browsers only know CSS so your awesome SASS code needs to be translated into normal CSS. Here I'll try to explain what you should aim for in order to take full advantage of SASS.
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)
Video by: Mark
This lesson goes over how to construct ordered and unordered lists and how to create hyperlinks.

715 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