Vineet Raj
Vineet Raj

Reputation: 85

XML to XLS Transformation through XSLT

How to retraverse an xml while converting into .xls file through XSLT?

I have the request xml as:-

<?xml version="1.0" encoding="UTF-8"?>

<report>
<header>
<request_id>121</request_id><content_provider>ews</content_provider><report_date>2013-09-26</report_date>
</header>

<policy_detail><client_name>MR JOHN PHILIP GRACE</client_name><date_of_birth>1954-04-21</date_of_birth><policy_number>0081467839</policy_number><clawback>518.67</clawback><date_policy_inception>1992-08-07</date_policy_inception>106085</frn><master_agent_number>1212190</master_agent_number><agent_number>6354773</agent_number><clawback_date>      </clawback_date>
</policy_detail>

<policy_detail><client_name>MISS LISA PORTER</client_name><date_of_birth>1970-05-18</date_of_birth><policy_number>0082625310</policy_number><clawback>463.72</clawback><date_policy_inception>1994-05-17</date_policy_inception><frn>106085</frn><master_agent_number>1212190</master_agent_number><agent_number>6366264</agent_number><clawback_date>      </clawback_date>
</policy_detail>

<policy_detail><client_name>MRS ELAINE LOCKYER</client_name><date_of_birth>1957-09-07</date_of_birth><policy_number>0108791948</policy_number><clawback>64.98</clawback><date_policy_inception>2004-07-01</date_policy_inception><frn>106085</frn><master_agent_number>2178267</master_agent_number><agent_number>1212189</agent_number><clawback_date>      </clawback_date>
</policy_detail>

<policy_detail><client_name>MR DEMETRIOUS PAPI</client_name><date_of_birth>1957-10-25</date_of_birth><policy_number>0019751627
</policy_number><clawback>427.71</clawback><date_policy_inception>1992-05-07</date_policy_inception><frn>106085</frn><master_agent_number>2001188</master_agent_number><agent_number>2009744</agent_number><clawback_date>      </clawback_date>
</policy_detail>

<summary><policy_count>4</policy_count><clawback_total>1475.08</clawback_total>
</summary>
</report>

The processing XSL is:--

<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output method="xml" indent="yes"/>
<xsl:template match="*">
    <xsl:apply-template/>
</xsl:template>
<xsl:template match="policy_detail">
<xsl:value-of select="client_name"/>
</xsl:template>

Below this, I have to insert code of calculating total clawback on the basis of a particular master_agent_no i.e. 1212190.

Upvotes: 0

Views: 117

Answers (1)

Michael Kay
Michael Kay

Reputation: 163322

Just add code that outputs

<xsl:value-of select="sum(//policy_detail[agent_number='1212190']/clawback)"/>

at the appropriate point in your stylesheet code.

Upvotes: 1

Related Questions