Как новичок в xsl, я пробовал различные примеры из этих сообщений, но для моего конкретного XML-файла я не могу удалить дубликаты строк TaskName.Я успешно удалил несколько записей "ResourceName", но хочу, чтобы данная задача появлялась только один раз под ResourceName.
Я был бы очень признателен за любые предложения.Вот мой xml (извините за длинный файл, но я думаю, что нужен для ясности), мой xsl, вывод, который я получаю, и показывающий вывод, который я хотел бы получить.
Источник XML:
<?xml version="1.0" encoding="UTF-8"?>
<?xml-stylesheet type="text/xsl" href="ResourceAssignments.xsl"?>
<ResourceAllocationReport>
<DetailedData>
<ResourceAllocation>
<Group>Week Starting on 7/24/11</Group>
<TaskResourceAllocation>
<TaskName>DEV-23876 Task A</TaskName>
<TaskDuration>5 days</TaskDuration>
<ResourceName>John Smith</ResourceName>
<AllocatedHours>2.400</AllocatedHours>
</TaskResourceAllocation>
</ResourceAllocation>
<ResourceAllocation>
<Group>Week Starting on 7/31/11</Group>
<TaskResourceAllocation>
<TaskName>DEV-23873 Task B</TaskName>
<TaskDuration>2 days</TaskDuration>
<ResourceName>John Smith</ResourceName>
<AllocatedHours>4.000</AllocatedHours>
</TaskResourceAllocation>
</ResourceAllocation>
<ResourceAllocation>
<Group>Week Starting on 8/7/11</Group>
<TaskResourceAllocation>
<TaskName>DEV-23879 Task C</TaskName>
<TaskDuration>10 days</TaskDuration>
<ResourceName>John Smith</ResourceName>
<AllocatedHours>1.600</AllocatedHours>
</TaskResourceAllocation>
</ResourceAllocation>
<ResourceAllocation>
<TaskResourceAllocation>
<TaskName>DEV-22837 List edit</TaskName>
<TaskDuration>10 days</TaskDuration>
<ResourceName>Sam Adams</ResourceName>
<AllocatedHours>5.000</AllocatedHours>
</TaskResourceAllocation>
</ResourceAllocation>
<ResourceAllocation>
<Group>Week Starting on 9/4/11</Group>
<TaskResourceAllocation>
<TaskName>DEV-19006 System Configuration Report</TaskName>
<TaskDuration>12 days</TaskDuration>
<ResourceName>Kimberly Clark</ResourceName>
<AllocatedHours>7.000</AllocatedHours>
</TaskResourceAllocation>
</ResourceAllocation>
<ResourceAllocation>
<TaskResourceAllocation>
<TaskName>DEV-19006 System Configuration Report</TaskName>
<TaskDuration>12 days</TaskDuration>
<ResourceName>Sam Adams</ResourceName>
<AllocatedHours>7.000</AllocatedHours>
</TaskResourceAllocation>
</ResourceAllocation>
<ResourceAllocation>
<TaskResourceAllocation>
<TaskName>DEV-22837 List edit</TaskName>
<TaskDuration>10 days</TaskDuration>
<ResourceName>Sam Adams</ResourceName>
<AllocatedHours>8</AllocatedHours>
</TaskResourceAllocation>
</ResourceAllocation>
<ResourceAllocation>
<Group>Week Starting on 9/25/11</Group>
<TaskResourceAllocation>
<TaskName>DEV-15997 Change modifiers for components</TaskName>
<TaskDuration>15 days</TaskDuration>
<ResourceName>Kimberly Clark</ResourceName>
<AllocatedHours>8.000</AllocatedHours>
</TaskResourceAllocation>
</ResourceAllocation>
<ResourceAllocation>
<Group>Week Starting on 10/2/11</Group>
<TaskResourceAllocation>
<TaskName>DEV-15997 Change modifiers for components</TaskName>
<TaskDuration>15 days</TaskDuration>
<ResourceName>Kimberly Clark</ResourceName>
<AllocatedHours>2.000</AllocatedHours>
</TaskResourceAllocation>
</ResourceAllocation>
</DetailedData>
</ResourceAllocationReport>
Таблица стилей:
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output method="html" indent="yes" />
<xsl:key name="ResourceKey" match="TaskResourceAllocation" use="ResourceName" />
<xsl:template match="ResourceAllocation">
<body>
<xsl:apply-templates select="TaskResourceAllocation[generate-id(.) =
generate-id(key('ResourceKey',ResourceName)[1])]"/>
</body>
</xsl:template>
<xsl:template match="TaskResourceAllocation">
<h2><xsl:value-of select="ResourceName" /></h2>
<table border="1">
<xsl:for-each select="key('ResourceKey',ResourceName)">
<xsl:if test="not(. = preceding::TaskName)">
<tr>
<td>
<xsl:value-of select="TaskName" />
</td>
<td>
<xsl:value-of select="TaskDuration" />
</td>
</tr>
</xsl:if>
</xsl:for-each>
</table>
</xsl:template>
</xsl:stylesheet>
Вывод (но я НЕ хочу дублировать задачи):
John Smith
DEV-23876 Task A 5 days
DEV-23873 Task B 2 days
DEV-23879 Task C 10 days
Sam Adams
DEV-22837 List edit 10 days
DEV-19006 System Configuration Report 12 days
DEV-22837 List edit 10 days
Kimberly Clark
DEV-19006 System Configuration Report 12 days
DEV-15997 Change modifiers for components 15 days
DEV-15997 Change modifiers for components 15 days
Желаемый вывод:
John Smith
DEV-23876 Task A 5 days
DEV-23873 Task B 2 days
DEV-23879 Task C 10 days
Sam Adams
DEV-19006 System Configuration Report 12 days
DEV-22837 List edit 10 days
Kimberly Clark
DEV-19006 System Configuration Report 12 days
DEV-15997 Change modifiers for components 15 days