count function in xslt

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • DAnne
    New Member
    • Jun 2006
    • 5

    count function in xslt

    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:

    Code:
    <!-- brings back a tally of the responses -->
         <fo:table-cell>
          <fo:block font="Arial" text-align="center" font-size="8pt" font-weight="normal" space-after="2px">
           <xsl:if test="not(sec_id &gt;=0 and sub_sec_id &gt;=0 and item_id=0)" >
             <xsl:if test="sec_id=$test">
              <xsl:variable name="grouping"><xsl:value-of select="audit_response/resp" /></xsl:variable>
               <xsl:if test="not(audit_response/resp='')" >           
                <xsl:choose><!--begins the outside choose -->
                 <xsl:when test="sec_id">
                  <fo:block font="Arial" text-align="center" font-size="8pt" font-weight="normal" space-after="2px">
                   <xsl:for-each select="audit_response/resp">
                   <xsl:value-of select="count(child::node())"/>
                   </xsl:for-each>
             </fo:block>
             </xsl:when>
             </xsl:choose>
             </xsl:if>
             </xsl:if>
             </xsl:if>
             </fo:block>
             </fo:table-cell>
    My XML snippet:

    Code:
    <?xml version="1.0" encoding="UTF-8" ?> 
    - <report>
    - <audit>
      <auditid>159</auditid> 
      <auditlevel_id>21</auditlevel_id> 
      <levelstring>AUDIT LIBRARY</levelstring> 
      <auditname>Cory</auditname> 
      <cust_id>2</cust_id> 
      <ld>1</ld> 
      <li>8</li> 
    - <questions>
    - <question>
      <id>13756</id> 
      <sec_id>0</sec_id> 
      <sub_sec_id>0</sub_sec_id> 
      <item_id>0</item_id> 
      <questiontype>Header</questiontype> 
      <resp_num>1</resp_num> 
      <itemdescription>Cory</itemdescription> 
      <possible_score>10.00</possible_score> 
      <score_criteria /> 
      <udf_info /> 
    - <audit_response>
      <id>11595</id> 
      <questionid>13756</questionid> 
      <resp /> 
      <narr /> 
      <score>.00</score> 
      <p_o>0</p_o> 
      <n_o>0</n_o> 
      <p_f>0</p_f> 
      <n_f>0</n_f> 
      <answered>0</answered> 
      <udf_info /> 
      <corr_acts /> 
      </audit_response>
      </question>
    - <question>
      <id>13757</id> 
      <sec_id>1</sec_id> 
      <sub_sec_id>0</sub_sec_id> 
      <item_id>0</item_id> 
      <questiontype>Header</questiontype> 
      <resp_num>1</resp_num> 
      <itemdescription>Section 1 - Enter section 1 description.</itemdescription> 
      <possible_score>10.00</possible_score> 
      <score_criteria /> 
      <udf_info /> 
    - <audit_response>
      <id>11596</id> 
      <questionid>13757</questionid> 
      <resp /> 
      <narr /> 
      <score>.00</score> 
      <p_o>0</p_o> 
      <n_o>0</n_o> 
      <p_f>0</p_f> 
      <n_f>0</n_f> 
      <answered>0</answered> 
      <udf_info /> 
      <corr_acts /> 
      </audit_response>
      </question>
    Thanks
    Last edited by Dormilich; Jan 21 '09, 11:00 AM. Reason: added [code] tags
Working...