Connecting Tech Pros Worldwide Help | Site Map

count function in xslt

Newbie
 
Join Date: Jun 2006
Posts: 5
#1: Jun 18 '06
I'm trying to do a simple count function in xslt and it's turning out to be extremely painful.

I have a report that brings back a set of responses for each question per section in an Audit.

I want to bring back the response only once (i.e. Na,Yes, No answers only once). I have this working. The part I'm having trouble with is the count. Now for each response I need to do a tally of how many times the respondent answered Yes or No.

My xslt keeps returning a count of 1 even though I should get a count of 3 for No and 4 for Yes and 1 for N/a.

I've lost hours trying to get this to work. I've tried everything (preceding, preceding-sibling etc). Any help would be greatly appreciate.

My xslt snippet:

Expand|Select|Wrap|Line Numbers
  1. <!-- brings back a tally of the responses -->
  2.      <fo:table-cell>
  3.       <fo:block font="Arial" text-align="center" font-size="8pt" font-weight="normal" space-after="2px">
  4.        <xsl:if test="not(sec_id &gt;=0 and sub_sec_id &gt;=0 and item_id=0)" >
  5.          <xsl:if test="sec_id=$test">
  6.           <xsl:variable name="grouping"><xsl:value-of select="audit_response/resp" /></xsl:variable>
  7.            <xsl:if test="not(audit_response/resp='')" >           
  8.             <xsl:choose><!--begins the outside choose -->
  9.              <xsl:when test="sec_id">
  10.               <fo:block font="Arial" text-align="center" font-size="8pt" font-weight="normal" space-after="2px">
  11.                <xsl:for-each select="audit_response/resp">
  12.                <xsl:value-of select="count(child::node())"/>
  13.                </xsl:for-each>
  14.          </fo:block>
  15.          </xsl:when>
  16.          </xsl:choose>
  17.          </xsl:if>
  18.          </xsl:if>
  19.          </xsl:if>
  20.          </fo:block>
  21.          </fo:table-cell>
My XML snippet:

Expand|Select|Wrap|Line Numbers
  1. <?xml version="1.0" encoding="UTF-8" ?> 
  2. - <report>
  3. - <audit>
  4.   <auditid>159</auditid> 
  5.   <auditlevel_id>21</auditlevel_id> 
  6.   <levelstring>AUDIT LIBRARY</levelstring> 
  7.   <auditname>Cory</auditname> 
  8.   <cust_id>2</cust_id> 
  9.   <ld>1</ld> 
  10.   <li>8</li> 
  11. - <questions>
  12. - <question>
  13.   <id>13756</id> 
  14.   <sec_id>0</sec_id> 
  15.   <sub_sec_id>0</sub_sec_id> 
  16.   <item_id>0</item_id> 
  17.   <questiontype>Header</questiontype> 
  18.   <resp_num>1</resp_num> 
  19.   <itemdescription>Cory</itemdescription> 
  20.   <possible_score>10.00</possible_score> 
  21.   <score_criteria /> 
  22.   <udf_info /> 
  23. - <audit_response>
  24.   <id>11595</id> 
  25.   <questionid>13756</questionid> 
  26.   <resp /> 
  27.   <narr /> 
  28.   <score>.00</score> 
  29.   <p_o>0</p_o> 
  30.   <n_o>0</n_o> 
  31.   <p_f>0</p_f> 
  32.   <n_f>0</n_f> 
  33.   <answered>0</answered> 
  34.   <udf_info /> 
  35.   <corr_acts /> 
  36.   </audit_response>
  37.   </question>
  38. - <question>
  39.   <id>13757</id> 
  40.   <sec_id>1</sec_id> 
  41.   <sub_sec_id>0</sub_sec_id> 
  42.   <item_id>0</item_id> 
  43.   <questiontype>Header</questiontype> 
  44.   <resp_num>1</resp_num> 
  45.   <itemdescription>Section 1 - Enter section 1 description.</itemdescription> 
  46.   <possible_score>10.00</possible_score> 
  47.   <score_criteria /> 
  48.   <udf_info /> 
  49. - <audit_response>
  50.   <id>11596</id> 
  51.   <questionid>13757</questionid> 
  52.   <resp /> 
  53.   <narr /> 
  54.   <score>.00</score> 
  55.   <p_o>0</p_o> 
  56.   <n_o>0</n_o> 
  57.   <p_f>0</p_f> 
  58.   <n_f>0</n_f> 
  59.   <answered>0</answered> 
  60.   <udf_info /> 
  61.   <corr_acts /> 
  62.   </audit_response>
  63.   </question>
Thanks
Reply