|
|
 |
| 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.
|
 |

July 10th, 2008, 08:27 AM
|
|
Authorized User
|
|
Join Date: Jul 2008
Location: , , .
Posts: 19
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
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 :(
|

July 10th, 2008, 10:11 AM
|
 |
Wrox Author
Points: 12,738, Level: 48 |
|
|
Join Date: Apr 2004
Location: Reading, Berks, United Kingdom.
Posts: 3,924
Thanks: 0
Thanked 82 Times in 80 Posts
|
|
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
|

July 11th, 2008, 04:47 AM
|
|
Authorized User
|
|
Join Date: Jul 2008
Location: , , .
Posts: 19
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
Thanx for ur reply but as m new to xslt can u solve my problem as how can we merge the two records here.
|

July 11th, 2008, 05:04 AM
|
 |
Wrox Author
Points: 12,738, Level: 48 |
|
|
Join Date: Apr 2004
Location: Reading, Berks, United Kingdom.
Posts: 3,924
Thanks: 0
Thanked 82 Times in 80 Posts
|
|
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
|

July 11th, 2008, 05:44 AM
|
|
Authorized User
|
|
Join Date: Jul 2008
Location: , , .
Posts: 19
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
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
|

July 11th, 2008, 05:56 AM
|
 |
Friend of Wrox
|
|
Join Date: Aug 2007
Location: Newcastle, , United Kingdom.
Posts: 1,359
Thanks: 0
Thanked 31 Times in 31 Posts
|
|
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 -/
|

July 11th, 2008, 05:59 AM
|
 |
Wrox Author
Points: 12,738, Level: 48 |
|
|
Join Date: Apr 2004
Location: Reading, Berks, United Kingdom.
Posts: 3,924
Thanks: 0
Thanked 82 Times in 80 Posts
|
|
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
|
| Thread Tools |
Search this Thread |
|
|
|
| Display Modes |
Linear Mode
|
Posting Rules
|
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
HTML code is Off
|
|
|
|
 |