[XSL-LIST Mailing List Archive Home] [By Thread] [By Date]

[xsl] Counting matching elements across two documents

Subject: [xsl] Counting matching elements across two documents
From: cknell@xxxxxxxxxx
Date: Mon, 17 Jan 2005 09:18:34 -0500

I process two documents with this stylesheet. The main document is a file called "matches.xml". The secondary document is a file called "roster.xml" (accessed via the document() function). The structures of the two input documents are:

    &lt;!-- More matches here --&gt;
  &lt;!-- More weeks here --&gt;

  <player established="yes" >
      <rating week-num="1">55.0</rating>
  &lt;!-- More players here --&gt;

The section of the stylesheet that's giving me problems is this:
<xsl:for-each select="$roster/players/player">
  <xsl:sort select="lname" data-type="text" order="ascending" />
  <tr><td><xsl:value-of select="concat(lname,', ', fname)" /></td><td><xsl:value-of select="count(//player[number = ./number])" /></td></tr>

The shorthand way of saying what I'm looking for is "I want to count all the W's for each player." 

A more detailed, but more long-winded explanation is, I am trying to count all the "/matches/week/match/player/lag" elements with a value of "W" for each "$roster/players/player" element where the value of the "number" child of the current "$roster/players/player" matches any "/matches/week/match/player/number" element, but so far I can't work out the proper XPath expression. I have been successful in returning the total number of players in the roster or the total number of matches played, unfortunately, neither is what I'm looking for.

Can someone point out the correct XPath expression, please?

Charles Knell
cknell@xxxxxxxxxx - email

Current Thread