IBM Support

Howto: Transform Non-XML input using DataPower

Technote (FAQ)


Question

How do I manipulate non-XML input on DataPower? How do I wrap non-XML input in XML to produce well-formed XML output?

Answer

One method to manipulate non-XML data is to wrap the document with XML tags to produce well-formed pseudo-XML. The resulting document can either be sent as-is or processed further before sending to the backend or client. If you require a more sophisticated transform, you may need to look into using WebSphere Transformation Extender mapping.

Transforming raw text to pseudo-XML:

This example will take the following text as input:


some text here
and here is some more
and some more


and some more

and wait, some more here


Steps to Create:

  1. Create a Transform action in the service that will be receiving non-XML requests.
  2. Select "Use XSLT specified in this action on a non-XML message" to specify that this is a Binary Transform.
  3. Upload the following style sheet as the Processing Control File.
  4. Click Done, and Apply all windows.


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

<dp:input-mapping href="sample.ffd" type="ffd"/>

<!-- This stylesheet copies the input to the output -->
<xsl:output method="xml"/>

<xsl:template match="/">
<xsl:value-of select="sampleFile/sampleTag" disable-output-escaping="yes" />
</xsl:template>
</xsl:stylesheet>


5. Upload the following FFD file into the local://sample.ffd directory from the File Manager.


<File name="sampleFile">
<!-- capture all data into this tag -->
<Field name="sampleTag" />
</File>


Sending the sample input above will result in the following output


<?xml version="1.0" encoding="utf-8"?>
<sampleFile>
<sampleTag>
some text here
and here is some more
and some more


and some more

and wait, some

</sampleTag>
</sampleFile>

Modifying HTML:

This example will take an HTML page (not the XML equivalent XHTML) and rewrite all links referencing 'original.host.com':

Steps to Create:

  1. Create a Transform action in the service that will be receiving non-XML requests.
  2. Select "Use XSLT specified in this action on a non-XML message" to specify that this is a Binary Transform.
  3. Upload the following style sheet as the Processing Control File.
  4. Click Done, and Apply all windows.


<?xml version="1.0" encoding="utf-8"?>
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:dp="http://www.datapower.com/extensions"
xmlns:regexp="http://exslt.org/regular-expressions">

<dp:input-mapping href="sample.ffd" type="ffd"/>
<!-- This stylesheet rewrites 'original.host.com' to 'new.host.com' -->
<xsl:output method="html"/>
<xsl:template match="/">

<xsl:variable name="htmlContent" select="inputHTMLDoc/HTML_ROOT/text()" />
<xsl:variable name="xformedContent" select="regexp:replace($htmlContent, 'original.host.com', 'g', 'new.host.com')" />

<xsl:value-of select="$xformedContent" disable-output-escaping="yes" />
</xsl:template>
</xsl:stylesheet>


5. Upload the following FFD file into the local://sample.ffd directory from the File Manager.


<File name="inputHTMLDoc">
<!-- capture all data into this tag -->
<Field name="HTML_ROOT" />
</File>


The resulting output will be the original HTML document with all occurrences of the old host name rewritten.

Document information

More support for: IBM DataPower Gateways
General

Software version: 4.0.1, 4.0.2, 5.0.0, 6.0.0, 6.0.1

Operating system(s): Firmware

Reference #: 1321379

Modified date: 13 October 2009