开发者

XSLT: Display unique rows of filtered XML recordset

开发者 https://www.devze.com 2022-12-29 07:56 出处:网络
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 s

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 getti开发者_StackOverflow社区ng

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>


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 
0

精彩评论

暂无评论...
验证码 换一张
取 消