Outputting a list of elements - HELP
Posted: Thu May 17, 2007 12:42 am
I have a collection of elements in xml that I need to process and output with xsl…
<Statement_Account_Charge>
<ChargeData>
<Charge>
< Date>3/28/07</ Date>
< Desc>First Charge</ Desc>
< Amt>$9.50</ Amt>
<Unit_Qty>1</ Unit_Qty>
< Unit_Amt>9.5000000</Amt>
</Charge>
</ChargeData>
<ChargeData>
<Charge>
< Date>3/28/07</ Date>
< Desc>Test Charge</ Desc>
< Amt>$11.50</ Amt>
<Unit_Qty>1</ Unit_Qty>
< Unit_Amt>11.5000000</Amt>
</Charge>
</ChargeData>
<ChargeData>
<Charge>
< Date>3/28/07</ Date>
< Desc>Test Charge</ Desc>
< Amt>$6.50</ Amt>
<Unit_Qty>1</ Unit_Qty>
< Unit_Amt>6.5000000</Amt>
</Charge>
</ChargeData>
<ChargeData>
<Charge>
< Date>3/28/07</ Date>
< Desc>Other Charge</ Desc>
< Amt>$7.50</ Amt>
<Unit_Qty>1</ Unit_Qty>
< Unit_Amt>7.5000000</Amt>
</Charge>
</ChargeData>
It looks like this except there are multiple /ChargeData/Charges. (There is only one charge per ChargeData)
I have several /Charges with a Desc of ‘Test Charge’.
Currently, I am outputting each /ChargeData/Charge to my pdf via xslt as a row.
I would like to modify this slightly to collect the /Charges with a Desc of ‘Test Charge’ and merge them into one row. The Date and Desc for each ‘Test Charge’ row are going to be the same. However, I would like to sum it’s Amt and Unit_Amt.
For Example (this is what I want the output to look like):
3/28/07 First Charge 9.5 x 1 $9.50
3/28/07 Test Charge 18.0 x 1 $18.00
3/28/07 First Charge 7.5 x 1 $7.50
Currently, I just loop through the /ChargeData/Charges with an xsl:for-each and output each as I come to it. I am at a loss on how to do this.
Can anyone give me some help on how I would accomplish this with xsl.
Thanks,
<Statement_Account_Charge>
<ChargeData>
<Charge>
< Date>3/28/07</ Date>
< Desc>First Charge</ Desc>
< Amt>$9.50</ Amt>
<Unit_Qty>1</ Unit_Qty>
< Unit_Amt>9.5000000</Amt>
</Charge>
</ChargeData>
<ChargeData>
<Charge>
< Date>3/28/07</ Date>
< Desc>Test Charge</ Desc>
< Amt>$11.50</ Amt>
<Unit_Qty>1</ Unit_Qty>
< Unit_Amt>11.5000000</Amt>
</Charge>
</ChargeData>
<ChargeData>
<Charge>
< Date>3/28/07</ Date>
< Desc>Test Charge</ Desc>
< Amt>$6.50</ Amt>
<Unit_Qty>1</ Unit_Qty>
< Unit_Amt>6.5000000</Amt>
</Charge>
</ChargeData>
<ChargeData>
<Charge>
< Date>3/28/07</ Date>
< Desc>Other Charge</ Desc>
< Amt>$7.50</ Amt>
<Unit_Qty>1</ Unit_Qty>
< Unit_Amt>7.5000000</Amt>
</Charge>
</ChargeData>
It looks like this except there are multiple /ChargeData/Charges. (There is only one charge per ChargeData)
I have several /Charges with a Desc of ‘Test Charge’.
Currently, I am outputting each /ChargeData/Charge to my pdf via xslt as a row.
I would like to modify this slightly to collect the /Charges with a Desc of ‘Test Charge’ and merge them into one row. The Date and Desc for each ‘Test Charge’ row are going to be the same. However, I would like to sum it’s Amt and Unit_Amt.
For Example (this is what I want the output to look like):
3/28/07 First Charge 9.5 x 1 $9.50
3/28/07 Test Charge 18.0 x 1 $18.00
3/28/07 First Charge 7.5 x 1 $7.50
Currently, I just loop through the /ChargeData/Charges with an xsl:for-each and output each as I come to it. I am at a loss on how to do this.
Can anyone give me some help on how I would accomplish this with xsl.
Thanks,