小编Nat*_*han的帖子

每个节点的XSL唯一值

好吧,我有这个xml

<roots>
<root>
    <name>first</name>
    <item type='test'><something>A</something></item>
    <item type='test'><something>B</something></item>
    <item type='test'><something>C</something></item>
    <item type='test'><something>A</something></item>
    <item type='other'><something>A</something></item>
    <item type='test'><something>B</something></item>
    <item type='other'><something>D</something></item>

</root>
<root>
<name>second</name>
    <item type='test'><something>E</something></item>
    <item type='test'><something>B</something></item>
    <item type='test'><something>F</something></item>
    <item type='test'><something>A</something></item>
    <item type='other'><something>A</something></item>
    <item type='test'><something>B</something></item>
    <item type='other'><something>D</something></item>

</root>

</roots>
Run Code Online (Sandbox Code Playgroud)

现在我需要获得每个根节点的唯一值到目前为止我有

<?xml version="1.0" encoding="ISO-8859-1"?>
<xsl:stylesheet version="1.0"
  xmlns:xsl="http://www.w3.org/1999/XSL/Transform">

  <xsl:output indent="yes" method="text"/>
  <xsl:key name="item-by-value" match="something" use="."/>
  <xsl:key name="rootkey" match="root" use="name"/>

  <xsl:template match="/">
    <xsl:for-each select="key('rootkey','second')">
      <xsl:for-each select="item/something">
        <xsl:if test="generate-id() = generate-id(key('item-by-value', normalize-space(.)))">
          <xsl:value-of select="."/>
        </xsl:if>
      </xsl:for-each> 
    </xsl:for-each>
  </xsl:template>

</xsl:stylesheet>
Run Code Online (Sandbox Code Playgroud)

如果我使用"First"作为获得第一根的关键我得到一个好的结果ABCD

如果我使用"秒"我怎么只得到EF但我需要结果是ABDFE

xslt unique

5
推荐指数
1
解决办法
1560
查看次数

标签 统计

unique ×1

xslt ×1