CDATA in XSLT String Functions Causes Problems

Do not use CDATA in XSLT string functions (value-of turns the content into a string).

For example, assume you are using the mapper to hard code a SOAP Adapter header attribute. The mapper encodes the data, which causes a problem for the endpoint service at runtime.

  • Mapping:
    [Expression for: "header"]
    "<![CDATA[ <CrosstalkMessage> <CrosstalkHeader> 
    <ProcessCode>1004</ProcessCode> <MessageType>100</MessageType> 
    <ExchangePattern>7</ExchangePattern> <EnterpriseId>ace7d6ae-78a8-f3gh-1d04
    -9fe0416d053c</EnterpriseId> <Token>h12749ed-913b-7e3e-2aef
    -8dd78255cb40</Token> <DestinationId>b3fbf48e-df96-f27d-5fac
    -38895618064f</DestinationId> <ContentEncoding>utf-8</ContentEncoding> 
    <ContentType>text/xml</ContentType> </CrosstalkHeader> </CrosstalkMessage> 
    ]]>"
  • Code:
    <tns:header xml:id="id_48">
          <xsl:value-of xml:id="id_82" select="'&lt;![CDATA[ &lt;CrosstalkMessage&gt; 
    &lt;CrosstalkHeader&gt; &lt;ProcessCode&gt;1004&lt;/ProcessCode&gt; 
    &lt;MessageType&gt;100&lt;/MessageType&gt; 
    &lt;ExchangePattern&gt;7&lt;/ExchangePattern&gt; &lt;EnterpriseId&gt;ace7d6ae
    -78a8-f3gh-1d04-9fe0416d053c&lt;/EnterpriseId&gt; &lt;Token&gt;h12749ed-913b
    -7e3e-2aef-8dd78255cb40&lt;/Token&gt; &lt;DestinationId&gt;b3fbf48e-df96-f27d
    -5fac-38895618064f&lt;/DestinationId&gt; &lt;ContentEncoding&gt;utf
    -8&lt;/ContentEncoding&gt; &lt;ContentType&gt;text/xml&lt;/ContentType&gt; 
    &lt;/CrosstalkHeader&gt; &lt;/CrosstalkMessage&gt; ]]&gt;'"/>
    </tns:header>

To achieve this:

  • Write the XML structure using a stage file action.
  • Read the XML as opaque content.
  • Map to the header element by using decodeBase64 of read content.
  • Use the cdata-section-elements attribute in XSLT referring to the header element.