How do I create CDATA section in output?

Hi,

I’m trying to put a CDATA in my output, something like this.

<?xml version="1.0" encoding="UTF-8"?>

<![CDATA[update for $a in input()/Process where $a/ID = 'eee36c' do replace $a/Name with Jean]]>


I can’t use entities as the xml fragment is copied from another document. Any ideas?

Regards,
Jean

<xsl:output cdata-section-elements=“query”/>

Unfortunately that doesn’t work if you have xml elements within that element.



I?m not sure I understand this statement. Isn?t the whole point of CDATA that it?s just character data, not elements or attributes or any such, even if it contains characters that would normally constitute markup?

Hi Curtis,

What I mean is that if you create elements within the quote element (like Jean) and you use xsl:output cdata-section-elements=“query”, then the quote element won’t specify cdata.

It will create the following

update for $a in input()/Process where $a/ID = ‘eee36c’ do replace $a/Name with Jean


I can’t have it like that as I’m getting the value via xpath in Mediator, and that only returns the text.

If there?s really an element (as opposed to text that happens to look like an element) then you really can?t use CDATA.

Maybe what you really want is something like this:

<xsl:output cdata-section-elements="query"/>
<xsl:template select="node-to-update">
<query>update for $a in input()/Process
  where $a/ID = &apos;<xsl:value-of select="@id"/>&apos; do
  replace $a/Name with
   <Name><xsl:value-of select="Name"/></Name></query>
</xsl:template> 



The point being that what appears as an element in the output is really just text, not an XML element.

Hi Chris,

In the end I decided to use the following transformation to create entities. It is however not really what I want as the result doesn’t look nice and isn’t very readable with all the ampersands etc. Just thought that maybe I could wrap it in a CDATA section but guess I can’t.

 	<xsl:template match="/">
		<Output>
			<xsl:apply-templates mode="queryDocument" select="*"/>
		</Output>
	</xsl:template>
	<!-- Recursively copy elements and attributes of result -->
	<xsl:template match="*" mode="queryDocument">
		<xsl:text><</xsl:text>
		<xsl:value-of select="local-name()"/>
		<xsl:for-each select="@*">
			<xsl:text> </xsl:text>
			<xsl:value-of select="local-name()"/>
			<xsl:text>="</xsl:text>
			<xsl:value-of select="."></xsl:value-of>
			<xsl:text>="</xsl:text>
		</xsl:for-each>
		<xsl:text>></xsl:text>
		<xsl:apply-templates mode="queryDocument"/>
		<xsl:text></</xsl:text>
		<xsl:value-of select="local-name()"/>
		<xsl:text>></xsl:text>
	</xsl:template>

For some reason all the entities are changed to < > etc. It doesn’t post right.