xsl-list
[Top] [All Lists]

[xsl] Counting records

2008-12-08 11:08:22
Hi,

I have a requirement to count the number of rows in an XML result set
returned from a database.  The result set can be empty, in which case
the returned XML will look like this:

<?xml version="1.0" encoding="utf-16"?>
<HesaValidate_Response xmlns="http://HesaValidateSqlSend";>
</HesaValidate_Response>

If any rows are returned they will look like the following:

<?xml version="1.0" encoding="utf-16"?>
<HesaValidate_Response xmlns="http://HesaValidateSqlSend";>
    <row     instance_no="1  "
    hesa_prog_id="6612"
    personal_id="07004871"
    surname="Aaaaa                         "
    forenames="Aaaa                                "
    prog_id="6612"
    mode_id="5"
    year_id="1"
    occurrence="01"
    full_title="Postgraduate Certificate Professional Practice:
Additional Learning Needs in Education              "
error_message="Blank HESA No/Instance No/HESA Programme" />
    <row
        instance_no="1  " hesa_prog_id="6612" personal_id="07004872"
surname="Bbbbbb"
        forenames="Bbbbbb                     " prog_id="6612"
mode_id="5" year_id="1"
        occurrence="01"
        full_title="Postgraduate Certificate Professional Practice:
Additional Learning Needs in Education              "
        error_message="Blank HESA No/Instance No/HESA Programme"
    />
    <row     hesa_no="0710890036741"
    instance_no="1  "
    personal_id="07003686"
    surname="Ccccc                         "
    forenames="Ccccc                "
    prog_id="9041"
    mode_id="1"
    year_id="1"
    occurrence="01"
    full_title="BSc (Hons) Sport Management
" error_message="Blank HESA No/Instance No/HESA Programme" />
</HesaValidate_Response>

I've tried to do this:

<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform";
version="1.0">
    <xsl:template match="/">
        <xsl:variable name="RowCount" select="count(//row)"/>
        The number of rows is: <xsl:value-of select="$RowCount"/>
    </xsl:template>
</xsl:stylesheet>

I probably don't need the variable, but I'm just using what I know.

The problem is that this always returns zero: as does
count(/HesaValidate_Response/row), and count(row); which I suppose is to
be expected if //row does.

Anyway, I'm obviously missing something incredibly obvious.  If someone
could point out to me what it is, I'd be grateful.

Thanks


Peter


--~------------------------------------------------------------------
XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list
To unsubscribe, go to: http://lists.mulberrytech.com/xsl-list/
or e-mail: <mailto:xsl-list-unsubscribe(_at_)lists(_dot_)mulberrytech(_dot_)com>
--~--