p2p.wrox.com Forums

Need to download code?

View our list of code downloads.


Go Back   p2p.wrox.com Forums > XML > XSLT
I forgot my password Register Now
Register | FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read
XSLT General questions and answers about XSLT. For issues strictly specific to the book XSLT 1.1 Programmers Reference, please post to that forum instead.

Welcome to the p2p.wrox.com Forums.

You are currently viewing the XSLT section of the Wrox p2p Programmer to Programmer discussion community. This is a community of more than 40,000 computer programmers including Wrox book authors and readers. As a guest, you can read any forum posting. By joining our free Wrox p2p community you can post your own programming questions and respond to other programmers’ questions. Registered users also don't have to see the ads that are displayed to guests. Registration is fast, simple and absolutely free so please, join today!
Join today and post to win prizes! Post more to increase your chances of being Wrox’s top poster of the month.

Reply
 
Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old July 10th, 2008, 08:27 AM
Authorized User
 
Join Date: Jul 2008
Location: , , .
Posts: 19
Thanks: 0
Thanked 0 Times in 0 Posts
Default how to merge two records of xml

My xml contains the reords of an employee shift and it's task. so it might be possible that one employee in one has to do many task. so my xml contains the reords as:
 <Detail>
    <idShiftNo>72</idShiftNo>
    <idEmployee>221265</idEmployee>
    <NameEmployee>Biswal, Antje</NameEmployee>
    <Date>2007-01-05T00:00:00+05:30</Date>
    <Department>1</Department>
    <ShiftName>F11</ShiftName>
    <ShiftStart>2007-01-05T02:30:00+05:30</ShiftStart>
    <ShiftEnd>2007-01-05T11:00:00+05:30</ShiftEnd>
    <idTaskNo>324</idTaskNo>
    <strNameJob>C-DE</strNameJob>
    <idTaskNo1>324</idTaskNo1>
    <TaskStart>2007-01-05T02:30:00+05:30</TaskStart>
    <TaskEnd>2007-01-05T04:15:00+05:30</TaskEnd>
    <TaskName>C-DE5824</TaskName>
    #000000
    <backColorHTML>#C0C0C0</backColorHTML>
    <ToolTip>Flight: Job: C-DE Task:C-DE5824 STA: STD: 03:45 AcOP: DE AcType: 320 Dest: TFS

PaxMax: 174 PaxBkd: 176</ToolTip>
  </Detail>
  <Detail>
    <idShiftNo>72</idShiftNo>
    <idEmployee>221265</idEmployee>
    <NameEmployee>Biswal, Antje</NameEmployee>
    <Date>2007-01-05T00:00:00+05:30</Date>
    <Department>1</Department>
    <ShiftName>F11</ShiftName>
    <ShiftStart>2007-01-05T02:30:00+05:30</ShiftStart>
    <ShiftEnd>2007-01-05T11:00:00+05:30</ShiftEnd>
    <idTaskNo>292</idTaskNo>
    <strNameJob>BO</strNameJob>
    <idTaskNo1>292</idTaskNo1>
    <TaskStart>2007-01-05T04:15:00+05:30</TaskStart>
    <TaskEnd>2007-01-05T04:55:00+05:30</TaskEnd>
    <TaskName>DE5824</TaskName>
    #000000
    <backColorHTML>#C0C0C0</backColorHTML>
    <ToolTip>Flight: Job: BO Task:DE5824 STA: STD: 03:45 AcOP: DE AcType: 320 Dest: TFS PaxMax:

174 PaxBkd: 176</ToolTip>
  </Detail>

The problem is that as i have to show this on a chart then there it shows as

72 Biswal, Antje shiftstarttime shiftendtime task1
72 Biswal, Antje shiftstarttime shiftendtime task2

but i wan't to show it like
72 Biswal, Antje shiftstarttime shiftendtime task1 task2


i have done to display the id,name,shiftstart and end as thay are same in all by just using distinct
72 Biswal, Antje shiftstarttime shiftendtime

but how can i merge the two task records .


