Question

How to retain hexadecimal code in xslt transformation?

Input:

<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="2.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:aid="http://ns.adobe.com/AdobeInDesign/4.0/" xmlns:aid5="http://ns.adobe.com/AdobeInDesign/5.0/">
<root>
   <p>This is sample character &#x000ED;</p>
</root>

Expected Output:

<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="2.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:aid="http://ns.adobe.com/AdobeInDesign/4.0/" xmlns:aid5="http://ns.adobe.com/AdobeInDesign/5.0/">
<root>
   <p aid:pstyle="para">This is sample character &#x000ED;</p>
</root>

No correct solution

OTHER TIPS

Use a character-map to control output serialization. You'll find the relevant part of the XSL specification here.

Note that there are other issues with your code. A stylesheet must contain a template that can be triggered, for example xsl:template match="/". Otherwise, nothing is serialized anyway.

Also, I do not see how this relates to an input XML document, since the content comes solely from your XSLT stylesheet.

Stylesheet

<xsl:stylesheet version="2.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">

<xsl:output use-character-maps="my-map" indent="yes"/>

<xsl:character-map name="my-map">
    <xsl:output-character character="&#x000ED;" string="&amp;#x000ED;"/>
</xsl:character-map>

<xsl:template match="/">
   <root>
      <p pstyle="para">This is sample character &#x000ED;</p>
   </root>
</xsl:template>
</xsl:stylesheet>

Output

<?xml version="1.0" encoding="UTF-8"?>
<root>
   <p pstyle="para">This is sample character &#x000ED;</p>
</root>
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top