Grouping, Relating or is it Merging Data ?

J

Jon Bosker

Help! This is probably easy but I just don't get it. I am trying to
relate and merge 2 datasets. My XML file has 2 datasets (1st level
nodes) TimeDetail and TimeSummary. The report is supposed to show the
TimeDetail rows then the TimeSummary row. Like this:
Task1 9:20 9:30 0:10 <-- from TimeDetail
Task2 9:30 10:00 0:30
TOTAL 0:40 <-- from TimeSummary

(The reason I am using 2 datasets is because I figured it was easier
doing the minutes to time conversion in .net but I could review that)

So the question is: How do I merge the 2 datasets? i.e. how do I
relate the data in TimeDetail to the data in TimeSummary? I have
things like
<xsl:for-each select = "/DS/TimeSummary">
<xsl:for-each select = "/DS/TimeDetail[Date=/DS/SummaryData/Date]">
... output the task, times etc
</xsl:for-each>
... output the TOTAL
</xsl:for-each>

So the filter [Date=/DS/SummaryData/Date] is not working as I want it
because it is not filtering... but I hope you can see the intention!
 
J

Jon Bosker

Here is a cut down version:

<?xml version="1.0" standalone="yes"?>
<NewDataSet>

<timeDataDetails>
<Date>8/08/2003</Date>
<Minutes>34</Minutes>
</timeDataDetails>
<timeDataDetails>
<Date>8/08/2003</Date>
<Minutes>28</Minutes>
</timeDataDetails>
<timeDataDetails>
<Date>9/08/2003</Date>
<Minutes>7</Minutes>
</timeDataDetails>

<summaryData>
<Date>8/08/2003</Date>
<TotalMinutes>1:01</TotalMinutes>
</summaryData>
<summaryData>
<Date>9/08/2003</Date>
<TotalMinutes>0:07</TotalMinutes>
</summaryData>

</NewDataSet>
 
D

Dimitre Novatchev

I don't see:
Task1 9:20 9:30 0:10 <-- from TimeDetail
Task2 9:30 10:00 0:30

any such data in your source xml...

Based on the source.xml you provided, what transformation do you want to be
performed and what exactly should the output be?


=====
Cheers,

Dimitre Novatchev.
http://fxsl.sourceforge.net/ -- the home of FXSL
 
J

Jon Bosker

Sorry about that - the first posting I was explaining the concept but in
the second I cut it down to the essential data. Of course there are
tags for the start and end times but I felt that they were not relevant
here as I am only having problems with the grouping/summing aspect.

Based on the source I have sent I want the output to be:

Date Minutes
--------- --------
8/08/2003 34
8/08/2003 28
Total 1:02

9/8/2003 7
Total 0:07

Thanks for being so patient with me :)

Regards, Jon
 
D

Dimitre Novatchev

This is straightforward:

<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">

<xsl:eek:utput method="text"/>

<xsl:template match="/">
<xsl:value-of select="'Date Minutes
---- -------'"/>
<xsl:apply-templates select="*/summaryData"/>
</xsl:template>

<xsl:template match="summaryData">
<xsl:apply-templates select="../timeDataDetails[Date =
current()/Date]"/>
<xsl:value-of select="concat('
','Total ', TotalMinutes,
'
')"/>
</xsl:template>

<xsl:template match="timeDataDetails">
<xsl:value-of select="concat('
', Date, ' ', Minutes)"/>
</xsl:template>
</xsl:stylesheet>

When this transformation is applied on your source.xml:

<NewDataSet>
<timeDataDetails>
<Date>8/08/2003</Date>
<Minutes>34</Minutes>
</timeDataDetails>
<timeDataDetails>
<Date>8/08/2003</Date>
<Minutes>28</Minutes>
</timeDataDetails>
<timeDataDetails>
<Date>9/08/2003</Date>
<Minutes>7</Minutes>
</timeDataDetails>
<summaryData>
<Date>8/08/2003</Date>
<TotalMinutes>1:01</TotalMinutes>
</summaryData>
<summaryData>
<Date>9/08/2003</Date>
<TotalMinutes>0:07</TotalMinutes>
</summaryData>
</NewDataSet>

the wanted result is produced:

Date Minutes
---- -------
8/08/2003 34
8/08/2003 28
Total 1:01

9/08/2003 7
Total 0:07



=====
Cheers,

Dimitre Novatchev.
http://fxsl.sourceforge.net/ -- the home of FXSL
 
J

Jon Bosker

Many thanks Dimitre - that worked a treat! :)
Regards, Jon

PS my final XSL looks something like this:
<?xml version="1.0" encoding="ISO-8859-1"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:template match="/">
<html>
<body>
<table>
<tr>
<th>Date</th>
<th>Project</th>
<th>Task</th>
<th>Start Time</th>
<th>End Time</th>
<th>Hours</th>
</tr>
<xsl:for-each select="/NewDataSet/SummaryData">
<xsl:for-each select="/NewDataSet/timeDataDetails[Date = current()/Date]">
<tr>
<td><xsl:value-of select="Date"/></td>
<td><xsl:value-of select="Project"/></td>
<td><xsl:value-of select="Task"/></td>
<td><xsl:value-of select="StartTime"/></td>
<td><xsl:value-of select="EndTime"/></td>
<td><xsl:value-of select="Time"/></td>
</tr>
</xsl:for-each>
<tr>
<td><xsl:value-of select="Date"/></td>
<td>=== </td>
<td></td>
<td></td>
<td>Total</td>
<td><xsl:value-of select="TotalTime"/></td>
</tr>
</xsl:for-each>
</table>
</body>
</html>
</xsl:template>
</xsl:stylesheet>
 

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

Members online

Forum statistics

Threads
473,769
Messages
2,569,579
Members
45,053
Latest member
BrodieSola

Latest Threads

Top