我的一个xslt更改了业务规则,我不确定如何处理它。如果查看下面的XML,您将看到我有一个雇员部分和一个设备部分。employee部分有一个嵌套在day标签和TimeDetail标签中的WorkOrderNumber,还有一个嵌套在Equipment -> EquipmentWorkOrder中的EquipmentWorkOrderNumber。
我过去只需要获得不同的WorkOrderNumber,因为在WorkOrderNumber和EquipmentWorkOrderNumber之间存在相关性,但是现在,可能有额外的EquipmentWorkOrderNumber不存在于员工WorkOrderNumber部分中。
我需要得到不同的WorkOrderNumber和EquipmentWorkOrderNumber不重复的值。我已经尝试了很多很多下面代码的变化,没有真正的进展。
<!-- The Key at the top -->
<xsl:key name="distinctWoEquipWo" match="//WorkOrderNumber | //EquipmentWorkOrderNumber" use="."/>
<!-- Where I loop through the distinct values -->
<xsl:for-each select=".//WorkOrderNumber | .//EquipmentWorkOrderNumber[generate-id() = generate-id(key('distinctWoEquipWo', .)[1])]">
是否有可能在选择中获得不同的WorkOrderNumber和EquipmentWorkOrderNumber值?
这是我正在使用的XML ?
<?xml-stylesheet type="text/xsl" href="TemplateTest.xsl"?>
<Timesheet>
<WeekEnding>Apr 28, 2013</WeekEnding>
<TeamMember>
<EmployeeNumber>AB00910</EmployeeNumber>
<EmployeeName>Demo, Derek</EmployeeName>
<EmployeeClass>F</EmployeeClass>
<Monday>
<TimeDetail>
<StartTime>Start</StartTime>
<StopTime>Stop</StopTime>
<WorkOrderNumber>4812537</WorkOrderNumber>
<RegularHoursStartTime>Start</RegularHoursStartTime>
<RegularHoursStopTime>Stop</RegularHoursStopTime>
<RegularHoursStartTime2>Start</RegularHoursStartTime2>
<RegularHoursStopTime2>Stop</RegularHoursStopTime2>
<RegularHours>9</RegularHours>
<OverTimeStartTime>Start</OverTimeStartTime>
<OverTimeStopTime>Stop</OverTimeStopTime>
<OverTimeStartTime2>Start</OverTimeStartTime2>
<OverTimeStopTime2>Stop</OverTimeStopTime2>
<OverTimeHours>Over Time</OverTimeHours>
<OtherStartTime>Start</OtherStartTime>
<OtherStopTime>Stop</OtherStopTime>
<OtherStartTime2>Start</OtherStartTime2>
<OtherStopTime2>Stop</OtherStopTime2>
<OtherHours>Other</OtherHours>
<PerDiem>NO</PerDiem>
<Notes>Notes</Notes>
</TimeDetail>
</Monday>
<Tuesday>
<TimeDetail>
<StartTime>Start</StartTime>
<StopTime>Stop</StopTime>
<WorkOrderNumber>4812537</WorkOrderNumber>
<RegularHoursStartTime>Start</RegularHoursStartTime>
<RegularHoursStopTime>Stop</RegularHoursStopTime>
<RegularHoursStartTime2>Start</RegularHoursStartTime2>
<RegularHoursStopTime2>Stop</RegularHoursStopTime2>
<RegularHours>12</RegularHours>
<OverTimeStartTime>Start</OverTimeStartTime>
<OverTimeStopTime>Stop</OverTimeStopTime>
<OverTimeStartTime2>Start</OverTimeStartTime2>
<OverTimeStopTime2>Stop</OverTimeStopTime2>
<OverTimeHours>Over Time</OverTimeHours>
<OtherStartTime>Start</OtherStartTime>
<OtherStopTime>Stop</OtherStopTime>
<OtherStartTime2>Start</OtherStartTime2>
<OtherStopTime2>Stop</OtherStopTime2>
<OtherHours>Other</OtherHours>
<PerDiem>NO</PerDiem>
<Notes>Notes</Notes>
</TimeDetail>
</Tuesday>
<Wednesday>
<TimeDetail>
<StartTime>Start</StartTime>
<StopTime>Stop</StopTime>
<WorkOrderNumber>4812537</WorkOrderNumber>
<RegularHoursStartTime>Start</RegularHoursStartTime>
<RegularHoursStopTime>Stop</RegularHoursStopTime>
<RegularHoursStartTime2>Start</RegularHoursStartTime2>
<RegularHoursStopTime2>Stop</RegularHoursStopTime2>
<RegularHours>11</RegularHours>
<OverTimeStartTime>Start</OverTimeStartTime>
<OverTimeStopTime>Stop</OverTimeStopTime>
<OverTimeStartTime2>Start</OverTimeStartTime2>
<OverTimeStopTime2>Stop</OverTimeStopTime2>
<OverTimeHours>Over Time</OverTimeHours>
<OtherStartTime>Start</OtherStartTime>
<OtherStopTime>Stop</OtherStopTime>
<OtherStartTime2>Start</OtherStartTime2>
<OtherStopTime2>Stop</OtherStopTime2>
<OtherHours>Other</OtherHours>
<PerDiem>NO</PerDiem>
<Notes>Notes</Notes>
</TimeDetail>
</Wednesday>
<Thursday>
<TimeDetail>
<StartTime>Start</StartTime>
<StopTime>Stop</StopTime>
<WorkOrderNumber>4812537</WorkOrderNumber>
<RegularHoursStartTime>Start</RegularHoursStartTime>
<RegularHoursStopTime>Stop</RegularHoursStopTime>
<RegularHoursStartTime2>Start</RegularHoursStartTime2>
<RegularHoursStopTime2>Stop</RegularHoursStopTime2>
<RegularHours>8</RegularHours>
<OverTimeStartTime>Start</OverTimeStartTime>
<OverTimeStopTime>Stop</OverTimeStopTime>
<OverTimeStartTime2>Start</OverTimeStartTime2>
<OverTimeStopTime2>Stop</OverTimeStopTime2>
<OverTimeHours>3</OverTimeHours>
<OtherStartTime>Start</OtherStartTime>
<OtherStopTime>Stop</OtherStopTime>
<OtherStartTime2>Start</OtherStartTime2>
<OtherStopTime2>Stop</OtherStopTime2>
<OtherHours>Other</OtherHours>
<PerDiem>NO</PerDiem>
<Notes>Notes</Notes>
</TimeDetail>
</Thursday>
<Friday>
<TimeDetail>
<StartTime>Start</StartTime>
<StopTime>Stop</StopTime>
<WorkOrderNumber>4812537</WorkOrderNumber>
<RegularHoursStartTime>Start</RegularHoursStartTime>
<RegularHoursStopTime>Stop</RegularHoursStopTime>
<RegularHoursStartTime2>Start</RegularHoursStartTime2>
<RegularHoursStopTime2>Stop</RegularHoursStopTime2>
<RegularHours>0</RegularHours>
<OverTimeStartTime>Start</OverTimeStartTime>
<OverTimeStopTime>Stop</OverTimeStopTime>
<OverTimeStartTime2>Start</OverTimeStartTime2>
<OverTimeStopTime2>Stop</OverTimeStopTime2>
<OverTimeHours>7</OverTimeHours>
<OtherStartTime>Start</OtherStartTime>
<OtherStopTime>Stop</OtherStopTime>
<OtherStartTime2>Start</OtherStartTime2>
<OtherStopTime2>Stop</OtherStopTime2>
<OtherHours>Other</OtherHours>
<PerDiem>NO</PerDiem>
<Notes>Notes</Notes>
</TimeDetail>
</Friday>
<Saturday />
<Sunday />
<CrewLeader>1</CrewLeader>
</TeamMember>
<TeamMember>
<EmployeeNumber>BB7789A</EmployeeNumber>
<EmployeeName>Employee, Daniel</EmployeeName>
<EmployeeClass>AL</EmployeeClass>
<Monday />
<Tuesday>
<TimeDetail>
<StartTime>Start</StartTime>
<StopTime>Stop</StopTime>
<WorkOrderNumber>4812537</WorkOrderNumber>
<RegularHoursStartTime>Start</RegularHoursStartTime>
<RegularHoursStopTime>Stop</RegularHoursStopTime>
<RegularHoursStartTime2>Start</RegularHoursStartTime2>
<RegularHoursStopTime2>Stop</RegularHoursStopTime2>
<RegularHours>12</RegularHours>
<OverTimeStartTime>Start</OverTimeStartTime>
<OverTimeStopTime>Stop</OverTimeStopTime>
<OverTimeStartTime2>Start</OverTimeStartTime2>
<OverTimeStopTime2>Stop</OverTimeStopTime2>
<OverTimeHours>Over Time</OverTimeHours>
<OtherStartTime>Start</OtherStartTime>
<OtherStopTime>Stop</OtherStopTime>
<OtherStartTime2>Start</OtherStartTime2>
<OtherStopTime2>Stop</OtherStopTime2>
<OtherHours>Other</OtherHours>
<PerDiem>YES</PerDiem>
<Notes>5xfullperdiem</Notes>
</TimeDetail>
</Tuesday>
<Wednesday>
<TimeDetail>
<StartTime>Start</StartTime>
<StopTime>Stop</StopTime>
<WorkOrderNumber>4812537</WorkOrderNumber>
<RegularHoursStartTime>Start</RegularHoursStartTime>
<RegularHoursStopTime>Stop</RegularHoursStopTime>
<RegularHoursStartTime2>Start</RegularHoursStartTime2>
<RegularHoursStopTime2>Stop</RegularHoursStopTime2>
<RegularHours>11</RegularHours>
<OverTimeStartTime>Start</OverTimeStartTime>
<OverTimeStopTime>Stop</OverTimeStopTime>
<OverTimeStartTime2>Start</OverTimeStartTime2>
<OverTimeStopTime2>Stop</OverTimeStopTime2>
<OverTimeHours>Over Time</OverTimeHours>
<OtherStartTime>Start</OtherStartTime>
<OtherStopTime>Stop</OtherStopTime>
<OtherStartTime2>Start</OtherStartTime2>
<OtherStopTime2>Stop</OtherStopTime2>
<OtherHours>Other</OtherHours>
<PerDiem>YES</PerDiem>
<Notes>5xfullperdiem</Notes>
</TimeDetail>
</Wednesday>
<Thursday>
<TimeDetail>
<StartTime>Start</StartTime>
<StopTime>Stop</StopTime>
<WorkOrderNumber>4812537</WorkOrderNumber>
<RegularHoursStartTime>Start</RegularHoursStartTime>
<RegularHoursStopTime>Stop</RegularHoursStopTime>
<RegularHoursStartTime2>Start</RegularHoursStartTime2>
<RegularHoursStopTime2>Stop</RegularHoursStopTime2>
<RegularHours>8</RegularHours>
<OverTimeStartTime>Start</OverTimeStartTime>
<OverTimeStopTime>Stop</OverTimeStopTime>
<OverTimeStartTime2>Start</OverTimeStartTime2>
<OverTimeStopTime2>Stop</OverTimeStopTime2>
<OverTimeHours>3</OverTimeHours>
<OtherStartTime>Start</OtherStartTime>
<OtherStopTime>Stop</OtherStopTime>
<OtherStartTime2>Start</OtherStartTime2>
<OtherStopTime2>Stop</OtherStopTime2>
<OtherHours>Other</OtherHours>
<PerDiem>YES</PerDiem>
<Notes>5xfullperdiem</Notes>
</TimeDetail>
</Thursday>
<Friday>
<TimeDetail>
<StartTime>Start</StartTime>
<StopTime>Stop</StopTime>
<WorkOrderNumber>4812537</WorkOrderNumber>
<RegularHoursStartTime>Start</RegularHoursStartTime>
<RegularHoursStopTime>Stop</RegularHoursStopTime>
<RegularHoursStartTime2>Start</RegularHoursStartTime2>
<RegularHoursStopTime2>Stop</RegularHoursStopTime2>
<RegularHours>Regular</RegularHours>
<OverTimeStartTime>Start</OverTimeStartTime>
<OverTimeStopTime>Stop</OverTimeStopTime>
<OverTimeStartTime2>Start</OverTimeStartTime2>
<OverTimeStopTime2>Stop</OverTimeStopTime2>
<OverTimeHours>7</OverTimeHours>
<OtherStartTime>Start</OtherStartTime>
<OtherStopTime>Stop</OtherStopTime>
<OtherStartTime2>Start</OtherStartTime2>
<OtherStopTime2>Stop</OtherStopTime2>
<OtherHours>Other</OtherHours>
<PerDiem>YES</PerDiem>
<Notes>5xfullperdiem</Notes>
</TimeDetail>
</Friday>
<Saturday />
<Sunday />
</TeamMember>
<TeamMember>
<EmployeeNumber>CDE890</EmployeeNumber>
<EmployeeName>Test, John</EmployeeName>
<EmployeeClass>G</EmployeeClass>
<Monday>
<TimeDetail>
<StartTime>Start</StartTime>
<StopTime>Stop</StopTime>
<WorkOrderNumber>4812537</WorkOrderNumber>
<RegularHoursStartTime>Start</RegularHoursStartTime>
<RegularHoursStopTime>Stop</RegularHoursStopTime>
<RegularHoursStartTime2>Start</RegularHoursStartTime2>
<RegularHoursStopTime2>Stop</RegularHoursStopTime2>
<RegularHours>9</RegularHours>
<OverTimeStartTime>Start</OverTimeStartTime>
<OverTimeStopTime>Stop</OverTimeStopTime>
<OverTimeStartTime2>Start</OverTimeStartTime2>
<OverTimeStopTime2>Stop</OverTimeStopTime2>
<OverTimeHours>Over Time</OverTimeHours>
<OtherStartTime>Start</OtherStartTime>
<OtherStopTime>Stop</OtherStopTime>
<OtherStartTime2>Start</OtherStartTime2>
<OtherStopTime2>Stop</OtherStopTime2>
<OtherHours>Other</OtherHours>
<PerDiem>NO</PerDiem>
<Notes>Notes</Notes>
</TimeDetail>
</Monday>
<Tuesday>
<TimeDetail>
<StartTime>Start</StartTime>
<StopTime>Stop</StopTime>
<WorkOrderNumber>4812537</WorkOrderNumber>
<RegularHoursStartTime>Start</RegularHoursStartTime>
<RegularHoursStopTime>Stop</RegularHoursStopTime>
<RegularHoursStartTime2>Start</RegularHoursStartTime2>
<RegularHoursStopTime2>Stop</RegularHoursStopTime2>
<RegularHours>12</RegularHours>
<OverTimeStartTime>Start</OverTimeStartTime>
<OverTimeStopTime>Stop</OverTimeStopTime>
<OverTimeStartTime2>Start</OverTimeStartTime2>
<OverTimeStopTime2>Stop</OverTimeStopTime2>
<OverTimeHours>Over Time</OverTimeHours>
<OtherStartTime>Start</OtherStartTime>
<OtherStopTime>Stop</OtherStopTime>
<OtherStartTime2>Start</OtherStartTime2>
<OtherStopTime2>Stop</OtherStopTime2>
<OtherHours>Other</OtherHours>
<PerDiem>NO</PerDiem>
<Notes>Notes</Notes>
</TimeDetail>
</Tuesday>
<Wednesday>
<TimeDetail>
<StartTime>Start</StartTime>
<StopTime>Stop</StopTime>
<WorkOrderNumber>4812537</WorkOrderNumber>
<RegularHoursStartTime>Start</RegularHoursStartTime>
<RegularHoursStopTime>Stop</RegularHoursStopTime>
<RegularHoursStartTime2>Start</RegularHoursStartTime2>
<RegularHoursStopTime2>Stop</RegularHoursStopTime2>
<RegularHours>11</RegularHours>
<OverTimeStartTime>Start</OverTimeStartTime>
<OverTimeStopTime>Stop</OverTimeStopTime>
<OverTimeStartTime2>Start</OverTimeStartTime2>
<OverTimeStopTime2>Stop</OverTimeStopTime2>
<OverTimeHours>Over Time</OverTimeHours>
<OtherStartTime>Start</OtherStartTime>
<OtherStopTime>Stop</OtherStopTime>
<OtherStartTime2>Start</OtherStartTime2>
<OtherStopTime2>Stop</OtherStopTime2>
<OtherHours>Other</OtherHours>
<PerDiem>NO</PerDiem>
<Notes>Notes</Notes>
</TimeDetail>
</Wednesday>
<Thursday>
<TimeDetail>
<StartTime>Start</StartTime>
<StopTime>Stop</StopTime>
<WorkOrderNumber>4812537</WorkOrderNumber>
<RegularHoursStartTime>Start</RegularHoursStartTime>
<RegularHoursStopTime>Stop</RegularHoursStopTime>
<RegularHoursStartTime2>Start</RegularHoursStartTime2>
<RegularHoursStopTime2>Stop</RegularHoursStopTime2>
<RegularHours>8</RegularHours>
<OverTimeStartTime>Start</OverTimeStartTime>
<OverTimeStopTime>Stop</OverTimeStopTime>
<OverTimeStartTime2>Start</OverTimeStartTime2>
<OverTimeStopTime2>Stop</OverTimeStopTime2>
<OverTimeHours>3</OverTimeHours>
<OtherStartTime>Start</OtherStartTime>
<OtherStopTime>Stop</OtherStopTime>
<OtherStartTime2>Start</OtherStartTime2>
<OtherStopTime2>Stop</OtherStopTime2>
<OtherHours>Other</OtherHours>
<PerDiem>NO</PerDiem>
<Notes>Notes</Notes>
</TimeDetail>
</Thursday>
<Friday>
<TimeDetail>
<StartTime>Start</StartTime>
<StopTime>Stop</StopTime>
<WorkOrderNumber>4812537</WorkOrderNumber>
<RegularHoursStartTime>Start</RegularHoursStartTime>
<RegularHoursStopTime>Stop</RegularHoursStopTime>
<RegularHoursStartTime2>Start</RegularHoursStartTime2>
<RegularHoursStopTime2>Stop</RegularHoursStopTime2>
<RegularHours>0</RegularHours>
<OverTimeStartTime>Start</OverTimeStartTime>
<OverTimeStopTime>Stop</OverTimeStopTime>
<OverTimeStartTime2>Start</OverTimeStartTime2>
<OverTimeStopTime2>Stop</OverTimeStopTime2>
<OverTimeHours>7</OverTimeHours>
<OtherStartTime>Start</OtherStartTime>
<OtherStopTime>Stop</OtherStopTime>
<OtherStartTime2>Start</OtherStartTime2>
<OtherStopTime2>Stop</OtherStopTime2>
<OtherHours>Other</OtherHours>
<PerDiem>NO</PerDiem>
<Notes>Notes</Notes>
</TimeDetail>
</Friday>
<Saturday />
<Sunday />
</TeamMember>
<Equipment>
<EquipmentWorkOrder>
<EquipmentWorkOrderNumber>4812537</EquipmentWorkOrderNumber>
<EquipmentDetail>
<EquipmentMileage>Mileage</EquipmentMileage>
<EquipmentHourMeter>Hour Meter</EquipmentHourMeter>
<EquipmentType>Bucket truck</EquipmentType>
<EquipmentNumber>8s96</EquipmentNumber>
<MondayHours>0</MondayHours>
<TuesdayHours>12</TuesdayHours>
<WednesdayHours>11</WednesdayHours>
<ThursdayHours>11</ThursdayHours>
<FridayHours>7</FridayHours>
<SaturdayHours>Saturday</SaturdayHours>
<SundayHours>Sunday</SundayHours>
<EquipmentNotes>Notes</EquipmentNotes>
</EquipmentDetail>
<EquipmentDetail>
<EquipmentMileage>Mileage</EquipmentMileage>
<EquipmentHourMeter>Hour Meter</EquipmentHourMeter>
<EquipmentType>Line truck</EquipmentType>
<EquipmentNumber>20x949</EquipmentNumber>
<MondayHours>9</MondayHours>
<TuesdayHours>12</TuesdayHours>
<WednesdayHours>11</WednesdayHours>
<ThursdayHours>11</ThursdayHours>
<FridayHours>7</FridayHours>
<SaturdayHours>Saturday</SaturdayHours>
<SundayHours>Sunday</SundayHours>
<EquipmentNotes>Notes</EquipmentNotes>
</EquipmentDetail>
<EquipmentDetail>
<EquipmentMileage>Mileage</EquipmentMileage>
<EquipmentHourMeter>Hour Meter</EquipmentHourMeter>
<EquipmentType>Pickup truck</EquipmentType>
<EquipmentNumber>38g356</EquipmentNumber>
<MondayHours>9</MondayHours>
<TuesdayHours>12</TuesdayHours>
<WednesdayHours>11</WednesdayHours>
<ThursdayHours>11</ThursdayHours>
<FridayHours>7</FridayHours>
<SaturdayHours>Saturday</SaturdayHours>
<SundayHours>Sunday</SundayHours>
<EquipmentNotes>Notes</EquipmentNotes>
</EquipmentDetail>
<EquipmentDetail>
<EquipmentMileage>Mileage</EquipmentMileage>
<EquipmentHourMeter>Hour Meter</EquipmentHourMeter>
<EquipmentType>Air compressor</EquipmentType>
<EquipmentNumber>1d158</EquipmentNumber>
<MondayHours>9</MondayHours>
<TuesdayHours>12</TuesdayHours>
<WednesdayHours>11</WednesdayHours>
<ThursdayHours>11</ThursdayHours>
<FridayHours>7</FridayHours>
<SaturdayHours>Saturday</SaturdayHours>
<SundayHours>Sunday</SundayHours>
<EquipmentNotes>Notes</EquipmentNotes>
</EquipmentDetail>
</EquipmentWorkOrder>
</Equipment>
</Timesheet>
谢谢你的帮助。
问题是您需要在节点选择周围加上括号以包含在键中,例如(//WorkOrderNumber | //EquipmentWorkOrderNumber)[generate-id...
。否则,你只是在WorkOrderNumber
节点上循环,只在键中包含EquipmentWorkOrderNumber
,并在这些节点上循环。
更充分…
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output method="xml" version="1.0" encoding="UTF-8" indent="yes"/>
<xsl:key name="workOrderNumberDistinct" match="WorkOrderNumber | EquipmentWorkOrderNumber" use="text()"/>
<xsl:template match="/">
<DistinctWorkOrderNumbers>
<xsl:for-each select="(//WorkOrderNumber | //EquipmentWorkOrderNumber)[generate-id() = generate-id(key('workOrderNumberDistinct', text())[1])]">
<Number>
<xsl:value-of select="."/>
</Number>
</xsl:for-each>
</DistinctWorkOrderNumbers>
</xsl:template>
</xsl:stylesheet>
输出……
<?xml version="1.0" encoding="UTF-8"?>
<DistinctWorkOrderNumbers>
<Number>4812537</Number>
</DistinctWorkOrderNumbers>