473,385 Members | 1,353 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

xslt problems

5
Hi,

I'm very new to xslt and this is my first time posting to a Forum so please forgive me if I transgress any protocols.

I have to do a tally report. This report is divided up into sections. Each section has a list of questions. Each question has responses.

I need to display a list of responses to the questions (i.e. set:distinct), once and only once, each section.

My second problem is that these questions can also have corrective actions associated with them (CAR's in the report). The first section has 5 CAR's but when I do a sum I get the result 2-1-2 instead of 5.


This is a cut down version of the xml I'm working with (I have to use XSLT 1.0 transforming using FOP):


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>13759</id> 
  14.         <sec_id>1</sec_id> 
  15.         <sub_sec_id>1</sub_sec_id> 
  16.         <item_id>1</item_id> 
  17.         <questiontype>SelectResponse</questiontype> 
  18.         <resp_num>3</resp_num> 
  19.         <itemdescription>Standard Action Test</itemdescription> 
  20.         <possible_score>10.00</possible_score> 
  21.         <score_criteria /> 
  22.         <s_rs>
  23.           <s_r>
  24.             <seq>3</seq> 
  25.             <narr>Standard Action Test Narrative</narr> 
  26.             <followup>efdqde</followup> 
  27.           </s_r>
  28.         </s_rs>
  29.         <udf_info /> 
  30.         <audit_response>
  31.           <id>11602</id> 
  32.           <question_id>13759</question_id> 
  33.           <resp>N/a</resp> 
  34.           <narr>Standard Action Test Narrative</narr> 
  35.           <score>0.0</score> 
  36.           <p_o>0</p_o> 
  37.           <n_o>0</n_o> 
  38.           <p_f>0</p_f> 
  39.           <n_f>0</n_f> 
  40.           <question_type>SelectResponse</question_type> 
  41.           <answered>1</answered> 
  42.           <recordChanged>Y</recordChanged> 
  43.           <corr_acts>
  44.             <corr_act>
  45.               <id>1</id> 
  46.             </corr_act>
  47.             <corr_act>
  48.               <id>3</id> 
  49.             </corr_act>
  50.           </corr_acts>
  51.         </audit_response>
  52. ...
This is my stylesheet:

Expand|Select|Wrap|Line Numbers
  1. <?xml version="1.0" encoding="UTF-8" ?>
  2. <xsl:stylesheet version="2.0"
  3.  
  4. xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
  5. xmlns:date="http://exslt.org/dates-and-times"
  6. xmlns:fo="http://www.w3.org/1999/XSL/Format"
  7. xmlns:xalan="http://xml.apache.org/xalan" 
  8. xmlns:java="http://xml.apache.org/xslt/java"
  9. xmlns:exsl="http://exslt.org/common" 
  10. xmlns:set="http://exslt.org/sets"
  11. xmlns:dyn="http://exslt.org/dynamic"
  12.  
  13. extension-element-prefixes="exsl"
  14. exclude-result-prefixes="set"> 
  15. <xsl:output />
  16.  
  17. <xsl:key name="response" match="audit_response" use="resp"/>
  18. <xsl:key name="responseNum" match="report/audit/questions/question" use="resp_num"/>
  19. <xsl:key name="car" match="report/audit/questions/question" use="audit_response/corr_acts/corr_act"/>
  20. <xsl:key name="response2" match="report/audit/questions/question" use="audit_response/resp" />
  21. <xsl:key name="corracts" match="report/audit/questions/question" use="audit_response/corr_acts/corr_act/id" />
  22. <xsl:key name="keys_sec_id" match="report/audit/questions/question" use="sec_id" />
  23.  
  24. <xsl:template match="/">
  25. <fo:root xmlns:fo="http://www.w3.org/1999/XSL/Format">
  26. <fo:layout-master-set>
  27. <fo:simple-page-master master-name="rptPages" page-height="10in"
  28. page-width="8in" margin-top="1cm" margin-bottom=".5cm" margin-left="1cm" margin-right="1cm" >
  29. <fo:region-body margin-bottom="1.5cm" margin-top="2cm" keep-together.within-page="always" >
  30. <fo:region-body> 
  31. <fo:region-after region-name="rptFooter" extent="1cm" />
  32. <fo:region-before region-name="rptHeader" extent="2cm" /> 
  33. </fo:simple-page-master> 
  34. </fo:layout-master-set>
  35. <fo:page-sequence master-reference="rptPages" force-page-count="no-force">
  36.      <fo:static-content flow-name="rptHeader" > 
  37.  
  38. <!-- beginning of region body and beginning of Page Header information-->
  39.  
  40. <fo:flow flow-name="xsl-region-body" >
  41.  
  42. <!-- beginning of test section -->
  43.  
  44. <fo:table table-layout="fixed" inline-progression-dimension="18cm" cell-spacing="0" cell-padding="0">
  45. <fo:table-column column-width="8cm" />
  46. <fo:table-column column-width="1cm" />
  47. <fo:table-column column-width="2cm" />
  48. <fo:table-column column-width="1.5cm" />
  49. <fo:table-column column-width=".1cm" />
  50. <fo:table-column column-width="1.5cm" />
  51.  
  52. <fo:table-body> 
  53. <fo:table-row>
  54. <fo:table-cell >
  55. <fo:block font="Arial" text-align="left" font-size="10pt" font-weight="bold" space-after="6px" > 
  56. Sections
  57. </fo:block>
  58. </fo:table-cell>
  59.  
  60. <fo:table-cell> 
  61. <fo:block font="Arial" text-align="center" font-size="10pt" font-weight="bold" space-after="6px" > 
  62. List #
  63. </fo:block>
  64. </fo:table-cell>
  65.  
  66. <fo:table-cell > 
  67. <fo:block font="Arial" text-align="center" font-size="10pt" font-weight="bold" space-after="6px" > 
  68. Response
  69. </fo:block>
  70. </fo:table-cell>
  71.  
  72. <fo:table-cell > 
  73. <fo:block font="Arial" text-align="center" font-size="10pt" font-weight="bold" space-after="6px" > 
  74. Tally
  75. </fo:block>
  76. </fo:table-cell>
  77. <fo:table-cell />
  78.  
  79. <fo:table-cell > 
  80. <fo:block font="Arial" text-align="center" font-size="10pt" font-weight="bold" space-after="6px" > 
  81. CAR 
  82. </fo:block>
  83. </fo:table-cell>
  84.  
  85. </fo:table-row>
  86. </fo:table-body>
  87. </fo:table>
  88. <fo:table table-layout="fixed" inline-progression-dimension="18cm" cell-spacing="0" cell-padding="0">
  89. <fo:table-column column-width="8cm" />
  90. <fo:table-column column-width="1cm" />
  91. <fo:table-column column-width="2cm" />
  92. <fo:table-column column-width="1.5cm" />
  93. <fo:table-column column-width=".1cm" />
  94. <fo:table-column column-width="1.5cm" /> 
  95. <fo:table-body> 
  96.  
  97. <xsl:for-each select="report/audit/questions/question">
  98. <xsl:sort data-type="number" select="sec_id"/>
  99. <xsl:sort data-type="number" select="sec_id" />
  100. <xsl:sort data-type="number" select="sub_sec_id" />
  101. <xsl:sort data-type="number" select="item_id" />
  102.  
  103. <fo:table-row>
  104.  
  105. <xsl:choose>
  106. <xsl:when test="sec_id">
  107. <xsl:variable name="test" select="sec_id"></xsl:variable>
  108. <xsl:if test="(sec_id &gt;=0) and sub_sec_id=0 and item_id=0 ">
  109. <fo:table-cell > 
  110. <fo:block font="Arial" text-align="left" font-size="8pt" font-weight="normal" space-after="2px"> 
  111. <xsl:value-of select ="sec_id" />-<xsl:value-of select ="sub_sec_id" />-
  112. <xsl:value-of select ="item_id" />
  113. <xsl:text disable-output-escaping="yes">&amp;#160;&amp;#160;&amp;#160;</xsl:text>
  114. <xsl:value-of select="itemdescription" />
  115. </fo:block>
  116. </fo:table-cell>
  117. </xsl:if> 
  118. <fo:table-cell />
  119.  
  120.  
  121. <fo:table-cell >
  122. <!-- brings back a unique response number -->
  123. <fo:block font="Arial" text-align="center" font-size="8pt" font-weight="normal" space-after="2px">
  124. <xsl:if test="not(sec_id &gt;=0 and sub_sec_id &gt;=0 and item_id=0)" >
  125. <xsl:if test="sec_id=$test">
  126. <xsl:for-each select="/report/audit/questions/question[generate-id() = generate-id(key('response2',audit_response/resp)[1])]" />
  127. <fo:block></fo:block>
  128. <xsl:if test="not(audit_response/resp='')">
  129. <xsl:value-of select ="resp_num" />
  130. </xsl:if>
  131. </xsl:if>
  132. </xsl:if>
  133. </fo:block>
  134. </fo:table-cell>
  135. <fo:table-cell >
  136. <fo:block font="Arial" text-align="center" font-size="8pt" font-weight="normal" space-after="2px">
  137. <xsl:choose> 
  138. <xsl:when test="sec_id">
  139. <xsl:if test="sec_id=$test">
  140. <xsl:if test="id=audit_response/question_id">
  141.  
  142.  
  143. <xsl:if test="not(audit_response/resp='')">
  144. <xsl:for-each select="/report/audit/questions/question[generate-id() = generate-id(key('response2',audit_response/resp)[1])]" />
  145. <xsl:variable name="groups"><xsl:value-of select="audit_response/resp" /></xsl:variable>
  146. <xsl:value-of select="exsl:node-set(set:distinct($groups))"/>
  147. <fo:block></fo:block>
  148. </xsl:if>
  149. </xsl:if>
  150. </xsl:if>
  151. </xsl:when>
  152. </xsl:choose>
  153. </fo:block>
  154. </fo:table-cell>
  155. <!-- brings back a tally of the responses -->
  156. <fo:table-cell>
  157. <fo:block font="Arial" text-align="center" font-size="8pt" font-weight="normal" space-after="2px">
  158. <xsl:if test="not(sec_id &gt;=0 and sub_sec_id &gt;=0 and item_id=0)" >
  159. <xsl:if test="sec_id=$test">
  160. <xsl:if test="not(audit_response/resp='')" >
  161. <xsl:for-each select="/report/audit/questions/question[generate-id() = generate-id(key('response2',audit_response/resp)[1])]" />
  162. <xsl:variable name="grouping"><xsl:value-of select="audit_response/resp" /></xsl:variable>
  163. <fo:block></fo:block> 
  164. <xsl:value-of select="count($grouping)"/>
  165. </xsl:if>
  166. </xsl:if>
  167. </xsl:if>
  168. </fo:block>
  169. </fo:table-cell>
  170. <!-- brings back a count of the cars per answered question --> 
  171. <xsl:choose>
  172. <xsl:when test="sec_id">
  173. <xsl:variable name="test" select="sec_id"></xsl:variable>
  174. <xsl:if test="(sec_id &gt;=0) and sub_sec_id=0 and item_id=0 ">
  175. <fo:table-cell > 
  176. <fo:block font="Arial" text-align="center" font-size="8pt" font-weight="bold" space-after="2px">
  177. <xsl:for-each select="/report/audit/questions/question">
  178. <xsl:if test="sec_id=$test">
  179. <xsl:variable name="trial"><number><xsl:value-of select="count(audit_response/corr_acts/corr_act[id])"/></number></xsl:variable>
  180. <xsl:if test="$trial &gt;0">
  181. <fo:block></fo:block>
  182. <xsl:value-of select ="sum(exsl:node-set($trial)/number)"/>
  183. </xsl:if>
  184. </xsl:if>
  185. </xsl:for-each>
  186. </fo:block>
  187. </fo:table-cell>
  188. </xsl:if>
  189. </xsl:when>
  190. </xsl:choose>
  191. </xsl:when>
  192. </xsl:choose><!--ends the outside choose -->
  193. </fo:table-row>
  194. </xsl:for-each>
  195. </fo:table-body>
  196. </fo:table<fo:block id="last-page"/>
  197. </fo:flow>
  198. </fo:page-sequence>
  199. </fo:root>
  200. </xsl:template>
  201. </xsl:stylesheet>
And this is how the report looks:

Sections List# Response Tally CAR
1-0-0 words 3 N/a 1 2
1 Yes 1 1
1 No 1 2
1 No 1
2-0-0 1 Yes 1 1
1 No 1
1 Yes 1

This report should print No only once for section 1-0-0 with a count of two. It should print Yes only once for section 2-0-0 with a count of 2. It should print a total of 5 for the CAR's in section 1-0-0 and only 1 (as it does) for section 2-0-0.


Sorry this is such a long post.
Thanks
Debbie
Jun 12 '06 #1
0 3272

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

Similar topics

0
by: Sergio del Amo | last post by:
Hi, I use the xslt functions provided by php. I am running in my computer the package xampp(www.apachefriends.org) which includes php/apache/mysql .. In this package the php includes the sablotron...
1
by: Doug Farrell | last post by:
Hi all, I'm trying to use the 4Suite xml/xsl tools to transform some XML data into HTML. I'm using some examples from the O'Reilly book "Python and XML" and things are blowing up. Here is the...
5
by: K. N. | last post by:
Is there any good and fast Python module for XSLT processing ? I'm going to use XML and XSLT to generate web pages, so I need XSLT processor that will be able to transform for example a DOM object...
6
by: Ramon M. Felciano | last post by:
Helo all -- I'm trying to gain a deeper understand for what type of semi-declarative programming can be done through XML and XPath/XSLT. I'm looking at graph processing problems as a testbed for...
9
by: Jeff Rubard | last post by:
I am curious to know whether anyone has experience using XSLT for web XML (non-XHTML) styling, either with CSS or standalone. I myself have engaged in rather unsuccessful experiments with the...
4
by: Ringo Langly | last post by:
Hi all, I'm a seasoned web programmer, but I've never touched XSLT. It's always been one of those acronyms I've never needed to educate myself on. Now... we're working with a web content...
1
by: Jens Mueller | last post by:
Hi there, this is a Java-XML Question, so I am not sure whether this is the right place, haven't found anything better .... I try to convert a Java object to XML via SAX and let the FOP...
4
by: Asbjørn Ulsberg | last post by:
Sorry for posting to a lot of groups, but I'm not sure what this problem relates to, so I thought it was better to be safe than sorry. Please feel free to set FUT to the proper group when...
10
by: daz_oldham | last post by:
Hi I am doing an XSLT that processes (for example) a list of hotels. Each hotel has the attribute @StarRating which is one of the following values: * ** *** ****
10
by: olivier.scalbert | last post by:
Hello, the following constraints: source: <Source> <Item>AAA</Item> <Item>BBBBBBBBBBB</Item> <Item>CCCCCCCCC</Item> <Item>DDDDDDDDDDDDDDD</Item>
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 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 former...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...

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.