我有以下XML数据:
<Timesheet>
<WeekEnding>Oct 7, 2012</WeekEnding>
<JobNumber>Doe - 508</JobNumber>
<WGNumber>WG No.</WGNumber>
<Customer>Dummy Company</Customer>
<City>Raleigh</City>
<State>North Carolina</State>
<TeamMember>
<EmployeeNumber>101010</EmployeeNumber>
<EmployeeName>Doe, Joseph</EmployeeName>
<EmployeeClass>UCL</EmployeeClass>
<Monday>
<TimeDetail>
<StartTime>Start</StartTime>
<StopTime>Stop</StopTime>
<WorkOrderNumber>safety meeting</WorkOrderNumber>
<RegularHours>.5</RegularHours>
<OverTimeHours>Over Time</OverTimeHours>
<OtherHours>Other</OtherHours>
<PerDiem>NO</PerDiem>
<Notes>Safety meeting</Notes>
</TimeDetail>
<TimeDetail>
<StartTime>Start</StartTime>
<StopTime>Stop</StopTime>
<WorkOrderNumber>rain time</WorkOrderNumber>
<RegularHours>2</RegularHours>
<OverTimeHours>Over Time</OverTimeHours>
<OtherHours>Other</OtherHours>
<PerDiem>NO</PerDiem>
<Notes>Rain time</Notes>
</TimeDetail>
<TimeDetail>
<StartTime>Start</StartTime>
<StopTime>Stop</StopTime>
<WorkOrderNumber>777091</WorkOrderNumber>
<RegularHours>7.5</RegularHours>
<OverTimeHours>Over Time</OverTimeHours>
<OtherHours>Other</OtherHours>
<PerDiem>NO</PerDiem>
<Notes>Capital blvd st lights</Notes>
</TimeDetail>
</Monday>
<Tuesday>
<TimeDetail>
<StartTime>Start</StartTime>
<StopTime>Stop</StopTime>
<WorkOrderNumber>safety meeting</WorkOrderNumber>
<RegularHours>.5</RegularHours>
<OverTimeHours>Over Time</OverTimeHours>
<OtherHours>Other</OtherHours>
<PerDiem>NO</PerDiem>
<Notes>Safety meeting</Notes>
</TimeDetail>
<TimeDetail>
<StartTime>Start</StartTime>
<StopTime>Stop</StopTime>
<WorkOrderNumber>777091</WorkOrderNumber>
<RegularHours>9.5</RegularHours>
<OverTimeHours>Over Time</OverTimeHours>
<OtherHours>Other</OtherHours>
<PerDiem>NO</PerDiem>
<Notes>Capital blvd st lights</Notes>
</TimeDetail>
</Tuesday>
<Wednesday>
<TimeDetail>
<StartTime>Start</StartTime>
<StopTime>Stop</StopTime>
<WorkOrderNumber>5555591</WorkOrderNumber>
<RegularHours>10</RegularHours>
<OverTimeHours>Over Time</OverTimeHours>
<OtherHours>Other</OtherHours>
<PerDiem>NO</PerDiem>
<Notes>Capital blvd st lights</Notes>
</TimeDetail>
</Wednesday>
<Thursday>
<TimeDetail>
<StartTime>Start</StartTime>
<StopTime>Stop</StopTime>
<WorkOrderNumber>111122</WorkOrderNumber>
<RegularHours>10</RegularHours>
<OverTimeHours>Over Time</OverTimeHours>
<OtherHours>Other</OtherHours>
<PerDiem>NO</PerDiem>
<Notes>120 sigma dr</Notes>
</TimeDetail>
</Thursday>
<Friday>
<TimeDetail>
<StartTime>Start</StartTime>
<StopTime>Stop</StopTime>
<WorkOrderNumber>999935</WorkOrderNumber>
<RegularHours>Regular</RegularHours>
<OverTimeHours>8</OverTimeHours>
<OtherHours>Other</OtherHours>
<PerDiem>NO</PerDiem>
<Notes>St light job Progress to pay half time</Notes>
</TimeDetail>
</Friday>
<Saturday></Saturday>
<Sunday></Sunday>
</TeamMember>
<TeamMember>
<EmployeeNumber>606060</EmployeeNumber>
<EmployeeName>Does, Stephen</EmployeeName>
<EmployeeClass>EO</EmployeeClass>
<Monday>
<TimeDetail>
<StartTime>Start</StartTime>
<StopTime>Stop</StopTime>
<WorkOrderNumber>safety meeting</WorkOrderNumber>
<RegularHours>.5</RegularHours>
<OverTimeHours>Over Time</OverTimeHours>
<OtherHours>Other</OtherHours>
<PerDiem>NO</PerDiem>
<Notes>Safety meeting</Notes>
</TimeDetail>
<TimeDetail>
<StartTime>Start</StartTime>
<StopTime>Stop</StopTime>
<WorkOrderNumber>rain time</WorkOrderNumber>
<RegularHours>2</RegularHours>
<OverTimeHours>Over Time</OverTimeHours>
<OtherHours>Other</OtherHours>
<PerDiem>NO</PerDiem>
<Notes>Rain time</Notes>
</TimeDetail>
<TimeDetail>
<StartTime>Start</StartTime>
<StopTime>Stop</StopTime>
<WorkOrderNumber>777091</WorkOrderNumber>
<RegularHours>7.5</RegularHours>
<OverTimeHours>Over Time</OverTimeHours>
<OtherHours>Other</OtherHours>
<PerDiem>NO</PerDiem>
<Notes>Capital blvd st lights</Notes>
</TimeDetail>
</Monday>
<Tuesday>
<TimeDetail>
<StartTime>Start</StartTime>
<StopTime>Stop</StopTime>
<WorkOrderNumber>safety meeting</WorkOrderNumber>
<RegularHours>.5</RegularHours>
<OverTimeHours>Over Time</OverTimeHours>
<OtherHours>Other</OtherHours>
<PerDiem>NO</PerDiem>
<Notes>Safety meeting</Notes>
</TimeDetail>
<TimeDetail>
<StartTime>Start</StartTime>
<StopTime>Stop</StopTime>
<WorkOrderNumber>777091</WorkOrderNumber>
<RegularHours>9.5</RegularHours>
<OverTimeHours>Over Time</OverTimeHours>
<OtherHours>Other</OtherHours>
<PerDiem>NO</PerDiem>
<Notes>Capital blvd st lights</Notes>
</TimeDetail>
</Tuesday>
<Wednesday>
<TimeDetail>
<StartTime>Start</StartTime>
<StopTime>Stop</StopTime>
<WorkOrderNumber>5555591</WorkOrderNumber>
<RegularHours>10</RegularHours>
<OverTimeHours>Over Time</OverTimeHours>
<OtherHours>Other</OtherHours>
<PerDiem>NO</PerDiem>
<Notes>Capital blvd st lights</Notes>
</TimeDetail>
</Wednesday>
<Thursday></Thursday>
<Friday></Friday>
<Saturday></Saturday>
<Sunday></Sunday>
</TeamMember>
<TeamMember>
<EmployeeNumber>707070</EmployeeNumber>
<EmployeeName>Hancock, Samuel</EmployeeName>
<EmployeeClass>EO</EmployeeClass>
<Monday></Monday>
<Tuesday></Tuesday>
<Wednesday>
<TimeDetail>
<StartTime>Start</StartTime>
<StopTime>Stop</StopTime>
<WorkOrderNumber>5555591</WorkOrderNumber>
<RegularHours>10</RegularHours>
<OverTimeHours>Over Time</OverTimeHours>
<OtherHours>Other</OtherHours>
<PerDiem>NO</PerDiem>
<Notes>Capital blvd st lights</Notes>
</TimeDetail>
</Wednesday>
<Thursday></Thursday>
<Friday></Friday>
<Saturday></Saturday>
<Sunday></Sunday>
</TeamMember>
<TeamMember>
<EmployeeNumber>808080</EmployeeNumber>
<EmployeeName>Franklin, Ben</EmployeeName>
<EmployeeClass>EO</EmployeeClass>
<Monday></Monday>
<Tuesday></Tuesday>
<Wednesday></Wednesday>
<Thursday>
<TimeDetail>
<StartTime>Start</StartTime>
<StopTime>Stop</StopTime>
<WorkOrderNumber>111122</WorkOrderNumber>
<RegularHours>10</RegularHours>
<OverTimeHours>Over Time</OverTimeHours>
<OtherHours>Other</OtherHours>
<PerDiem>NO</PerDiem>
<Notes>120 sigma dr</Notes>
</TimeDetail>
</Thursday>
<Friday></Friday>
<Saturday></Saturday>
<Sunday></Sunday>
</TeamMember>
<TeamMember>
<EmployeeNumber>909090</EmployeeNumber>
<EmployeeName>Doess, Smith</EmployeeName>
<EmployeeClass>UCL</EmployeeClass>
<Monday></Monday>
<Tuesday></Tuesday>
<Wednesday></Wednesday>
<Thursday></Thursday>
<Friday>
<TimeDetail>
<StartTime>Start</StartTime>
<StopTime>Stop</StopTime>
<WorkOrderNumber>999935</WorkOrderNumber>
<RegularHours>4</RegularHours>
<OverTimeHours>4</OverTimeHours>
<OtherHours>Other</OtherHours>
<PerDiem>NO</PerDiem>
<Notes>St light job Progress to pay half time</Notes>
</TimeDetail>
</Friday>
<Saturday></Saturday>
<Sunday></Sunday>
</TeamMember>
我正在遍历员工并使用以下循环显示数据:
<xsl:for-each select="Timesheet/TeamMember[EmployeeNumber!='Employee No.']"></xsl:for-each>
在该循环中,我需要执行另一个循环,该循环将显示员工循环当前位置的员工的不同工作订单。以下是我一直在使用的一些代码。问题是它返回整个XML文件的所有不同工单而不是当前员工。我已经反复重复了几个小时,但我要么在XML文件中得到所有工作订单,要么就是0.有人可以给我一些帮助吗?谢谢。
我在XSLT的顶部声明了这个键
<xsl:key name="distinctWorkOrder" match="//WorkOrderNumber" use="."></xsl:key>
这是我一直试图获得员工工作订单的循环
<xsl:for-each select="..//WorkOrderNumber[generate-id() = generate-id(key('distinctWorkOrder', .)[1])][//EmployeeNumber=$empId])">
更新: 输出是HTML。为了显示员工信息,我这样做了:
<tr style="height:20px;">
<td class="normalBorders" style="text-align:left;">Name</td>
<td class="borderT" style="text-align:center;">
<div style="border-bottom:1px solid black;height:12px;width:200px;">
<xsl:value-of select="EmployeeName"></xsl:value-of>
</div>
</td>
<td colspan="2" class="borderT" style="text-align:right;">Emp. ID#</td>
<td colspan="2" class="borderT" style="text-align:center">
<div style="border-bottom:1px solid black;height:15px; width:100%;display:inline-block;">
<xsl:value-of select="EmployeeNumber"/>
</div>
</td>
<td colspan="2" class="borderT"> </td>
<td rowspan="2" colspan="4" class="borderT borderR">
<div style="width:100%;height:27px;border-bottom:1px solid black;">
<img src="{../Signatures/Path}" style="width:100%;height:34px;"/>
</div>
</td>
</tr>
<tr style="height:20px;">
<td class="borderL" style="text-align:left;">Sign/Date</td>
<td style="text-align:center;">
<div style="border-bottom:1px solid black;height:12px;width:200px;">
<xsl:value-of select="EmployeeName"></xsl:value-of>
</div>
</td>
<td colspan="5"> </td>
<td style="text-align:right;">Approved</td>
</tr>
这里我需要循环并输出与此
类似的工单数据<xsl:for-each select="..//WorkOrderNumber[generate-id() = generate-id(key('distinctWorkOrder', .)[1])][//EmployeeNumber=$empId])">
<tr>
<td class="normalBorders"><xsl:value-of select="//WorkOrderNumber"/></td>
<td>Other data</td>
</tr>
答案 0 :(得分:1)
以下是如何操作(HTML格式留作读者练习):
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output omit-xml-declaration="yes" indent="yes"/>
<xsl:strip-space elements="*"/>
<xsl:key name="kEmpOrder"
match="TeamMember[not(EmployeeNumber='Employee No.')]/*/*/WorkOrderNumber"
use="concat(../../../EmployeeNumber, '+', .)"/>
<xsl:template match="TeamMember">
<Employee>
<xsl:copy-of select="*[starts-with(name(), 'Employee')]"/>
<WorkOrders>
<xsl:copy-of select=
"*/*/WorkOrderNumber
[generate-id()
=
generate-id(key('kEmpOrder',
concat(../../../EmployeeNumber, '+', .)
)[1]
)
]
"/>
</WorkOrders>
</Employee>
</xsl:template>
<xsl:template match="text()"/>
</xsl:stylesheet>
在提供的XML文档上应用此转换时:
<Timesheet>
<WeekEnding>Oct 7, 2012</WeekEnding>
<JobNumber>Doe - 508</JobNumber>
<WGNumber>WG No.</WGNumber>
<Customer>Dummy Company</Customer>
<City>Raleigh</City>
<State>North Carolina</State>
<TeamMember>
<EmployeeNumber>101010</EmployeeNumber>
<EmployeeName>Doe, Joseph</EmployeeName>
<EmployeeClass>UCL</EmployeeClass>
<Monday>
<TimeDetail>
<StartTime>Start</StartTime>
<StopTime>Stop</StopTime>
<WorkOrderNumber>safety meeting</WorkOrderNumber>
<RegularHours>.5</RegularHours>
<OverTimeHours>Over Time</OverTimeHours>
<OtherHours>Other</OtherHours>
<PerDiem>NO</PerDiem>
<Notes>Safety meeting</Notes>
</TimeDetail>
<TimeDetail>
<StartTime>Start</StartTime>
<StopTime>Stop</StopTime>
<WorkOrderNumber>rain time</WorkOrderNumber>
<RegularHours>2</RegularHours>
<OverTimeHours>Over Time</OverTimeHours>
<OtherHours>Other</OtherHours>
<PerDiem>NO</PerDiem>
<Notes>Rain time</Notes>
</TimeDetail>
<TimeDetail>
<StartTime>Start</StartTime>
<StopTime>Stop</StopTime>
<WorkOrderNumber>777091</WorkOrderNumber>
<RegularHours>7.5</RegularHours>
<OverTimeHours>Over Time</OverTimeHours>
<OtherHours>Other</OtherHours>
<PerDiem>NO</PerDiem>
<Notes>Capital blvd st lights</Notes>
</TimeDetail>
</Monday>
<Tuesday>
<TimeDetail>
<StartTime>Start</StartTime>
<StopTime>Stop</StopTime>
<WorkOrderNumber>safety meeting</WorkOrderNumber>
<RegularHours>.5</RegularHours>
<OverTimeHours>Over Time</OverTimeHours>
<OtherHours>Other</OtherHours>
<PerDiem>NO</PerDiem>
<Notes>Safety meeting</Notes>
</TimeDetail>
<TimeDetail>
<StartTime>Start</StartTime>
<StopTime>Stop</StopTime>
<WorkOrderNumber>777091</WorkOrderNumber>
<RegularHours>9.5</RegularHours>
<OverTimeHours>Over Time</OverTimeHours>
<OtherHours>Other</OtherHours>
<PerDiem>NO</PerDiem>
<Notes>Capital blvd st lights</Notes>
</TimeDetail>
</Tuesday>
<Wednesday>
<TimeDetail>
<StartTime>Start</StartTime>
<StopTime>Stop</StopTime>
<WorkOrderNumber>5555591</WorkOrderNumber>
<RegularHours>10</RegularHours>
<OverTimeHours>Over Time</OverTimeHours>
<OtherHours>Other</OtherHours>
<PerDiem>NO</PerDiem>
<Notes>Capital blvd st lights</Notes>
</TimeDetail>
</Wednesday>
<Thursday>
<TimeDetail>
<StartTime>Start</StartTime>
<StopTime>Stop</StopTime>
<WorkOrderNumber>111122</WorkOrderNumber>
<RegularHours>10</RegularHours>
<OverTimeHours>Over Time</OverTimeHours>
<OtherHours>Other</OtherHours>
<PerDiem>NO</PerDiem>
<Notes>120 sigma dr</Notes>
</TimeDetail>
</Thursday>
<Friday>
<TimeDetail>
<StartTime>Start</StartTime>
<StopTime>Stop</StopTime>
<WorkOrderNumber>999935</WorkOrderNumber>
<RegularHours>Regular</RegularHours>
<OverTimeHours>8</OverTimeHours>
<OtherHours>Other</OtherHours>
<PerDiem>NO</PerDiem>
<Notes>St light job Progress to pay half time</Notes>
</TimeDetail>
</Friday>
<Saturday></Saturday>
<Sunday></Sunday>
</TeamMember>
<TeamMember>
<EmployeeNumber>606060</EmployeeNumber>
<EmployeeName>Does, Stephen</EmployeeName>
<EmployeeClass>EO</EmployeeClass>
<Monday>
<TimeDetail>
<StartTime>Start</StartTime>
<StopTime>Stop</StopTime>
<WorkOrderNumber>safety meeting</WorkOrderNumber>
<RegularHours>.5</RegularHours>
<OverTimeHours>Over Time</OverTimeHours>
<OtherHours>Other</OtherHours>
<PerDiem>NO</PerDiem>
<Notes>Safety meeting</Notes>
</TimeDetail>
<TimeDetail>
<StartTime>Start</StartTime>
<StopTime>Stop</StopTime>
<WorkOrderNumber>rain time</WorkOrderNumber>
<RegularHours>2</RegularHours>
<OverTimeHours>Over Time</OverTimeHours>
<OtherHours>Other</OtherHours>
<PerDiem>NO</PerDiem>
<Notes>Rain time</Notes>
</TimeDetail>
<TimeDetail>
<StartTime>Start</StartTime>
<StopTime>Stop</StopTime>
<WorkOrderNumber>777091</WorkOrderNumber>
<RegularHours>7.5</RegularHours>
<OverTimeHours>Over Time</OverTimeHours>
<OtherHours>Other</OtherHours>
<PerDiem>NO</PerDiem>
<Notes>Capital blvd st lights</Notes>
</TimeDetail>
</Monday>
<Tuesday>
<TimeDetail>
<StartTime>Start</StartTime>
<StopTime>Stop</StopTime>
<WorkOrderNumber>safety meeting</WorkOrderNumber>
<RegularHours>.5</RegularHours>
<OverTimeHours>Over Time</OverTimeHours>
<OtherHours>Other</OtherHours>
<PerDiem>NO</PerDiem>
<Notes>Safety meeting</Notes>
</TimeDetail>
<TimeDetail>
<StartTime>Start</StartTime>
<StopTime>Stop</StopTime>
<WorkOrderNumber>777091</WorkOrderNumber>
<RegularHours>9.5</RegularHours>
<OverTimeHours>Over Time</OverTimeHours>
<OtherHours>Other</OtherHours>
<PerDiem>NO</PerDiem>
<Notes>Capital blvd st lights</Notes>
</TimeDetail>
</Tuesday>
<Wednesday>
<TimeDetail>
<StartTime>Start</StartTime>
<StopTime>Stop</StopTime>
<WorkOrderNumber>5555591</WorkOrderNumber>
<RegularHours>10</RegularHours>
<OverTimeHours>Over Time</OverTimeHours>
<OtherHours>Other</OtherHours>
<PerDiem>NO</PerDiem>
<Notes>Capital blvd st lights</Notes>
</TimeDetail>
</Wednesday>
<Thursday></Thursday>
<Friday></Friday>
<Saturday></Saturday>
<Sunday></Sunday>
</TeamMember>
<TeamMember>
<EmployeeNumber>707070</EmployeeNumber>
<EmployeeName>Hancock, Samuel</EmployeeName>
<EmployeeClass>EO</EmployeeClass>
<Monday></Monday>
<Tuesday></Tuesday>
<Wednesday>
<TimeDetail>
<StartTime>Start</StartTime>
<StopTime>Stop</StopTime>
<WorkOrderNumber>5555591</WorkOrderNumber>
<RegularHours>10</RegularHours>
<OverTimeHours>Over Time</OverTimeHours>
<OtherHours>Other</OtherHours>
<PerDiem>NO</PerDiem>
<Notes>Capital blvd st lights</Notes>
</TimeDetail>
</Wednesday>
<Thursday></Thursday>
<Friday></Friday>
<Saturday></Saturday>
<Sunday></Sunday>
</TeamMember>
<TeamMember>
<EmployeeNumber>808080</EmployeeNumber>
<EmployeeName>Franklin, Ben</EmployeeName>
<EmployeeClass>EO</EmployeeClass>
<Monday></Monday>
<Tuesday></Tuesday>
<Wednesday></Wednesday>
<Thursday>
<TimeDetail>
<StartTime>Start</StartTime>
<StopTime>Stop</StopTime>
<WorkOrderNumber>111122</WorkOrderNumber>
<RegularHours>10</RegularHours>
<OverTimeHours>Over Time</OverTimeHours>
<OtherHours>Other</OtherHours>
<PerDiem>NO</PerDiem>
<Notes>120 sigma dr</Notes>
</TimeDetail>
</Thursday>
<Friday></Friday>
<Saturday></Saturday>
<Sunday></Sunday>
</TeamMember>
<TeamMember>
<EmployeeNumber>909090</EmployeeNumber>
<EmployeeName>Doess, Smith</EmployeeName>
<EmployeeClass>UCL</EmployeeClass>
<Monday></Monday>
<Tuesday></Tuesday>
<Wednesday></Wednesday>
<Thursday></Thursday>
<Friday>
<TimeDetail>
<StartTime>Start</StartTime>
<StopTime>Stop</StopTime>
<WorkOrderNumber>999935</WorkOrderNumber>
<RegularHours>4</RegularHours>
<OverTimeHours>4</OverTimeHours>
<OtherHours>Other</OtherHours>
<PerDiem>NO</PerDiem>
<Notes>St light job Progress to pay half time</Notes>
</TimeDetail>
</Friday>
<Saturday></Saturday>
<Sunday></Sunday>
</TeamMember>
</Timesheet>
生成了所需的正确分组结果:
<Employee>
<EmployeeNumber>101010</EmployeeNumber>
<EmployeeName>Doe, Joseph</EmployeeName>
<EmployeeClass>UCL</EmployeeClass>
<WorkOrders>
<WorkOrderNumber>safety meeting</WorkOrderNumber>
<WorkOrderNumber>rain time</WorkOrderNumber>
<WorkOrderNumber>777091</WorkOrderNumber>
<WorkOrderNumber>5555591</WorkOrderNumber>
<WorkOrderNumber>111122</WorkOrderNumber>
<WorkOrderNumber>999935</WorkOrderNumber>
</WorkOrders>
</Employee>
<Employee>
<EmployeeNumber>606060</EmployeeNumber>
<EmployeeName>Does, Stephen</EmployeeName>
<EmployeeClass>EO</EmployeeClass>
<WorkOrders>
<WorkOrderNumber>safety meeting</WorkOrderNumber>
<WorkOrderNumber>rain time</WorkOrderNumber>
<WorkOrderNumber>777091</WorkOrderNumber>
<WorkOrderNumber>5555591</WorkOrderNumber>
</WorkOrders>
</Employee>
<Employee>
<EmployeeNumber>707070</EmployeeNumber>
<EmployeeName>Hancock, Samuel</EmployeeName>
<EmployeeClass>EO</EmployeeClass>
<WorkOrders>
<WorkOrderNumber>5555591</WorkOrderNumber>
</WorkOrders>
</Employee>
<Employee>
<EmployeeNumber>808080</EmployeeNumber>
<EmployeeName>Franklin, Ben</EmployeeName>
<EmployeeClass>EO</EmployeeClass>
<WorkOrders>
<WorkOrderNumber>111122</WorkOrderNumber>
</WorkOrders>
</Employee>
<Employee>
<EmployeeNumber>909090</EmployeeNumber>
<EmployeeName>Doess, Smith</EmployeeName>
<EmployeeClass>UCL</EmployeeClass>
<WorkOrders>
<WorkOrderNumber>999935</WorkOrderNumber>
</WorkOrders>
</Employee>
<强>解释强>:
使用复合键正确使用 Muenchian grouping method 。