[XSL-LIST Mailing List Archive Home] [By Thread] [By Date] [Recent Entries] [Reply To This Message]

Counting matching elements across two documents

Subject: Counting matching elements across two documents
From: cknell@xxxxxxxxxx
Date: Mon, 17 Jan 2005 09:18:34 -0500
roster.xml
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:

matches.xml
===========
<matches>
  <week>
    <number>1</number>
    <match>
      <race-to>60</race-to>
      <player>
        <number>1</number>
        <spot>0</spot>
        <score>51</score>
        <lag>L</lag>
        <paid>2.50</paid>
      </player>
      <player>
        <number>2</number>
        <spot>16</spot>
        <score>60</score>
        <lag>W</lag>
        <paid>5</paid>
      </player>
    </match>
    &lt;!-- More matches here --&gt;
  <week>
  &lt;!-- More weeks here --&gt;
</matches>

roster.xml
===========
<players>
  <player established="yes" >
    <number>5</number>
    <lname>Knell</lname>
    <fname>Charles</fname>
    <handy-cap-history>
      <rating week-num="1">55.0</rating>
    </handy-cap-history>
  </player>
  &lt;!-- More players here --&gt;
</players>

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>
</xsl:for-each>

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

PURCHASE STYLUS STUDIO ONLINE TODAY!

Purchasing Stylus Studio from our online shop is Easy, Secure and Value Priced!

Buy Stylus Studio Now

Download The World's Best XML IDE!

Accelerate XML development with our award-winning XML IDE - Download a free trial today!

Don't miss another message! Subscribe to this list today.
Email
First Name
Last Name
Company
Subscribe in XML format
RSS 2.0
Atom 0.3
Site Map | Privacy Policy | Terms of Use | Trademarks
Free Stylus Studio XML Training:
W3C Member
Stylus Studio® and DataDirect XQuery ™are products from DataDirect Technologies, is a registered trademark of Progress Software Corporation, in the U.S. and other countries. © 2004-2013 All Rights Reserved.