Grouping, Relating or is it Merging Data ?

Discussion in 'XML' started by Jon Bosker, Sep 26, 2003.

  1. Jon Bosker

    Jon Bosker Guest

    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!
     
    Jon Bosker, Sep 26, 2003
    #1
    1. Advertising

  2. So what is the contents of the two xml files?

    =====
    Cheers,

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


    "Jon Bosker" <> wrote in message
    news:...
    > 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!
     
    Dimitre Novatchev, Sep 27, 2003
    #2
    1. Advertising

  3. Jon Bosker

    Jon Bosker Guest

    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>



    *** Sent via Developersdex http://www.developersdex.com ***
    Don't just participate in USENET...get rewarded for it!
     
    Jon Bosker, Sep 27, 2003
    #3
  4. 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


    "Jon Bosker" <> wrote in message
    news:3f7587e7$0$62080$...
    > 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>
    >
    >
    >
    > *** Sent via Developersdex http://www.developersdex.com ***
    > Don't just participate in USENET...get rewarded for it!
     
    Dimitre Novatchev, Sep 27, 2003
    #4
  5. Jon Bosker

    Jon Bosker Guest

    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

    *** Sent via Developersdex http://www.developersdex.com ***
    Don't just participate in USENET...get rewarded for it!
     
    Jon Bosker, Sep 28, 2003
    #5
  6. 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



    "Jon Bosker" <> wrote in message
    news:3f76c44e$0$62083$...
    > 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
    >
    > *** Sent via Developersdex http://www.developersdex.com ***
    > Don't just participate in USENET...get rewarded for it!
    >
     
    Dimitre Novatchev, Sep 28, 2003
    #6
  7. Jon Bosker

    Jon Bosker Guest

    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>
     
    Jon Bosker, Sep 29, 2003
    #7
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Chipmunk
    Replies:
    2
    Views:
    317
    Eric Lawrence [MSFT]
    Feb 23, 2004
  2. Leo
    Replies:
    13
    Views:
    587
    James McGill
    Feb 28, 2006
  3. duddle13
    Replies:
    4
    Views:
    350
    Arvind
    May 9, 2006
  4. John Walton
    Replies:
    2
    Views:
    241
    Roel Schroeven
    Sep 23, 2005
  5. Al Cadalzo

    new Menu control and relating pages in a 'grouping'

    Al Cadalzo, Jan 12, 2006, in forum: ASP .Net Web Controls
    Replies:
    0
    Views:
    135
    Al Cadalzo
    Jan 12, 2006
Loading...

Share This Page