Hi Folks,
I have two questions:

1). How to escape CDATA in your xslt script?

<xsl:template match="/">
	<![CDATA[
		<xsl:apply-templates select="node()"/>
		]]>
	</xsl:template>

In the above code, the template inside CDATA does not get executed. What I actually want is the result from this template (<xsl:apply-templates select="node()"/>) to be returned as CDATA. For example, if the apply template returns....

<request code=10 type="2"/>

then i want the final output to be

<![CDATA[<request code=10 type="2"/>]]>

. But at the moment apply template is not getting executed.

2). My second question is regarding the response to be transformed/decoded to CDATA or proper xml.

I'm getting a response from a webservice for example:

<?xml version="1.0" encoding="utf-8"?>
<soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
	<soap:Body>
		<ForwardRequestResponse xmlns="http://webservices.kuoni.ch">
			<ForwardRequestResult>&lt;?xml version="1.0" encoding="windows-1252"?&gt;&lt;Response Version="2.5" From="KUEKA0" To="EBOOKERS" TermId="EB0001" Window="A" Date="04082009" Time="095322" Type="ERROR" Confirm="YES" Agent="541406" Lang="DE" UserCode="EBOO" UserType="M" UserName="EBOOKERS" UserFirstName="CH" Mode="Test"&gt;&lt;Err SegRef="001"&gt;&lt;ErrorNr&gt;3706&lt;/ErrorNr&gt;&lt;ErrorText&gt;Datum für Flug/Transport überprüfen&lt;/ErrorText&gt;&lt;/Err&gt;&lt;/Response&gt;</ForwardRequestResult>
		</ForwardRequestResponse>
	</soap:Body>
</soap:Envelope>

Now if you look inside, <ForwardRequestResult> element the text is encoded, how can I decode it to a proper xml form i.e. without these &lt; ? &gt; ect ??

Thanks.

Suppose you have the following XML document

<requests>
   <request code="10" type="2"/>
</requests>

The following XSL

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

<xsl:output method="xml"/>

<xsl:template match="node()" >
   <xsl:text disable-output-escaping="yes"><![CDATA[<![CDATA[]]></xsl:text>
   <xsl:copy-of select="node()"/>
   <xsl:text disable-output-escaping="yes">]]</xsl:text>
   <xsl:text disable-output-escaping="yes">></xsl:text>
</xsl:template>

<xsl:template match="/">
    <xsl:apply-templates select="node()"/>
</xsl:template>

</xsl:stylesheet>

produces your desired ouput

<?xml version="1.0"?>
<![CDATA[
   <request code="10" type="2"/>
]]>
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.