Skip to Content
0

Escape character handling in xslt map

Nov 29, 2016 at 05:00 PM

29

avatar image

Hello Experts,

I'm very new to xslt mapping. I got this requirement here, that receiver web application need escape characters in XML entity replacement. i.e. if PO xml has '&' it should get convert it to & like this...

I tried below code, but certainly it is not working

-----------------------------------------------------------------------

<?xml version="1.0" encoding="utf-8"?>
<xsl:stylesheet version="2.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
    <xsl:output method="xhtml" indent="yes"/> 
<xsl:template match="@*|node()">
<xsl:copy> <xsl:apply-templates select="@*|node()"/>
</xsl:copy> </xsl:template> <xsl:template match="*/text()"> <xsl:value-of select="replace(., '&', '&')"/> </xsl:template>
</xsl:stylesheet>

----------------------------------------------------------------------------

Input:

<Root>

<Test>ABC & DEF</Test>

</Root>

Desired Output:

<Root>

<Test>ABC & DEF</Test>

</Root>

-----------------------------------------------------------------------------

Please tell me where i'm getting wrong, and a code will be highly appreciated.

Thanks a lot.

PS. Can't use JAVA mapping, it'd have been much easier though...

10 |10000 characters needed characters left characters exceeded

the code actually <xsl:value-ofselect="replace(., '& amp;', '& amp;')"/>

and

Desired Output:

<Root>

<Test>ABC & amp; DEF</Test>

</Root>

0
* Please Login or Register to Answer, Follow or Comment.

1 Answer

Evgeniy Kolmakov Nov 30, 2016 at 05:53 AM
0

Hi Debtirtha!

Does your XSL transformation raise any error?

Regards, Evgeniy.

Show 3 Share
10 |10000 characters needed characters left characters exceeded

No, but it generates the same 'and' sign in output, if you are testing the code, plz remove the space in '& amp;'

0

I'm asking because it should raise error since your source XML is not well-formed. I guess you need to use java mapping to replace "&" with "&".

Regards, Evgeniy.

0

But you say you can't...

0