Solved

XSLT: Convert Character entity to hex

Posted on 2006-11-02
9
913 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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Removing information on Duplicate XML Nodes 24 72
Grunt No Clean Targets 6 110
xpath sql query 2008 8 44
SQL XML ALL Nodes Compare in function 2 18
The Confluence of Individual Knowledge and the Collective Intelligence At this writing (summer 2013) the term API (http://dictionary.reference.com/browse/API?s=t) has made its way into the popular lexicon of the English language.  A few years ago, …
What is Node.js? Node.js is a server side scripting language much like PHP or ASP but is used to implement the complete package of HTTP webserver and application framework. The difference is that Node.js’s execution engine is asynchronous and event…
Viewers will learn about the regular for loop in Java and how to use it. Definition: Break the for loop down into 3 parts: Syntax when using for loops: Example using a for loop:
The viewer will learn how to create a basic form using some HTML5 and PHP for later processing. Set up your basic HTML file. Open your form tag and set the method and action attributes.: (CODE) Set up your first few inputs one for the name and …

861 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

23 Experts available now in Live!

Get 1:1 Help Now