Generate a summary from an XML file.
I have an XML file with this detail:
<sales>
<sale P_ID="12" L_ID="02" T_ID="02-06-2003">
<quantity>46</quantity>
</sale>
<sale P_ID="11" L_ID="03" T_ID="22-07-2003">
<quantity>31</quantity>
</sale>
<sale P_ID="12" L_ID="03" T_ID="02-07-2004">
<quantity>59</quantity>
</sale>
<sale P_ID="11" L_ID="04" T_ID="22-06-2003">
<quantity>27</quantity>
</sale>
<sale P_ID="12" L_ID="04" T_ID="13-06-2004">
<quantity>19</quantity>
</sale>
<products>
<product>
<p_id>11</p_id>
<p_name>Glasses</p_name>
</product>
<product>
<p_id>12</p_id>
<p_name>Clothes</p_name>
</product>
<product>
<p_id>13</p_id>
<p_name>Shoes</p_name>
</product>
</products>
<locations>
<state>
<s_name>New South Wales</s_name>
<city>
<c_name>Sydney</c_name>
<l_id>01</l_id>
</city>
<city>
<c_name>New England</c_name>
<l_id>02</l_id>
</city>
</state>
<state>
<s_name>Victoria</s_name>
<city>
<c_name>Melbourne</c_name>
<l_id>03</l_id>
</city>
</state>
<state>
<s_name>Queensland</s_name>
<city>
<c_name>Brisbane</c_name>
<l_id>04</l_id>
</city>
</state>
</locations>
<time>
<year>
<y_name>2003</y_name>
<month>
<m_name>06</m_name>
<date>
<d_name>02</d_name>
<t_id>02-06-2003</t_id>
</date>
<date>
<d_name>22</d_name>
<t_id>22-06-2003</t_id>
</date>
</month>
<month>
<m_name>07</m_name>
<date>
<d_name>22</d_name>
<t_id>22-07-2003</t_id>
</date>
</month>
</year>
<year>
<y_name>2004</y_name>
<month>
<m_name>06</m_name>
<date>
<d_name>13</d_name>
<t_id>13-06-2004</t_id>
</date>
</month>
<month>
<m_name>07</m_name>
<date>
<d_name>02</d_name>
<t_id>02-07-2004</t_id>
</date>
</month>
</year>
</time>
</sales>
And I want to generate XSL code that summarize the data into the format like this:
Year=...
---------------------------------------------------------------------------------
States(rows)/Products(columns) | Glasses | Clothes | Shoes | TOTAL
---------------------------------------------------------------------------------
New South Wales | xxxx | xxxxx | xxxxx | xxxx
---------------------------------------------------------------------------------
Victoria | xxxx | xxxx | xxxx | xxxx
---------------------------------------------------------------------------------
Queensland | xxxx | xxxx | xxxx | xxxx
---------------------------------------------------------------------------------
TOTAL | xxxx | xxxx | xxxx | xxxx
---------------------------------------------------------------------------------
Year=...
---------------------------------------------------------------------------------
States(rows)/Products(columns) | Glasses | Clothes | Shoes | TOTAL
---------------------------------------------------------------------------------
New South Wales | xxxx | xxxxx | xxxxx | xxxx
---------------------------------------------------------------------------------
Victoria | xxxx | xxxx | xxxx | xxxx
---------------------------------------------------------------------------------
Queensland | xxxx | xxxx | xxxx | xxxx
---------------------------------------------------------------------------------
TOTAL | xxxx | xxxx | xxxx | xxxx
---------------------------------------------------------------------------------
I've tried for a number of codes I can think, but all ended up with the error "VariableReference given for variable out of context or without definition!"
I've no idea what should I do. Can you help me to find a way to map the data from this XML file into a summarized detail?
Thank you for any suggestion.
PS. I'm fairly new to XSLT. The solution of this problem might be easier than I think.
|