More Help Counting

Discussion in 'XML' started by Graham, Sep 20, 2004.

  1. Graham

    Graham Guest

    Hi,
    I am in need of help trying to count the number of records that a Key
    group contains. I am a newbie and apologise if this seems a dumb
    request!

    I have the following XSLT and keep getting zero returned.

    <?xml version="1.0" encoding="ISO-8859-1"?>
    <xsl:stylesheet version="1.0"
    xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
    <!-- Define keys used to group elements -->
    <xsl:key name="keyContactGUID" match="result"
    use="objectid.contactid"/>


    <xsl:template match="/">
    <!-- autonumber for the sorting id column -->
    <html>
    <body>
    <h2>Grouping Test</h2>

    <table border="1">
    <tr bgcolor="#9acd32">
    <th>Contact</th>
    <th># of Visits</th>
    <th>Account</th>
    </tr>
    <xsl:variable name="CC"
    select="count(key('keyContactGUID',objectid.contactid))"/>
    <!-- Process each Contact-->
    <xsl:for-each select="//result[generate-id(.) =
    generate-id(key('keyContactGUID',objectid.contactid)[1])]">

    <tr>
    <xsl:variable name="CID">
    <xsl:value-of select="objectid.contactid"/>
    </xsl:variable>
    <td>
    <xsl:value-of select="objectid.fullname"/>
    <p/>
    </td>
    <td>
    <xsl:value-of
    select="count(key('keyContactGUID',objectid.contactid)/activityid)"/>
    </td>
    <td>
    <xsl:value-of select="objectid.accountid/@name"/>
    </td>
    </tr>

    </xsl:for-each>


    </table>
    <xsl:variable name="CC"
    select="count(key('keyContactGUID',objectid.contactid))"/>
    Count = <xsl:value-of select="$CC"/>
    </body>
    </html>
    </xsl:template>
    </xsl:stylesheet>

    Thanks in advance
    Graham.
    Graham, Sep 20, 2004
    #1
    1. Advertising

  2. Graham wrote:

    > I am in need of help trying to count the number of records that a Key
    > group contains. I am a newbie and apologise if this seems a dumb
    > request!
    >
    > I have the following XSLT and keep getting zero returned.


    Well, you forgot to provide a sample input XML.

    --
    Oleg Tkachenko [XML MVP]
    http://blog.tkachenko.com
    Oleg Tkachenko [MVP], Sep 20, 2004
    #2
    1. Advertising

  3. Graham wrote:


    > <xsl:template match="/">
    > <!-- autonumber for the sorting id column -->
    > <html>
    > <body>


    As you can see here context node is root. There is no objectid.contactid
    element in this context.

    > <xsl:variable name="CC"
    > select="count(key('keyContactGUID',objectid.contactid))"/>
    > Count = <xsl:value-of select="$CC"/>


    I'm not sure which count you need, but try somethng like
    <xsl:variable name="CC"
    select="count(key('keyContactGUID',//result/objectid.contactid))"/>

    --
    Oleg Tkachenko [XML MVP]
    http://blog.tkachenko.com
    Oleg Tkachenko [MVP], Sep 20, 2004
    #3
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Davidd Sargent

    Help with counting lines?

    Davidd Sargent, Aug 13, 2004, in forum: Perl
    Replies:
    3
    Views:
    440
    Gunnar Hjalmarsson
    Aug 13, 2004
  2. Michael
    Replies:
    4
    Views:
    399
    Matt Hammond
    Jun 26, 2006
  3. Robert Klemme

    With a Ruby Yell: more, more more!

    Robert Klemme, Sep 28, 2005, in forum: Ruby
    Replies:
    5
    Views:
    205
    Jeff Wood
    Sep 29, 2005
  4. edwardfredriks

    counting up instead of counting down

    edwardfredriks, Sep 6, 2005, in forum: Javascript
    Replies:
    6
    Views:
    188
    Dr John Stockton
    Sep 7, 2005
  5. Christopher Pisz
    Replies:
    2
    Views:
    103
    James Kanze
    Apr 1, 2014
Loading...

Share This Page