0

Input:(XML)

<A1Result xmlns:s="http://schemas.xmlsoap.org/soap/envelope/">
    <![CDATA[
    <?xml version="1.0" encoding="UTF-8" ?>
    <ABCD_XML_DATA>
        <Header>
            <MessageId>AGDMY1323292534488</MessageId>
        </Header>
    </ABCD_XML_DATA>
    ]]>
</A1Result>

I need this output using xsl:

<ABCD_XML_DATA>
    <Header>
        <MessageId>AGDMY1323292534488</MessageId>
    </Header>
</ABCD_XML_DATA>

additional info, my i/p & o/p are written in/to varibales.

i tried this,

<xsl:variable name="Data"> 
    <xsl:value-of select="$A1Result" disable-output-escaping="yes"/> 
</xsl:variable>

please suggest how to achieve this, thanks.

2 Answers 2

1

finally figured out, the original answer from Borodin(below) also works. I had to parse the i/p, for my processor to recognize.

(i am using dp xsl processor, so the name space dp); i was trying the same thing yesterday with no luck; i had to parse it to work.

<xsl:copy-of select="dp:parse(dp:variable('var://context/saved/MyRes')//*[local-name()='A1Result'])" disable-output-escaping="yes"/> 

where, 'var://context/saved/MyRes', has the input xml from question.

Thanks All.

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

Comments

0

Your source XML is not well-formed because you can't have an XML declaration after the opening tag of the root element.

Assuming this declaration should be moved to the top of the file, you can write an XSLT transform that use the text output method to produce what you want.

<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
  version="1.0">

  <xsl:output method="text"/>

  <xsl:template match="/">
  <xsl:value-of select="A1Result"/>
  </xsl:template>

</xsl:stylesheet>

output

<ABCD_XML_DATA>
    <Header>
        <MessageId>AGDMY1323292534488</MessageId>
    </Header>
</ABCD_XML_DATA>

Update

If you want to remove the XML declaration from the CDATA then the best you can do is use

<xsl:value-of select="substring-after(A1Result, '?>')"/>

12 Comments

also, input is saved in a varibale. i cannot have match as root.
@user2395396: I've updated my answer to deal with your first comment. Are you now saying that the entire XML document an XSLT variable value?
yes. and i am trying to save it again in a varibale. more info added in question.
@Borodin This isn't right. Anything other than ]]> is allowed in CDATA - see w3.org/TR/REC-xml/#sec-cdata-sect "Within a CDATA section, only the CDEnd string is recognized as markup, so that left angle brackets and ampersands may occur in their literal form; they need not (and cannot) be escaped using " &lt; " and " &amp; ". CDATA sections cannot nest. "
@peter.murray.rust: I'm sorry, what isn't right? I don't see that what you have quoted conflicts with anything I have written.
|

Your Answer

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