please help me in this
m waiting for ur replies :(






Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Reddit!
Reply With Quote
  #2 (permalink)  
Old July 10th, 2008, 10:11 AM
mhkay's Avatar
Wrox Author
Points: 12,738, Level: 48
Points: 12,738, Level: 48 Points: 12,738, Level: 48 Points: 12,738, Level: 48
Activity: 100%
Activity: 100% Activity: 100% Activity: 100%
 
Join Date: Apr 2004
Location: Reading, Berks, United Kingdom.
Posts: 3,924
Thanks: 0
Thanked 82 Times in 80 Posts
Default

This problem is known as grouping, and if you google for "XSLT Grouping" (or preferably, look it up in your favourite XSLT textbook) you will find lots of information on the subject. It's very easy in XSLT 2.0 using the <xsl:for-each-group> instruction. It'd rather harder in XSLT 1.0, but there are well-known techniques.

Michael Kay
http://www.saxonica.com/
Author, XSLT Programmer's Reference and XPath 2.0 Programmer's Reference
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Reddit!
Reply With Quote
  #3 (permalink)  
Old July 11th, 2008, 04:47 AM
Authorized User
 
Join Date: Jul 2008
Location: , , .
Posts: 19
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Thanx for ur reply but as m new to xslt can u solve my problem as how can we merge the two records here.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Reddit!
Reply With Quote
  #4 (permalink)  
Old July 11th, 2008, 05:04 AM
mhkay's Avatar
Wrox Author
Points: 12,738, Level: 48
Points: 12,738, Level: 48 Points: 12,738, Level: 48 Points: 12,738, Level: 48
Activity: 100%
Activity: 100% Activity: 100% Activity: 100%
 
Join Date: Apr 2004
Location: Reading, Berks, United Kingdom.
Posts: 3,924
Thanks: 0
Thanked 82 Times in 80 Posts
Default

Sorry, I don't solve problems for people, I try to help people solve them for themselves.

Michael Kay
http://www.saxonica.com/
Author, XSLT Programmer's Reference and XPath 2.0 Programmer's Reference
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Reddit!
Reply With Quote
  #5 (permalink)  
Old July 11th, 2008, 05:44 AM
Authorized User
 
Join Date: Jul 2008
Location: , , .
Posts: 19
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Sorry sir but u r getting me wrong as m searching on xslt grouping and able to find the distinct records but not able to get merge two records

what m doing is as:
xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:foo="http://whatever">



  <xsl:key name="distinctShift" match="NewDataSet/Detail" use="./idShiftNo"/>

 <xsl:for-each select="NewDataSet/Detail[generate-id() = generate-id(key('distinctShift', ./idShiftNo))]">
<xsl:template match="/">
<table>
<tr>
                <td>
                  <xsl:value-of select="idShiftNo"/>
                </td>
                <td>
                  <xsl:value-of select="ShiftName"/>
                </td>
</tr>
</table>
</xsl:template>
</xsl:stylesheet>
not able to get record combine

Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Reddit!
Reply With Quote
  #6 (permalink)  
Old July 11th, 2008, 05:56 AM
samjudson's Avatar
Friend of Wrox
Points: 4,453, Level: 28
Points: 4,453, Level: 28 Points: 4,453, Level: 28 Points: 4,453, Level: 28
Activity: 61%
Activity: 61% Activity: 61% Activity: 61%
 
Join Date: Aug 2007
Location: Newcastle, , United Kingdom.
Posts: 1,359
Thanks: 0
Thanked 31 Times in 31 Posts
Default

Looks like you are close, but your for-each loop is in the wrong place.

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



<xsl:key name="distinctShift" match="NewDataSet/Detail" use="./idShiftNo"/>

<xsl:template match="/">

<table>

<xsl:for-each select="NewDataSet/Detail[generate-id() = generate-id(key('distinctShift', ./idShiftNo)[1])]">
  <tr>
    <td>
      <xsl:value-of select="idShiftNo"/>
    </td>
    <td>
      <xsl:value-of select="ShiftName"/>
    </td>
    <td>
      <xsl:for-each select="/NewDataSet/Detail[idShiftNo = current()/idShiftNo]">
        <xsl:if test="position() != 1">,</xsl:if>
        <xsl:value-of select="idTaskNo"/>
      </xsl:for-each>
    </td>
  </tr>
</xsl:for-each>
</table>
</xsl:template>

</xsl:stylesheet>

I think that might do what you want.

/- Sam Judson : Wrox Technical Editor -/
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Reddit!
Reply With Quote
  #7 (permalink)  
Old July 11th, 2008, 05:59 AM
mhkay's Avatar
Wrox Author
Points: 12,738, Level: 48
Points: 12,738, Level: 48 Points: 12,738, Level: 48 Points: 12,738, Level: 48
Activity: 100%
Activity: 100% Activity: 100% Activity: 100%
 
Join Date: Apr 2004
Location: Reading, Berks, United Kingdom.
Posts: 3,924
Thanks: 0
Thanked 82 Times in 80 Posts
Default

In Muenchian grouping there is always an outer loop, which selects one element for each group, and an inner loop, which processes all the elements of the group. Your code has the outer loop, so it executes once for each group, but is missing the inner loop, which you will need to get the values (such as task1, task2) that are different between different elements in the group.

(The code also seems to have got mangled somehow, it has the for-each outside an xsl:template. I assume that's just carelessness, of the same kind that causes you to write in text shorthand. You need to cure yourself of this - careless people never make good programmers.)

Michael Kay
http://www.saxonica.com/
Author, XSLT Programmer's Reference and XPath 2.0 Programmer's Reference
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Reddit!
Reply With Quote
Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off
Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
How to merge two xml documents together? NewToXSL Pro VB.NET 2002/2003 2 August 22nd, 2008 06:28 AM
merge Records from 2 databases keturpatel Access VBA 4 September 22nd, 2007 10:56 AM
merge two xml file and make new xml using xslt ketan XSLT 0 September 21st, 2004 09:48 AM
XML Merge... babloo81 XML 3 November 14th, 2003 06:44 AM
Merge XML files into a xml file using xslt lxu XML 4 November 6th, 2003 06:01 PM



All times are GMT -4. The time now is 06:59 AM.


Powered by vBulletin® Version 3.6.8
Copyright ©2000 - 2009, Jelsoft Enterprises Ltd.
© 2008 Wiley Publishing, Inc