0

I have a unformatted string XML, which has to be converted to XML using XSLT 2.0

Below is the sample unformatted string XML.I tried few XSLT but didnt worked like adding the disable-output-escaping.The Tag opening symbol(<) is not getting displayed,instead of that still the "<" is displayed.So basically need to replace "<" to "<"

<?xml version = "1.0" encoding = "UTF-8"?>
<ns0:Message xmlns:ns0 = "http://www.àbc.com/abc/Message_V2.xsd">
    <ns0:Payload>
        &lt;ns:EXPINV02-ZEXPINV2-4x xmlns:ae="http://www.àbc.com/abc/05" 
    xmlns:ns="http://www.àbc.com/abc/IDOCS" 
   xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
   xsi:type="ns:EXP">            
   &lt;EDI__DC>&lt;TABNAM>EDI_DC40&lt;/TABNAM>&lt;MANDT>510&lt;/MANDT>
  &lt;DOCNUM>0000000058569441&lt;/DOCNUM>&lt;DOCREL>740&lt;/DOCREL>
  &lt;STATUS>30&lt;/STATUS>&lt;DIRECT>1&lt;/DIRECT>&lt;OUTMOD>
  2&lt;/OUTMOD>&lt;EXPRSS xsi:nil="true"/>&lt;TEST 
  xsi:nil="true"/>&lt;IDOCTYP>EXPINV02&lt;/IDOCTYP>
  &lt;CIMTYP>ZEXPINV2&lt;/CIMTYP>&lt;MESTYP>ZINVOICE0&lt;/MESTYP>
  &lt;MESCOD xsi:nil="true"/>&lt;MESFCT xsi:nil="true"/>
  &lt;STD xsi:nil="true"/>&lt;STDVRS 
  xsi:nil="true"/>&lt;STDMES>ZINVOI&lt;/STDMES>
  &lt;SNDPOR>SAPNEQ&lt;/SNDPOR>&lt;SNDPRT>LS&lt;/SNDPRT>&lt;SNDPFC 
  xsi:nil="true"/>&lt;SNDPRN>NEQ510&lt;/SNDPRN>&lt;SNDSAD 
  xsi:nil="true"/>&lt;SNDLAD 
  xsi:nil="true"/>&lt;RCVPOR>NXPINVOICE&lt;/RCVPOR>&lt;RCVPRT>
  LS&lt;/RCVPRT>&lt;RCVPFC 
  xsi:nil="true"/>&lt;RCVPRN>PSFFORMSCA&lt;/RCVPRN>&lt;RCVSAD 
  xsi:nil="true"/>&lt;RCVLAD 
  xsi:nil="true"/>&lt;CREDAT>20190715&lt;/CREDAT>&lt;CRETIM>
  152902&lt;/CRETIM>&lt;REFINT xsi:nil="true"/>&lt;REFGRP 
  xsi:nil="true"/>&lt;REFMES xsi:nil="true"/>&lt;ARCKEY 
  xsi:nil="true"/>&lt;SERIAL>20190528064107&lt;/SERIAL>&lt;/EDI__DC>
    </ns0:Payload>
</ns0:Message>

Expected Output is below:

 <?xml version = "1.0" encoding = "UTF-8"?>
 <ns0:Message xmlns:ns0 = "http://www.àbc.com/abc/Message_V2.xsd">
    <ns0:Payload>
        <ns:EXPINV02-ZEXPINV2-4x xmlns:ae="http://www.àbc.com/abc/05" 
   xmlns:ns="http://www.àbc.com/abc/IDOCS" 
     xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
   xsi:type="ns:EXP">
            <EDI__DC><TABNAM>EDI_DC40</TABNAM><MANDT>510</MANDT> 
  <DOCNUM>0000000058569441</DOCNUM><DOCREL>740</DOCREL> 
  <STATUS>30</STATUS><DIRECT>1</DIRECT><OUTMOD>2</OUTMOD><EXPRSS 
  xsi:nil="true"/><TEST xsi:nil="true"/><IDOCTYP>EXPINV02</IDOCTYP> 
  <CIMTYP>ZEXPINV2</CIMTYP><MESTYP>ZINVOICE0</MESTYP><MESCOD 
  xsi:nil="true"/><MESFCT xsi:nil="true"/><STD xsi:nil="true"/><STDVRS 
  xsi:nil="true"/><STDMES>ZINVOI</STDMES><SNDPOR>SAPNEQ</SNDPOR> 
  <SNDPRT>LS</SNDPRT><SNDPFC xsi:nil="true"/><SNDPRN>NEQ510</SNDPRN> 
  <SNDSAD xsi:nil="true"/><SNDLAD xsi:nil="true"/> 
  <RCVPOR>NXPINVOICE</RCVPOR><RCVPRT>LS</RCVPRT><RCVPFC xsi:nil="true"/> 
  <RCVPRN>PSFFORMSCA</RCVPRN><RCVSAD xsi:nil="true"/><RCVLAD 
  xsi:nil="true"/><CREDAT>20190715</CREDAT><CRETIM>152902</CRETIM><REFINT 
   xsi:nil="true"/><REFGRP xsi:nil="true"/><REFMES xsi:nil="true"/> 
  <ARCKEY 
   xsi:nil="true"/><SERIAL>20190528064107</SERIAL></EDI__DC>
    </ns0:Payload>
  </ns0:Message>
4
  • Actually its the ""\&lt;" symbol getting displayed Commented Jul 19, 2019 at 6:39
  • convert to file text then convert xml Commented Jul 19, 2019 at 6:58
  • Are you able to upgrade to XSLT 3.0? If so, you could make use of parse-xml to do this. Having said that, your escaped XML is missing the closing EXPINV02-ZEXPINV2-4x tag, so would not actually be valid at the moment. Thanks! Commented Jul 19, 2019 at 7:58
  • disable-output-escaping should work - but the escaped string is missing the closing </ns:EXPINV02-ZEXPINV2-4x> tag, so the result will not be a well-formed XML document. Commented Jul 19, 2019 at 10:26

2 Answers 2

2

In XSLT 3.0 you can use parse-xml(). There's no guaranteed-portable way of doing it in XSLT 2.0. Some processors may offer an extension function similar to parse-xml(), some may allow you to implement your own extension functions, some may support the "data" URI scheme in the document() function.

Sign up to request clarification or add additional context in comments.

Comments

0
Check Following Code:-

<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="2.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output method="xml" indent="yes" encoding="UTF-8"/>
    <xsl:output method="xml" indent="yes" use-character-maps="angle-brackets"/>
<xsl:character-map name="angle-brackets">
    <xsl:output-character character="&lt;" string="&lt;"/>
    <xsl:output-character character="&gt;" string="&gt;"/>
</xsl:character-map>
<xsl:strip-space elements="*"/>
<xsl:template match="Plugins">
    <xsl:copy>
        <xsl:apply-templates select="Configuration"/>
    </xsl:copy>
</xsl:template>
<xsl:template match="Configuration">
    <xsl:variable name="input">
        <xsl:value-of select="."/>
    </xsl:variable>
    <xsl:apply-templates select="document(concat('data:text/xml,',$input))"/>
</xsl:template>
<xsl:template match="@*|node()">
    <xsl:copy>
        <xsl:apply-templates select="@*|node()"/>
    </xsl:copy>
</xsl:template>
</xsl:stylesheet>

1 Comment

This solution depends on the processor supporting the "data:" URI scheme in the document() function, which is by no means guaranteed.

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.