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處理器。