I have an XML file like
我有一个XML文件
<ns0:Employees xmlns:ns0="http://TestIndexMap.Employees">
<Employee FirstName="FirstName_0" LastName="LastName_1" dept="dept_2" empNumber="1">
<Schedules>
<Schedule Date_join="2008-01-20" Date_end="2008-01-30" />
</Schedules>
</Employee>
<Employee FirstName="FirstName_0" LastName="LastName_1" dept="dept_2" empNumber="2">
<Schedules>
<Schedule Date_join="2008-01-20" Date_end="2008-01-30" />
</Schedules>
</Employee>
<Employee FirstName="FirstName_2" LastName="LastName_1" dept="dept_2" empNumber="2">
<Schedules>
<Schedule Date_join="2007-01-21" Date_end="2007-12-30" />
</Schedules>
</Employee>
<Employee FirstName="FirstName_2" LastName="LastName_1" dept="dept_2" empNumber="2">
<Schedules>
<Schedule Date_join="2007-01-21" Date_end="2007-12-30" />
<Schedule Date_join="2008-06-20" Date_end="2008-01-30" />
</Schedules>
</Employee>
</ns0:Employees>
I would want to remove the duplicates based on the fistname, last name and date_join and data_end .
我想根据fistname,姓氏和date_join以及data_end删除重复项。
Please, can someone explain how to achive this with XSLT?
请问,有人可以解释如何使用XSLT实现这一目标吗?
1 个解决方案
#1
5
Here are some samples of how to remove duplicates based on element name and id field. It should be not too hard to extend this to arbitrary fields.
以下是一些如何根据元素名称和id字段删除重复项的示例。将其扩展到任意字段应该不难。
Q: Expansion. A part of my xml looks like this:
问:扩张。我的xml的一部分看起来像这样:
<location>
<state>xxxx</state>
</location>
<location>
<state>yyyy</state>
</location>
<location>
<state>xxxx</state>
</location>
The desired output is:
所需的输出是:
xxxx
yyyy
That is, duplicate values of state should not be printed. Can this be done?
也就是说,不应打印重复的状态值。可以这样做吗?
<xsl:variable name="unique-list"
select="//state[not(.=following::state)]" />
<xsl:for-each select="$unique-list">
<xsl:value-of select="." />
</xsl:for-each>
#1
5
Here are some samples of how to remove duplicates based on element name and id field. It should be not too hard to extend this to arbitrary fields.
以下是一些如何根据元素名称和id字段删除重复项的示例。将其扩展到任意字段应该不难。
Q: Expansion. A part of my xml looks like this:
问:扩张。我的xml的一部分看起来像这样:
<location>
<state>xxxx</state>
</location>
<location>
<state>yyyy</state>
</location>
<location>
<state>xxxx</state>
</location>
The desired output is:
所需的输出是:
xxxx
yyyy
That is, duplicate values of state should not be printed. Can this be done?
也就是说,不应打印重复的状态值。可以这样做吗?
<xsl:variable name="unique-list"
select="//state[not(.=following::state)]" />
<xsl:for-each select="$unique-list">
<xsl:value-of select="." />
</xsl:for-each>