0
我有以下xml文件。根据属性值从xsl:key返回的包中删除重复项
<Bank>
<Person personId="1" type="1071" deleted="0">
</Person>
<Person personId="2" type="1071" deleted="0">
</Person>
<Person personId="3" type="1071" deleted="0">
</Person>
<Account>
<Role personId="1" type="1025" />
</Account>
<Account>
<Role personId="1" type="1025" />
</Account>
<Account>
<Role personId="1" type="1018" />
</Account>
<Account>
<Role personId="3" type="1025" />
<Role personId="1" type="1018" />
</Account>
<Account>
<Role personId="2" type="1025" />
</Account>
</Bank>
和下面的XSL转换。
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output method="text" encoding="ISO-8859-1" />
<xsl:strip-space elements="*" />
<xsl:key name="roleKey"
match="Role[(@type = '1025' or @type = '1018' or @type = '1022' or @type = '1023') and not(@validTo)]"
use="@personId" />
<xsl:template match="Person">
<xsl:value-of select="@personId" />
<xsl:variable name="roles" select="key('roleKey', @personId)" />
<xsl:for-each select="$roles">
<xsl:text>;</xsl:text><xsl:value-of select="@type" />
</xsl:for-each>
<xsl:text>
</xsl:text>
</xsl:template>
</xsl:stylesheet>
实际的结果如下,我想删除重复的type
值。
1;1025;1025;1018;1018
2;1025
3;1025
预期的结果应该是这样如下...
1;1025;1018
2;1025
3;1025
我曾尝试涉及来自this website关键字following
同时还与Muenchian方法的伎俩提示。他们都不工作,因为他们似乎在浏览整个文档并为每个Person
元素匹配重复项,而我只想在personId
属性定义的Person
上下文中删除重复项。
如何从key
函数返回的包中删除那些重复项?或者,也许有一种方法,我可以在xsl:for-each
中使用,只打印我想要的内容?
我只能使用XSLT 1.0中的可用内容。我没有可能使用任何XSLT 2.0处理器。