1

I receive text from source system with HTML special escape characters in middle of text. Now I need to translate it to the actual character in XSLT 2.0

I/p like

<Data>Lenevo100 f&amp;uuml;r Laser</Data>
<Data>DELL &amp;Agrave;llow Drucker</Data>

and the expected output would be

<DataOutput>Lenevo100 fÜr Laser</DataOutput>
<DataOutput>DELL Àllow Drucker</DataOutput>

If it is always only 2 or 3 values i can do the replace or translate function but the problem is this HTML special code characters are so many .Can any provide the solution to achieve this,

List of HTML special characters code https://www.ou.edu/research/electron/internet/special.shtml

8
  • There may be solutions specific to a particular XSLT processor or execution platform. Let us know which product you are using for your XSLT 2.0 library. Commented Apr 3, 2023 at 13:54
  • I am using this XSLT 2.0 Oracle Cloud OIC product Commented Apr 3, 2023 at 15:42
  • Which XSLT 2 processor is used in Oracle Cloud OIC? Does it allow you to use Java libraries from XSLT so that you could call into an HTML parser? Commented Apr 3, 2023 at 20:27
  • No it wont allow to call Java libraries. Commented Apr 4, 2023 at 4:49
  • What about my posted answer, to use the XSLT library parsing HTML/HTML entity references? Can't you use that either? Commented Apr 4, 2023 at 9:45

1 Answer 1

1

David Carlisle has an HTML parser written in XSLT 2.0, it is online at https://github.com/davidcarlisle/web-xslt/blob/main/htmlparse/htmlparse.xsl, you can use it as follows:

<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
    xmlns:xs="http://www.w3.org/2001/XMLSchema"
    xmlns:dpc="data:,dpc"
    exclude-result-prefixes="#all"
    version="2.0">
  
  <xsl:import href="https://raw.githubusercontent.com/davidcarlisle/web-xslt/main/htmlparse/htmlparse.xsl"/>

  <xsl:template match="Data">
    <DataOutput>
      <xsl:value-of select="dpc:htmlparse(., '', true())"/>
    </DataOutput>
  </xsl:template>
  
</xsl:stylesheet>
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.