473,474 Members | 1,324 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

count function in xslt

5 New Member
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
Jun 18 '06 #1
0 4512

Sign in to post your reply or Sign up for a free account.

Similar topics

12
by: Mark Constant | last post by:
I have a drop-down list now and I got it so when something is selected from the drop down list it calls a JavaScript function. I want it so the value selected from the drop-down list is sent as a...
6
by: M.Kamermans | last post by:
I have an XSLT script that has to operate on some particularly nasty XML to turn it into a SQL databse, but 'entries' in the XML aren't actually unique, so their unique identifier is useless. I...
4
by: Larry R | last post by:
I am trying to use XPath (XSLT 1.0), EXSLT 1.1 (.Net) to select the nodelist consisting of the 'top n' nodes. THe counter is the count of item/value. Using a traditional for-each logic, the...
4
by: ralf321 | last post by:
Hello! i want to count elements in xslt. All with meta=13 contains a AND meta 14 contains b but it dont work any Idee why? Thanks. i try it with count(object/node/data)
4
by: gualtmacchi | last post by:
I'm processing an XML input file getting a plain text file where from M nodes I got N output lines... It's not relevant but the input file is a recordset coming from a database and the output is...
1
by: mad_a | last post by:
I have a question about XSLT. I am trying to count the number of sibblings a parent node has (of a specific name). Say I have <topNode> <page> text in here</page> <page> text in...
6
by: Mario Vázquez | last post by:
Hi, I'm tryin in vane to get the number of elements of some type from a XML document using the count() function. I'm not in a XSLT document. I'm just trying to get this from a .NET XmlDocument...
2
by: Volkan | last post by:
Hi, I'm trying to compare two XML documents and i'm using XPath queries to select nodes. XPathNavigator's Select method runs fast enough and returns an XPathNodeIterator object. When i try to...
16
by: njsimha | last post by:
Hi, I have the following XML snippet: <root> <template1> <elem1>1000</elem1> <elem2> <subelem1>65</subelem1>
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
1
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.