Subject: [xsl] Sum of multiple elements|
From: "Chad Gorshing" <gorshing@xxxxxxxxx>
Date: Fri, 29 Jun 2007 15:47:59 -0500
I have an instance document, input.xml below, that I have to perform a sum on multiple elements. As you can see in my instance document, I perform the sum function with the 'count' element. I believe this is going to mainly be a grouping problem.
I need to sum all of: * Sex, Grade, Race - (All males, in grade 01, of race HI) * Sex, Grade - (All males in grade 01) * Sex, Race - (All males of race HI) * Grade, Race - (Everybody of race HI in grade 01)
These totals are repeated for about 15 grades, and 6 races, and of course once for male and another time for females. So 15 * 6 = 90 ... 90 * 2 = 180 combinations. You can see where my concern lies.
My instance document can be as large as (or possibly even larger than) 20MB. So with a document that big and with all the combinations ... well ... I'm just plain scared :)
I would like to open the door for suggestions on the best way to handle this. I would assume this is best left up to something such as a DBMS, but I am currently stuck with this scenario. I do also have access to the schema, so reading the possible values from a schema is also an option instead of traversing the document.
The project will be a C# 2.0 app, but for testing and developing of the transform I am using xalan 1.10.0 with xerces 2.7.0 ... so no XSLT 2.0 possible.
input.xml ==================== <?xml version="1.0" ?> <data xmlns="http://schemas.somewhere.com/class.xsd"> <district num="1234"> <local num="1234-12"> <class> <grade>01</grade> <race>HI</race> <gender>M</gender> <count>26</count> </class> <class> <grade>PK</grade> <race>AM</race> <gender>M</gender> <count>2</count> </class> </local> <local num="1234-12"> <class> <grade>KG</grade> <race>HI</race> <gender>F</gender> <count>21</count> </class> <class> <grade>KG</grade> <race>HI</race> <gender>F</gender> <count>7</count> </class> </local> </district> </data>