2013-05-07 50 views
0

我對某個XSLT進行了業務規則更改,但我不確定如何處理它。如果你看下面的XML,你會看到我有一個員工部分和一個設備部分。員工部分有一個嵌套在日期標籤和TimeDetail標籤中的WorkOrderNumber,並且在Equipment - > EquipmentWorkOrder中嵌套有一個EquipmentWorkOrderNumber。使用XSLT從XML的兩個不同部分獲取不同的值

我用來僅僅需要獲得不同的WorkOrderNumber,因爲WorkOrderNumber和EquipmentWorkOrderNumber之間會有相關性,但現在可能會有額外的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])]"> 

是否有可能在select中獲得不同的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> 

感謝您的所有幫助。

+0

你能告訴我們你希望收到XML輸出? – ABach 2013-05-07 14:22:21

+0

輸出是html,但有很多,但在上面的循環中,我試圖用工作訂單號打印標題。   ​​的 – inosu812 2013-05-07 14:36:11

+0

@ inosu812似乎適用於我(使用xsltoroc) – 2013-05-07 14:50:14

回答

0

問題是你需要在包含在你的密鑰中的節點選擇周圍使用小括號,如(//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> 
+0

如果您複製星期一至星期六的數據,您將看到它帶來了兩次工單號。我會看看我是否可以獲得其他XML數據來證明這一點。 – inosu812 2013-05-07 14:55:33

+0

好的,我自己修改了輸入XML並查看你的意思。我上面的轉換仍然有效。您需要圍繞此'(// WorkOrderNumber | // EquipmentWorkOrderNumber)'的括號。 – davmos 2013-05-07 15:00:44

+0

好的。我還更改了上面的XML數據,以便每個人都可以更全面地瞭解我所談論的內容。 – inosu812 2013-05-07 15:03:52