Search code examples
xmlxsltcdata

xsl:cdata elements inside xsl:element


I am trying to get the following output :

<name><![CDATA[ SomeNameHere ]]></name>

using the following xslt :

  <xsl:element name="name"> 
            <xsl:cdata>
                <xsl:value-of select="name"/> 
            </xsl:cdata>
  </xsl:element>

But while compiling I get the following exception :

'xsl:cdata' cannot be a child of the 'xsl:element' element.

How can I insert cdata elements inside an xml node then?

Thank you.


Solution

  • There's no such think as <xsl:cdata>

    If your <xsl:output/> includes name among the elements listed in the cdata-section-elements attributes, then it will use CDATA sections for all such elements.

    If you needed it in one particular case, you could kludge with disable-output-escaping though really you shouldn't have any need for this.