 |
| 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 Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
|
|
|
|

July 10th, 2008, 07:27 AM
|
|
Authorized User
|
|
Join Date: Jul 2008
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, 09:11 AM
|
 |
Wrox Author
|
|
Join Date: Apr 2004
Posts: 4,962
Thanks: 0
Thanked 292 Times in 287 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, 03:47 AM
|
|
Authorized User
|
|
Join Date: Jul 2008
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, 04:04 AM
|
 |
Wrox Author
|
|
Join Date: Apr 2004
Posts: 4,962
Thanks: 0
Thanked 292 Times in 287 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, 04:44 AM
|
|
Authorized User
|
|
Join Date: Jul 2008
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, 04:56 AM
|
 |
Friend of Wrox
|
|
Join Date: Aug 2007
Posts: 2,128
Thanks: 1
Thanked 189 Times in 188 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, 04:59 AM
|
 |
Wrox Author
|
|
Join Date: Apr 2004
Posts: 4,962
Thanks: 0
Thanked 292 Times in 287 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
|
|
 |