XML to XML
The XML2XML policy allows a user to configure source and target document structures using the Fiorano Mapper and create an XSL used for transforming documents. Alternatively, it allows users to define XSL created using external tools. Documents passed to the component are transformed using the XSL defined.
Xalan (2.7.0) and Saxon (8.4) transformer implementations are bundled within the Fiorano environment for performing transformations.
To retrieve simple elements from XML, Assign Variables policy along with the XPath option is preferred.
Configuration
The properties that have to be configured to use the policy are described below.
Figure 1: XML to XML Policy Configuration attributes
Property | Description |
Skip Namespaces | Whether or not to skip adding namespace declarations to XML elements while converting. |
XSLT Engine | Select the XSL Transformation engine to be used. Below are the available options:
|
XSL | This is an XML-based style sheet which defines the XSL that is used to transform source data to the desired output. It is the language for expressing style sheets. An XSL style sheet such as CSS is a file that describes how to display an XML document of a given type. |
Example
To retrieve only the body of a message from a SOAP-based web service response, please use the following XSL:
Stripping SOAP envelope
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" version="1.0">
<xsl:output indent="yes" />
<xsl:template match="@* | node()">
<xsl:copy>
<xsl:apply-templates select="@* | node()" />
</xsl:copy>
</xsl:template>
<xsl:template match="soapenv:*">
<xsl:apply-templates select="@* | node()" />
</xsl:template>
</xsl:stylesheet>
Example
To achieve transformation of a basic XML input using a customized XSL template configured in the policy, please go through the following illustration:
1) Please use the following XSL to specify as template in the policy configuration.
XSL template
<?xml version="1.0" encoding="ISO-8859-1"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:foo="http://www.foo.org/" xmlns:bar="http://www.bar.org">
<xsl:template match="/">
<html>
<body>
<h2>My CD Collection</h2>
<table border="1">
<tr bgcolor="#9acd32">
<th>Title</th>
<th>Artist</th>
<th>Country</th>
<th>Company</th>
<th>Price</th>
<th>Year</th>
</tr>
<xsl:for-each select="catalog/foo:cd">
<tr>
<td><xsl:value-of select="title"/></td>
<td><xsl:value-of select="artist"/></td>
<td><xsl:value-of select="country"/></td>
<td><xsl:value-of select="company"/></td>
<td><xsl:value-of select="price"/></td>
<td><xsl:value-of select="bar:year"/></td>
</tr>
</xsl:for-each>
</table>
</body>
</html>
</xsl:template>
</xsl:stylesheet>
2) Please use the following XML to feed input to the policy.
XML input
<?xml version="1.0" encoding="ISO-8859-1"?>
<catalog xmlns:foo="http://www.foo.org/" xmlns:bar="http://www.bar.org">
<foo:cd>
<title>Empire Burlesque</title>
<artist>Bob Dylan</artist>
<country>USA</country>
<company>Columbia</company>
<price>10.90</price>
<bar:year>1985</bar:year>
</foo:cd>
<foo:cd>
<title>Hide your heart</title>
<artist>Bonnie Tyler</artist>
<country>UK</country>
<company>CBS Records</company>
<price>9.90</price>
<bar:year>1988</bar:year>
</foo:cd>
<foo:cd>
<title>Greatest Hits</title>
<artist>Dolly Parton</artist>
<country>USA</country>
<company>RCA</company>
<price>9.90</price>
<bar:year>1982</bar:year>
</foo:cd>
</catalog>
3) The expected output of the policy execution is the transformed XML which is as follows:
Transformed XML output
<html xmlns:foo="http://www.foo.org/" xmlns:bar="http://www.bar.org">
<body>
<h2>My CD Collection</h2>
<table border="1">
<tr bgcolor="#9acd32">
<th>Title</th>
<th>Artist</th>
<th>Country</th>
<th>Company</th>
<th>Price</th>
<th>Year</th>
</tr>
<tr>
<td>Empire Burlesque</td>
<td>Bob Dylan</td>
<td>USA</td>
<td>Columbia</td>
<td>10.90</td>
<td>1985</td>
</tr>
<tr>
<td>Hide your heart</td>
<td>Bonnie Tyler</td>
<td>UK</td>
<td>CBS Records</td>
<td>9.90</td>
<td>1988</td>
</tr>
<tr>
<td>Greatest Hits</td>
<td>Dolly Parton</td>
<td>USA</td>
<td>RCA</td>
<td>9.90</td>
<td>1982</td>
</tr>
</table>
</body>
</html>