我有一个项目,我需要在 XML 文档的标签中获取和计算不同的值。如果您查看 XML,我会特别尝试计算周二的 WorkOrderNumbers 的不同数量。稍后我会在星期一等。我已经尝试了以下代码。
<xsl:variable name="tmp" select="count(//Tuesday/TimeDetail/WorkOrderNumber[generate-id() = generate-id(key('distinctWorkOrder', .)[1])])"></xsl:variable>
这返回 2。我也试过这个
<xsl:variable name="tmp2" select="count(//Tuesday/TimeDetail/WorkOrderNumber[not(.=/preceding-sibling::WorkOrderNumber)])"></xsl:variable>
它返回 4。正确答案是 3。
我在下面添加了 XML。有人可以指出我做错了什么吗?非常感谢。
<Timesheet>
<WeekEnding>Sep 18, 2011</WeekEnding>
<JobNumber>00010-5523</JobNumber>
<Customer>Test Company INC</Customer>
<TeamMember>
<EmployeeNumber>10566</EmployeeNumber>
<EmployeeName>Employee, One</EmployeeName>
<EmployeeClass>Class</EmployeeClass>
<Monday>
<TimeDetail>
<StartTime>Start</StartTime>
<StopTime>Stop</StopTime>
<WorkOrderNumber>14963</WorkOrderNumber>
<RegularHours>8</RegularHours>
<OverTimeHours>3</OverTimeHours>
<OtherHours>4 - Holiday</OtherHours>
<Notes>I took the afternoon off.</Notes>
</TimeDetail>
</Monday>
<Tuesday>
<TimeDetail>
<StartTime>Start</StartTime>
<StopTime>Stop</StopTime>
<WorkOrderNumber>14963</WorkOrderNumber>
<RegularHours>5</RegularHours>
<OverTimeHours>Over Time</OverTimeHours>
<OtherHours>Other</OtherHours>
<Notes>Notes</Notes>
</TimeDetail>
<TimeDetail>
<StartTime>Start</StartTime>
<StopTime>Stop</StopTime>
<WorkOrderNumber>15101</WorkOrderNumber>
<RegularHours>2</RegularHours>
<OverTimeHours>Over Time</OverTimeHours>
<OtherHours>Other</OtherHours>
<Notes>Notes</Notes>
</TimeDetail>
</Tuesday>
<Wednesday>
<TimeDetail>
<StartTime>Start</StartTime>
<StopTime>Stop</StopTime>
<WorkOrderNumber>14963</WorkOrderNumber>
<RegularHours>5</RegularHours>
<OverTimeHours>Over Time</OverTimeHours>
<OtherHours>Other</OtherHours>
<Notes>Notes</Notes>
</TimeDetail>
</Wednesday>
<Thursday>
<TimeDetail>
<StartTime>Start</StartTime>
<StopTime>Stop</StopTime>
<WorkOrderNumber>14963</WorkOrderNumber>
<RegularHours>5</RegularHours>
<OverTimeHours>Over Time</OverTimeHours>
<OtherHours>Other</OtherHours>
<Notes>Notes</Notes>
</TimeDetail>
</Thursday>
<Friday>
<TimeDetail>
<StartTime>Start</StartTime>
<StopTime>Stop</StopTime>
<WorkOrderNumber>14963</WorkOrderNumber>
<RegularHours>5</RegularHours>
<OverTimeHours>2</OverTimeHours>
<OtherHours>Other</OtherHours>
<Notes>Notes</Notes>
</TimeDetail>
</Friday>
<Saturday>
<TimeDetail>
<StartTime>Start</StartTime>
<StopTime>Stop</StopTime>
<WorkOrderNumber>14963</WorkOrderNumber>
<RegularHours>5</RegularHours>
<OverTimeHours>Over Time</OverTimeHours>
<OtherHours>Other</OtherHours>
<Notes>Notes</Notes>
</TimeDetail>
</Saturday>
<Sunday>
<TimeDetail>
<StartTime>Start</StartTime>
<StopTime>Stop</StopTime>
<WorkOrderNumber>14963</WorkOrderNumber>
<RegularHours>5</RegularHours>
<OverTimeHours>1</OverTimeHours>
<OtherHours>Other</OtherHours>
<Notes>Notes</Notes>
</TimeDetail>
</Sunday>
</TeamMember>
<TeamMember>
<EmployeeNumber>81135</EmployeeNumber>
<EmployeeName>Employee, Two</EmployeeName>
<EmployeeClass>Class</EmployeeClass>
<Monday>
<TimeDetail>
<StartTime>Start</StartTime>
<StopTime>Stop</StopTime>
<WorkOrderNumber>15100</WorkOrderNumber>
<RegularHours>5</RegularHours>
<OverTimeHours>Over Time</OverTimeHours>
<OtherHours>1 - Company Meetings</OtherHours>
<Notes>These are my notes.</Notes>
</TimeDetail>
<TimeDetail>
<StartTime>Start</StartTime>
<StopTime>Stop</StopTime>
<WorkOrderNumber>22965</WorkOrderNumber>
<RegularHours>7</RegularHours>
<OverTimeHours>Over Time</OverTimeHours>
<OtherHours>Other</OtherHours>
<Notes>Notes</Notes>
</TimeDetail>
<TimeDetail>
<StartTime>Start</StartTime>
<StopTime>Stop</StopTime>
<WorkOrderNumber>23570</WorkOrderNumber>
<RegularHours>Regular</RegularHours>
<OverTimeHours>1</OverTimeHours>
<OtherHours>Other</OtherHours>
<Notes>Notes</Notes>
</TimeDetail>
</Monday>
<Tuesday></Tuesday>
<Wednesday></Wednesday>
<Thursday>
<TimeDetail>
<StartTime>Start</StartTime>
<StopTime>Stop</StopTime>
<WorkOrderNumber>23591</WorkOrderNumber>
<RegularHours>7</RegularHours>
<OverTimeHours>Over Time</OverTimeHours>
<OtherHours>Other</OtherHours>
<Notes>Notes</Notes>
</TimeDetail>
<TimeDetail>
<StartTime>Start</StartTime>
<StopTime>Stop</StopTime>
<WorkOrderNumber>15100</WorkOrderNumber>
<RegularHours>1</RegularHours>
<OverTimeHours>1</OverTimeHours>
<OtherHours>Other</OtherHours>
<Notes>Test</Notes>
</TimeDetail>
</Thursday>
<Friday></Friday>
<Saturday></Saturday>
<Sunday></Sunday>
</TeamMember>
<TeamMember>
<EmployeeNumber>105779</EmployeeNumber>
<EmployeeName>Employee, Three</EmployeeName>
<EmployeeClass>W</EmployeeClass>
<Monday>
<TimeDetail>
<StartTime>Start</StartTime>
<StopTime>Stop</StopTime>
<WorkOrderNumber>19583</WorkOrderNumber>
<RegularHours>8</RegularHours>
<OverTimeHours>Over Time</OverTimeHours>
<OtherHours>Other</OtherHours>
<Notes>Notes</Notes>
</TimeDetail>
</Monday>
<Tuesday>
<TimeDetail>
<StartTime>Start</StartTime>
<StopTime>Stop</StopTime>
<WorkOrderNumber>15099</WorkOrderNumber>
<RegularHours>1</RegularHours>
<OverTimeHours>7</OverTimeHours>
<OtherHours>Other</OtherHours>
<Notes>Notes</Notes>
</TimeDetail>
</Tuesday>
<Wednesday>
<TimeDetail>
<StartTime>Start</StartTime>
<StopTime>Stop</StopTime>
<WorkOrderNumber>15099</WorkOrderNumber>
<RegularHours>1</RegularHours>
<OverTimeHours>7</OverTimeHours>
<OtherHours>Other</OtherHours>
<Notes>Notes</Notes>
</TimeDetail>
</Wednesday>
<Thursday>
<TimeDetail>
<StartTime>Start</StartTime>
<StopTime>Stop</StopTime>
<WorkOrderNumber>15099</WorkOrderNumber>
<RegularHours>1</RegularHours>
<OverTimeHours>7</OverTimeHours>
<OtherHours>Other</OtherHours>
<Notes>Notes</Notes>
</TimeDetail>
</Thursday>
<Friday>
<TimeDetail>
<StartTime>Start</StartTime>
<StopTime>Stop</StopTime>
<WorkOrderNumber>15099</WorkOrderNumber>
<RegularHours>1</RegularHours>
<OverTimeHours>7</OverTimeHours>
<OtherHours>Other</OtherHours>
<Notes>Notes</Notes>
</TimeDetail>
</Friday>
<Saturday></Saturday>
<Sunday></Sunday>
</TeamMember>