XSLT:显示已过滤 XML 记录集的唯一行

发布于 2024-08-31 11:11:00 字数 2884 浏览 4 评论 0原文

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

有什么想法吗?

蒂亚!

CG

我的过滤器如下所示:


Frannklin

模板
< br> <

xsl:template match="Row" mode="g1000a">
客户端:

我得到的结果
客户端:测试版
客户端:测试版
客户端:测试版
客户:伽玛
客户:

我想要达美结果
客户端:测试版
客户:伽玛
客户端:Delta

示例记录集

<行>

















I've got a recordset that I'm filtering on a particular field (i.e. Manager ="Frannklin"). Now I'd like to group the results of that filtered recordset based on another field (Client). I can't seem to get Muenchian grouping to work right.

Any thoughts?

TIA!

CG

My filter looks like this:

<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 ]" />

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

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

Results I'm getting
Client: Beta
Client: Beta
Client: Beta
Client: Gamma
Client: Delta

Results I want
Client: Beta
Client: Gamma
Client: Delta

Sample recordset
<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>

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

久随 2024-09-07 11:11:00

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

此转换

<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 

You need a compound key for this.

This transformation:

<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>

when applied on the provided XML document, produces the wanted, correct result:

  Client: Beta 
  Client: Gamma 
  Client: Delta 
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文