I have a set of orders and want to generate an html document with the orders, I want to use parse template for that but I do not know how this will work for multiple order items in the payload. I want to generate something like this:
<html>
<body>
<table border=4>
<tr>
<th>Order No</th>
<th>Order Description</th>
<th>Provisioning Date</th>
</tr>
<tr>
<td>#[payload[0]['order_no']]</td>
<td>#[payload[0]['order_description']]</td>
<td>#[payload[0]['provisioning_date']]</td>
</tr>
<tr>
<td>#[payload[1]['order_no']]</td>
<td>#[payload[1]['order_description']]</td>
<td>#[payload[1]['provisioning_date']]</td>
</tr>
...... to n orders
</table>
</body>
</html>
This is what I am trying to accomplish. How can I achieve this with parse-template?
Using MEL (Mule Expression Language) you can loop through each order and construct the html and dynamic values needed.
#[
String orders = "";
for(int i = 0; i < payload.size(); i++) {
orders += "<tr>";
orders += "<td>" + payload[i]['order_no'] + "</td>";
orders += "<td>" + payload[i]['order_description'] + "</td>";
orders += "<td>" + payload[i]['provisioning_date'] + "</td>";
orders += "</tr>"
}
return orders;
]