0

我有一个记录集,我正在对特定字段进行过滤(即 Manager ="Frannklin")。现在我想根据另一个字段(客户端)对过滤后的记录集的结果进行分组。我似乎无法让 Muenchian 分组正常工作。

有什么想法吗?

蒂亚!

CG

我的过滤器如下所示:

<xsl:key name="k1" match="Row" use="@Manager"/>
<xsl:param name="dvt_filterval">Frannklin</xsl:param>
<xsl:variable name="Rows" select="/dsQueryResponse/Rows/Row" />
<xsl:variable name="FilteredRowsAttr" select="$Rows[normalize-space(@*[name()=$FieldNameNoAtSign])=$dvt_filterval ]" />

模板
<xsl:apply-templates select="$FilteredRowsAttr[generate-id() = generate-id(key('k1',@Manager))]" mode="g1000a">
</xsl:apply-templates>

<xsl:template match="Row" mode="g1000a">
客户:<xsl:value-of select="@Client"/>
</xsl:template>

结果我得到
客户端:Beta
客户端:Beta
客户端:Beta
客户端:Gamma
客户端:Delta

我想要的结果
客户:Beta
客户:Gamma
客户:Delta

样本记录集
<dsQueryResponse>
<Rows>
<Row Manager="Smith" Client="Alpha " Project_x0020_Name="Annapolis" PM_x0023_="00123" />
<Row Manager="Ford" Client="Alpha " Project_x0020_Name="Brown" PM_x0023_="00124" />
<Row Manager="Cronkite" Client="Beta " Project_x0020_Name="Gannon" PM_x0023_="00129" />
<Row Manager="Clinton, Bill" Client="Beta " Project_x0020_Name="Harvard" PM_x0023_="00130" />
<Row Manager="Frannklin" Client="Beta " Project_x0020_Name="Irving" PM_x0023_="00131" />
<Row Manager="Frannklin" Client="Beta " Project_x0020_Name="Jakarta" PM_x0023_="00132" />
<Row Manager="Frannklin" Client="Beta " Project_x0020_Name="Vassar" PM_x0023_="00135" />
<Row Manager="Jefferson" Client="Gamma " Project_x0020_Name="Stamford" PM_x0023_="00141" />
<Row Manager="Cronkite" Client="Gamma " Project_x0020_Name="Tufts" PM_x0023_="00142" />
<Row Manager="Frannklin" Client="Gamma " Project_x0020_Name="UCLA" PM_x0023_="00143" />
<Row Manager="Jefferson" Client="Gamma " Project_x0020_Name="Villanova" PM_x0023_="00144" />
<Row Manager="Carter" Client="Delta " Project_x0020_Name="Drexel" PM_x0023_="00150" />
<Row Manager="Clinton" Client="Delta " Project_x0020_Name="Iona" PM_x0023_="00151" />
<Row Manager="Frannklin" Client="Delta " Project_x0020_Name="Temple" PM_x0023_="00152" />
<Row Manager="Ford" Client="Epsilon " Project_x0020_Name="UNC" PM_x0023_="00157" />
<Row Manager="Clinton" Client="Epsilon " Project_x0020_Name="Berkley" PM_x0023_="00158" />
</Rows>
</dsQueryResponse>

4

1 回答 1

1

为此,您需要一个复合键。

这种转变

<xsl:stylesheet version="1.0"
 xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
 <xsl:output method="text"/>

 <xsl:key name="kClientByMgr" match="@Client"
      use="concat(../@Manager, '+', .)"/>

 <xsl:template match="/">
    <xsl:for-each select=
     "*/*/*/@Client[generate-id()
          =
           generate-id(key('kClientByMgr',
                           concat('Frannklin', '+', .)
                           )[1]
                       )
           ]
     ">
      Client: <xsl:value-of select="."/>
    </xsl:for-each>
 </xsl:template>
</xsl:stylesheet>

当应用于提供的 XML 文档时,会产生所需的正确结果

  Client: Beta 
  Client: Gamma 
  Client: Delta 
于 2010-05-04T22:52:05.943 回答