[exslt] exsl help
by Debbie other posts by this author
Jun 12 2006 9:38AM messages near this date
Re: [exslt] str:tokenize question
|
Re: [exslt] Problem loading module Dates and Times into xmlspy
& XSLT Forgive me if I am not suppose to request help from this website. Stylus
Studio recommended I send you my request for help. If you can't help me
could you suggest a forum that might be able to? Thanks in advance....here
is my info:
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):
<?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> 13759</id>
<sec_id> 1</sec_id>
<sub_sec_id> 1</sub_sec_id>
<item_id> 1</item_id>
<questiontype> SelectResponse</questiontype>
<resp_num> 3</resp_num>
<itemdescription> Standard Action Test</itemdescription>
<possible_score> 10.00</possible_score>
<score_criteria />
- <s_rs>
- <s_r>
<seq> 3</seq>
<narr> Standard Action Test Narrative</narr>
<followup> efdqde</followup>
</s_r>
</s_rs>
<udf_info />
- <audit_response>
<id> 11602</id>
<question_id> 13759</question_id>
<resp> N/a</resp>
<narr> Standard Action Test Narrative</narr>
<score> 0.0</score>
<p_o> 0</p_o>
<n_o> 0</n_o>
<p_f> 0</p_f>
<n_f> 0</n_f>
<question_type> SelectResponse</question_type>
<answered> 1</answered>
<recordChanged> Y</recordChanged>
- <corr_acts>
- <corr_act>
<id> 1</id>
</corr_act>
- <corr_act>
<id> 3</id>
</corr_act>
</corr_acts>
</audit_response>
This is my stylesheet:
<?xml version="1.0" encoding="UTF-8" ?>
<xsl:stylesheet version="2.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"<http://www.w3.org/1999/XSL/Transform>
xmlns:date="http://exslt.org/dates-and-times"<http://exslt.org/dates-and-times>
xmlns:fo="http://www.w3.org/1999/XSL/Format"<http://www.w3.org/1999/XSL/Format>
xmlns:xalan="http://xml.apache.org/xalan" <http://xml.apache.org/xalan>
xmlns:java="http://xml.apache.org/xslt/java"<http://xml.apache.org/xslt/java>
xmlns:exsl="http://exslt.org/common" <http://exslt.org/common>
xmlns:set="http://exslt.org/sets" <http://exslt.org/sets>
xmlns:dyn="http://exslt.org/dynamic" <http://exslt.org/dynamic>
extension-element-prefixes="exsl"
exclude-result-prefixes="set">
<xsl:output />
<xsl:key name="response" match="audit_response" use="resp"/>
<xsl:key name="responseNum" match="report/audit/questions/question"
use="resp_num"/>
<xsl:key name="car" match="report/audit/questions/question"
use="audit_response/corr_acts/corr_act"/>
<xsl:key name="response2" match="report/audit/questions/question"
use="audit_response/resp" />
<xsl:key name="corracts" match="report/audit/questions/question"
use="audit_response/corr_acts/corr_act/id" />
<xsl:key name="keys_sec_id" match="report/audit/questions/question"
use="sec_id" />
<xsl:template match="/">
<fo:root xmlns:fo="http://www.w3.org/1999/XSL/Format"> <http://www.w3.org/1999/XSL/Format>
<!--
Document : auditResponse.xsl
Created on : May 19/2006
Author : Debbie Power
Description: Tally Report for JLaptop V35
-->
<fo:layout-master-set>
<fo:simple-page-master master-name="rptPages" page-height="10in"
page-width="8in" margin-top="1cm" margin-bottom=".5cm" margin-left="1cm"
margin-right="1cm" >
<fo:region-body margin-bottom="1.5cm" margin-top="2cm"
keep-together.within-page="always" >
</fo:region-body>
<fo:region-after region-name="rptFooter" extent="1cm" />
<fo:region-before region-name="rptHeader" extent="2cm" />
</fo:simple-page-master>
</fo:layout-master-set>
<fo:page-sequence master-reference="rptPages" force-page-count="no-force">
<fo:static-content flow-name="rptHeader" >
<!-- REPORT HEADER -->
<fo:table table-layout="fixed" inline-progression-dimension="18cm"
cell-spacing="0" cell-padding="0">
<fo:table-column column-width="6cm" />
<fo:table-column column-width="9cm" />
<fo:table-column column-width="3.5cm" />
<fo:table-body>
<fo:table-row>
<fo:table-cell>
<!--<fo:external-graphic width="2.0in" height="0.75in"
src="file:images/headerlogocorner.jpg" /> -->
</fo:table-cell>
</fo:table-row>
<fo:table-row>
<fo:table-cell>
<fo:block font-size="17pt" font="Arial" font-weight="bold">
<!-- <xsl:value-of select="report/audit/company_name" /> -->
</fo:block>
</fo:table-cell>
</fo:table-row>
<fo:table-row>
<fo:table-cell>
<fo:block>
<xsl:text disable-output-escaping="yes"> &#160;</xsl:text>
</fo:block>
</fo:table-cell>
</fo:table-row>
<fo:table-row>
<fo:table-cell>
<fo:block font-size="12pt" font="Arial" font-weight="bold"
space-after="5px"> Tally Report</fo:block>
</fo:table-cell>
</fo:table-row>
</fo:table-body>
</fo:table>
</fo:static-content>
<!-- End of header section. Beginning of page footer -->
<fo:static-content flow-name="rptFooter">
<fo:block font-size="9pt" font-weight="normal">
<fo:table table-layout="fixed" inline-progression-dimension="18cm"
cell-spacing="0" cell-padding="0">
<fo:table-column column-width="4cm" />
<fo:table-column column-width="7.5cm" />
<fo:table-column column-width="2cm" />
<fo:table-column column-width="2cm" />
<fo:table-body>
<fo:table-row>
<fo:table-cell>
<fo:block> <xsl:text
disable-output-escaping="yes"> &#160;</xsl:text></fo:block>
</fo:table-cell>
</fo:table-row>
<fo:table-row>
<fo:table-cell>
<fo:block font-size="9pt" font="Arial" font-weight="normal"
text-align="left" >
<xsl:variable name="date"> <xsl:value-of select="date:date-time()"
/> </xsl:variable>
<xsl:value-of select="substring($date,1,10)" />
</fo:block>
</fo:table-cell>
<fo:table-cell>
<fo:block font="Arial" text-align="center" font-size="6pt"
font-weight="normal" >
<xsl:value-of select="report/AuditResponse/footerText" />
</fo:block>
</fo:table-cell>
<fo:table-cell>
<fo:block font="Arial" text-align="right" font-size="9pt"
font-weight="normal"> Page <fo:page-number/> / <fo:page-number-citation
ref-id="last-page"/> </fo:block>
</fo:table-cell>
</fo:table-row>
</fo:table-body>
</fo:table>
</fo:block>
</fo:static-content>
<!-- beginning of region body and beginning of Page Header information-->
<fo:flow flow-name="xsl-region-body" >
<fo:table table-layout="fixed" inline-progression-dimension="18cm"
cell-spacing="0" cell-padding="0">
<fo:table-column column-width="6cm" />
<fo:table-column column-width="9cm" />
<fo:table-column column-width="3.5cm" />
<fo:table-body>
<fo:table-row>
<fo:table-cell>
<fo:block font="Arial" font-size="9pt"
font-weight="bold"> Customer:</fo:block>
</fo:table-cell>
<fo:table-cell>
<fo:block font="Arial" font-size="9pt">
<xsl:value-of select="report/audit/customername" />
</fo:block>
</fo:table-cell>
</fo:table-row>
<fo:table-row>
<fo:table-cell>
<fo:block font-size="9pt" font="Arial" font-weight="bold"> Audit
Location:</fo:block>
</fo:table-cell>
<fo:table-cell>
<fo:block font="Arial" font-size="9pt">
<xsl:value-of select="report/audit/levelstring" />
</fo:block>
</fo:table-cell>
</fo:table-row>
<fo:table-row>
<fo:table-cell>
<fo:block font-size="9pt" font="Arial" font-weight="bold"> Audit
Name:</fo:block>
</fo:table-cell>
<fo:table-cell>
<fo:block font="Arial" font-size="9pt">
<xsl:value-of select="report/audit/auditname" />
</fo:block>
</fo:table-cell>
</fo:table-row>
<fo:table-row>
<fo:table-cell>
<fo:block font="Arial" font-size="9pt" font-weight="bold"> Audit
Date:</fo:block>
</fo:table-cell>
<fo:table-cell>
<fo:block font="Arial" font-size="9pt">
<xsl:value-of select="report/audit/audit_date" />
</fo:block>
</fo:table-cell>
</fo:table-row>
<fo:table-row>
<fo:table-cell >
<fo:block font-size="9pt" font="Arial" font-weight="bold"> User
Account:</fo:block>
</fo:table-cell>
<fo:table-cell >
<fo:block font="Arial" font-size="9pt">
<xsl:value-of select="report/audit/user_name" />
</fo:block>
</fo:table-cell>
</fo:table-row>
<fo:table-row>
<fo:table-cell number-columns-spanned="4">
<fo:block border-bottom-style="solid" border-top-style="thin"
border-bottom-color="#000000" border-top-color="#000000"
border-bottom-width="thin"
border-top-width="thin" space-after="6px">
</fo:block>
</fo:table-cell>
</fo:table-row>
<fo:table-row />
<fo:table-row />
</fo:table-body>
</fo:table>
<!-- beginning of test section -->
<fo:table table-layout="fixed" inline-progression-dimension="18cm"
cell-spacing="0" cell-padding="0">
<fo:table-column column-width="8cm" />
<fo:table-column column-width="1cm" />
<fo:table-column column-width="2cm" />
<fo:table-column column-width="1.5cm" />
<fo:table-column column-width=".1cm" />
<fo:table-column column-width="1.5cm" />
<fo:table-body>
<fo:table-row>
<fo:table-cell >
<fo:block font="Arial" text-align="left" font-size="10pt" font-weight="bold"
space-after="6px" >
Sections
</fo:block>
</fo:table-cell>
<fo:table-cell>
<fo:block font="Arial" text-align="center" font-size="10pt"
font-weight="bold" space-after="6px" >
List #
</fo:block>
</fo:table-cell>
<fo:table-cell >
<fo:block font="Arial" text-align="center" font-size="10pt"
font-weight="bold" space-after="6px" >
Response
</fo:block>
</fo:table-cell>
<fo:table-cell >
<fo:block font="Arial" text-align="center" font-size="10pt"
font-weight="bold" space-after="6px" >
Tally
</fo:block>
</fo:table-cell>
<fo:table-cell />
<fo:table-cell >
<fo:block font="Arial" text-align="center" font-size="10pt"
font-weight="bold" space-after="6px" >
CAR
</fo:block>
</fo:table-cell>
</fo:table-row>
</fo:table-body>
</fo:table>
<fo:table table-layout="fixed" inline-progression-dimension="18cm"
cell-spacing="0" cell-padding="0">
<fo:table-column column-width="8cm" />
<fo:table-column column-width="1cm" />
<fo:table-column column-width="2cm" />
<fo:table-column column-width="1.5cm" />
<fo:table-column column-width=".1cm" />
<fo:table-column column-width="1.5cm" />
<fo:table-body>
<xsl:for-each select="report/audit/questions/question">
<xsl:sort data-type="number" select="sec_id"/>
<xsl:sort data-type="number" select="sec_id" />
<xsl:sort data-type="number" select="sub_sec_id" />
<xsl:sort data-type="number" select="item_id" />
<fo:table-row>
<xsl:choose>
<xsl:when test="sec_id">
<xsl:variable name="test" select="sec_id"> </xsl:variable>
<xsl:if test="(sec_id >=0) and sub_sec_id=0 and item_id=0 ">
<fo:table-cell >
<fo:block font="Arial" text-align="left" font-size="8pt"
font-weight="normal" space-after="2px">
<xsl:value-of select ="sec_id" /> -<xsl:value-of select ="sub_sec_id" />-
<xsl:value-of select ="item_id" />
<xsl:text
disable-output-escaping="yes"> &#160;&#160;&#160;</xsl:text>
<xsl:value-of select="itemdescription" />
</fo:block>
</fo:table-cell>
</xsl:if>
<fo:table-cell />
<fo:table-cell >
<!-- brings back a unique response number -->
<fo:block font="Arial" text-align="center" font-size="8pt"
font-weight="normal" space-after="2px">
<xsl:if test="not(sec_id >=0 and sub_sec_id >=0 and item_id=0)" >
<xsl:if test="sec_id=$test">
<xsl:for-each select="/report/audit/questions/question[generate-id() =
generate-id(key('response2',audit_response/resp)[1])]" />
<fo:block> </fo:block>
<xsl:if test="not(audit_response/resp='')">
<xsl:value-of select ="resp_num" />
</xsl:if>
</xsl:if>
</xsl:if>
</fo:block>
</fo:table-cell>
<fo:table-cell >
<fo:block font="Arial" text-align="center" font-size="8pt"
font-weight="normal" space-after="2px">
<xsl:choose>
<xsl:when test="sec_id">
<xsl:if test="sec_id=$test">
<xsl:if test="id=audit_response/question_id">
<xsl:if test="not(audit_response/resp='')">
<xsl:for-each select="/report/audit/questions/question[generate-id() =
generate-id(key('response2',audit_response/resp)[1])]" />
<xsl:variable name="groups"> <xsl:value-of select="audit_response/resp"
/> </xsl:variable>
<xsl:value-of select="exsl:node-set(set:distinct($groups))"/>
<fo:block> </fo:block>
</xsl:if>
</xsl:if>
</xsl:if>
</xsl:when>
</xsl:choose>
</fo:block>
</fo:table-cell>
<!-- 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 >=0 and sub_sec_id >=0 and item_id=0)" >
<xsl:if test="sec_id=$test">
<xsl:if test="not(audit_response/resp='')" >
<xsl:for-each select="/report/audit/questions/question[generate-id() =
generate-id(key('response2',audit_response/resp)[1])]" />
<xsl:variable name="grouping"> <xsl:value-of select="audit_response/resp"
/> </xsl:variable>
<fo:block> </fo:block>
<xsl:value-of select="count($grouping)"/>
</xsl:if>
</xsl:if>
</xsl:if>
</fo:block>
</fo:table-cell>
<!-- brings back a count of the cars per answered question -->
<xsl:choose>
<xsl:when test="sec_id">
<xsl:variable name="test" select="sec_id"> </xsl:variable>
<xsl:if test="(sec_id >=0) and sub_sec_id=0 and item_id=0 ">
<fo:table-cell >
<fo:block font="Arial" text-align="center" font-size="8pt"
font-weight="bold" space-after="2px">
<xsl:for-each select="/report/audit/questions/question">
<xsl:if test="sec_id=$test">
<xsl:variable name="trial"> <number><xsl:value-of
select="count(audit_response/corr_acts/corr_act[id])"/> </number></xsl:variable>
<xsl:if test="$trial >0">
<fo:block> </fo:block>
<xsl:value-of select ="sum(exsl:node-set($trial)/number)"/>
</xsl:if>
</xsl:if>
</xsl:for-each>
</fo:block>
</fo:table-cell>
</xsl:if>
</xsl:when>
</xsl:choose>
</xsl:when>
</xsl:choose> <!--ends the outside choose -->
</fo:table-row>
</xsl:for-each>
</fo:table-body>
</fo:table> <fo:table table-layout="fixed" space-before="7px" border="1"
border-style="solid" background-color="#EEEEEE"
inline-progression-dimension="18cm" cell-spacing="0" cell-padding="0">
<fo:table-column column-width="8cm" />
<fo:table-column column-width="1cm" />
<fo:table-column column-width="2cm" />
<fo:table-column column-width="1.5cm" />
<fo:table-column column-width="2.5cm" />
<fo:table-column column-width=".5cm" />
<fo:table-body>
<fo:table-row>
<fo:table-cell >
<fo:block font="Arial" text-align="left" font-size="10pt" font-weight="bold"
space-after="6px" >
Report Summary Totals:
</fo:block>
</fo:table-cell>
<fo:table-cell />
<fo:table-cell >
<fo:block font="Arial" text-align="right" font-size="10pt"
font-weight="bold" space-after="6px" >
Responses
</fo:block>
</fo:table-cell>
<fo:table-cell>
<fo:block font="Arial" text-align="center" font-size="10pt"
font-weight="bold" space-after="6px" >
Total
</fo:block>
</fo:table-cell>
</fo:table-row>
<fo:table-row>
<fo:table-cell />
</fo:table-row>
</fo:table-body>
</fo:table>
<!-- table to bring back the responses and car tallies-->
<fo:table table-layout="fixed" border="1" border-style="solid"
background-color="#99FFFF" inline-progression-dimension="18cm"
cell-spacing="0" cell-padding="0">
<fo:table-column column-width="8cm" />
<fo:table-column column-width="1cm" />
<fo:table-column column-width="2cm" />
<fo:table-column column-width="1.5cm" />
<fo:table-column column-width="2.5cm" />
<fo:table-column column-width=".5cm" />
<fo:table-body>
<fo:table-row>
<fo:table-cell />
<fo:table-cell />
<fo:table-cell >
<fo:block font="Arial" text-align="center" font-size="8pt"
font-weight="normal" space-after="2px">
<xsl:for-each select="report/audit/questions/question[generate-id() =
generate-id(key('response2',audit_response/resp)[1])]">
<xsl:if test="not(audit_response/resp='')" >
<fo:block> </fo:block>
<xsl:value-of select="audit_response/resp"/>
</xsl:if>
</xsl:for-each>
</fo:block>
</fo:table-cell>
<fo:table-cell >
<fo:block font="Arial" text-align="center" font-size="8pt"
font-weight="normal" space-after="2px">
<xsl:for-each select="report/audit/questions/question[count(.|
key('response2', audit_response/resp)[1]) = 1]">
<xsl:if test="not(audit_response/resp='')" >
<fo:block> </fo:block>
<xsl:value-of select="count(key('response2',audit_response/resp))"/>
</xsl:if>
</xsl:for-each>
</fo:block>
</fo:table-cell>
</fo:table-row>
<fo:table-row>
<fo:table-cell />
<fo:table-cell />
<fo:table-cell >
<fo:block font="Arial" text-align="center" font-size="10pt"
font-weight="bold" space-after="6px" >
CARs
</fo:block>
</fo:table-cell>
<!-- brings back a count of the cars per answered question -->
<fo:table-cell>
<fo:block font="Arial" text-align="center" font-size="8pt"
font-weight="normal" space-after="2px">
<xsl:choose>
<xsl:when test="/report/audit/questions/question">
<xsl:if test="not(audit_response/resp='')" >
<xsl:if test="not(audit_response/corr_acts/corr_act='')">
<xsl:if test="not(audit_response/corr_acts/corr_act/id=0)">
<xsl:value-of select="count(//corr_act) div 2"/>
</xsl:if>
</xsl:if>
</xsl:if>
</xsl:when>
</xsl:choose>
</fo:block>
</fo:table-cell>
</fo:table-row>
<!--end of CAR code -->
</fo:table-body>
</fo:table>
<fo:block id="last-page"/>
</fo:flow>
</fo:page-sequence>
</fo:root>
</xsl:template>
</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
|