Best way to group data (in XML)

  • Thread starter Thread starter jehugaleahsa
  • Start date Start date
J

jehugaleahsa

Hello:

I have an XML file that contains records with a Date attribute. I
would like to group all the records together with a particular date,
so that I can later iterate over the different dates to calculate
information based on the contained records.

So, for instance, I have sales records for every day in the year, I
would like to calculate the total sales for each week in the year. So
I need to be able to group by weeks. Is there a tool for XML that will
allow me to group like this?

Thanks,
Travis
 
I have an XML file that contains records with a Date attribute. I
would like to group all the records together with a particular date,
so that I can later iterate over the different dates to calculate
information based on the contained records.

So, for instance, I have sales records for every day in the year, I
would like to calculate the total sales for each week in the year. So
I need to be able to group by weeks. Is there a tool for XML that will
allow me to group like this?

XSLT 2.0 or XQuery are languages to perform the grouping. Saxon 9 from
<http://saxon.sourceforge.net/> implements both XSLT 2.0 and XQuery and
has a .NET version.
Grouping can also be done with XSLT 1.0 where the .NET framework has an
implementation with System.Xml.Xsl.XslCompiledTransform.
 
XSLT 2.0 or XQuery are languages to perform the grouping. Saxon 9 from
<http://saxon.sourceforge.net/> implements both XSLT 2.0 and XQuery and
has a .NET version.
Grouping can also be done with XSLT 1.0 where the .NET framework has an
implementation with System.Xml.Xsl.XslCompiledTransform.

Thanks. I have an implementation using the xsl:key element with XSLT.
I will stick with that. I think I will look at XQuery while I'm at it.

Thanks again,
Travis
 
I have an XML file that contains records with a Date attribute. I
would like to group all the records together with a particular date,
so that I can later iterate over the different dates to calculate
information based on the contained records.

So, for instance, I have sales records for every day in the year, I
would like to calculate the total sales for each week in the year. So
I need to be able to group by weeks. Is there a tool for XML that will
allow me to group like this?

Do you mean you want to group the records in the original XML file, or
you want to process an XML file which has ungrouped data and group the
data in memory?

If it's the latter, and if .NET 3.5 is an option, I suggest you look at
LINQ to XML. It's nice and powerful :)
 
Do you mean you want to group the records in the original XML file, or
you want to process an XML file which has ungrouped data and group the
data in memory?

If it's the latter, and if .NET 3.5 is an option, I suggest you look at
LINQ to XML. It's nice and powerful :)

I have looked at it. It is pretty spiffy. Unfortunately we are in a
transition period. Hopefully soon!
 
I have looked at it. It is pretty spiffy. Unfortunately we are in a
transition period. Hopefully soon!

I suspect there are more than a few of us in exactly that situation :)

Fortunately I get to use .NET 3.5 for my book's web site, so I do get
to do more than "toy" projects in it - although the web site is tiny
anyway, really.
 
Why not translate it to XSD using the tool for that.

And then generate a stronly typed dataset class for it.

Load in the instanced version of that your XML

You can iterate in that in almost every way you want.

Cor
 
The classic answer for such in xslt would be "Muenchian Grouping";
since you are using xsl:key, I suspect you are more than half-way
there anyway ;-p

Just search for the above term; very easy to use, and very quick. Of
course, it'll help if your week-number is already in the data,
otherwise you might need a method to do that first...

Marc
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads

Removing Offsetting XML Nodes 5
Declarations within Xml Schema 3
Linq to Xml 1
SQL query to XML 2
Help with XML 10
XML to Dictionary using LINQ 2
Mixing linq to sql and linq to xml (in linqpad) 2
Searching XML 5

Back
Top