|
Subject: [xsl] control break processing From: Debbie <debbieannepower@xxxxxxxxx> Date: Sun, 20 Aug 2006 15:03:51 -0230 |
I hope this gets through...I'm having trouble getting through to your mailing list.
I'm using XALAN and XSLT1.0 to generate a report in pdf format in FOP 0.20.5. My editor is Netbeans.
My xml document stores a list of questions and responses to the questions. These questions are divided up into sections (i.e section 1-0-0 has a list of questions and responses, section 2-0-0 has a list of questions and resposnses and so on).
I need to return a list of unique responses per section. The code I have now fails when there are 3 consecutive answers. For instance if the last 2 responses in section one are No and the first response in section 2 is No the report prints No twice in section 1 and doesn't print at all in section 2. I've tried all of the archives and still can't find a solution. I've tried the muenchian method as well and couldn't get it right. Note: Though this report uses Yes, No as responses the responses will be generated dynamically and could be anything not necessarily yes and no.
<!--brings back unique responses -->
<fo:table-row>
<fo:table-cell>
<fo:block font="Arial" text-align="left"
font-size="8pt" space-before="0px" font-weight="normal"
space-after="0px" linefeed-treatment="ignore"
white-space-collapse="true" white-space-treatment="ignore"
wrap-option="no-wrap" >
<xsl:for-each
select="audit_response/resp[1][not(.=preceding::audit_response/resp[1])]
| audit_response/resp[1][not(.=following::audit_response/resp[1])]">
<xsl:if
test="not(../resp=following-sibling::audit_response/resp[1] )">
<text /><xsl:value-of
select="child::text()" /><text />
</xsl:if>
</xsl:for-each>
</fo:block>
</fo:table-cell><itemdescription>Section 1, SubSection 1 - Enter section 1, subsection 1 description.</itemdescription>
<itemdescription>Section 1, SubSection 2 - Enter section 1, subsection 2 description.</itemdescription>
<itemdescription>Section 2, SubSection 1 - Enter section 2, subsection 1 description.</itemdescription>
<itemdescription>Section 2, SubSection 2 - Enter section 2, subsection 2 description.</itemdescription>
<itemdescription>Section 1, Subsection 2, Item 1 - Enter an audit definition / question.</itemdescription>
<itemdescription>Section 2, Subsection 1, Item 1 - Enter an audit definition / question.</itemdescription>
<itemdescription>Section 2, Subsection 2, Item 1 - Enter an audit definition / question.</itemdescription>
<itemdescription>Section 1, Subsection 1, Item 2 - Enter an audit definition / question.</itemdescription>
<itemdescription>Section 1, Subsection 2, Item 2 - Enter an audit definition / question.</itemdescription>
<itemdescription>Section 2, Subsection 1, Item 2 - Enter an audit definition / question.</itemdescription>
<itemdescription>Section 2, Subsection 2, Item 1 - Enter an audit definition / question.</itemdescription>
<!--
Document : tallyReport.xsl
Created on : July 17, 2006
Author : dpower
Description:
Combination of corrective action report and tally
report. Now referred to
as Summary Reportxmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:date="http://exslt.org/dates-and-times" xmlns:fo="http://www.w3.org/1999/XSL/Format" xmlns:xalan="http://xml.apache.org/xalan" xmlns:java="http://xml.apache.org/xslt/java" xmlns:exsl="http://exslt.org/common" extension-element-prefixes="exsl">
<!-- keys for the Summary Report--> <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">
<fo:layout-master-set>
<fo:simple-page-master master-name="simpleA4"
page-height="10in" page-width="8in" margin-top="1cm"
margin-bottom="1cm" margin-left="1cm" margin-right="1cm">
<fo:region-before region-name="rptHeader" extent="4.8cm" />
<fo:region-body margin-bottom="2.8cm" margin-top="4.8cm" />
<fo:region-after extent="2cm"/>
</fo:simple-page-master>
</fo:layout-master-set> <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:./IATAlogo.jpg" />
</fo:table-cell>
</fo:table-row>
<fo:table-row>
<fo:table-cell number-columns-spanned="3">
<fo:block font-size="12pt" text-align="right"
font="Arial" font-weight="bold" >Summary Report</fo:block>
</fo:table-cell>
</fo:table-row>
<fo:table-row>
<fo:table-cell number-columns-spanned="3">
<fo:block border-bottom-style="solid"
border-bottom-color="#000000"
border-top-color="#000000" border-bottom-width="thin"
border-top-width="thin" space-after="5px" >
</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="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" space-afer="5px">
<xsl:value-of select="report/audit/audit_date" />
</fo:block>
</fo:table-cell>
</fo:table-row>
<fo:table-row>
<fo:table-cell number-columns-spanned="3">
<fo:block border-bottom-style="solid"
border-bottom-color="#000000"
border-top-color="#000000" border-bottom-width="thin"
border-top-width="thin" space-after="5px" >
</fo:block>
</fo:table-cell>
</fo:table-row>
</fo:table-body>
</fo:table>
</fo:static-content><!--Ends report header--> <!--Begins Report footer-->
<fo:static-content flow-name="xsl-region-after">
<fo:block font-size="10pt" font-weight="normal">
<fo:table table-layout="fixed" inline-progression-dimension="18cm">
<fo:table-column column-width="1.5cm" />
<fo:table-column column-width="14.5cm"/>
<fo:table-column column-width="2cm"/>
<fo:table-body>
<fo:table-row>
<fo:table-cell>
<fo:block font-size="8pt" font-weight="normal">
<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:table-cell>
<fo:table-cell>
<fo:block font-size="8pt" 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>
<!--Ends report footer-->
<!--Begins region body--> <fo:flow flow-name="xsl-region-body">
<fo:table table-layout="fixed"
inline-progression-dimension="18.5cm" 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-size="12pt" font="Arial"
font-weight="bold" space-after="5px" >
Results Tally By Section
</fo:block>
</fo:table-cell>
</fo:table-row>
<fo:table-row>
<fo:table-cell number-columns-spanned="6">
<fo:block border-bottom-style="solid"
border-bottom-color="#000000"
border-top-color="#000000" border-bottom-width="thin"
border-top-width="thin" space-after="5px" >
</fo:block>
</fo:table-cell>
</fo:table-row>
</fo:table-body>
</fo:table>
<fo:table table-layout="fixed" inline-progression-dimension="18.5cm" 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:if test="(sec_id >=0) and sub_sec_id=0 and item_id=0 "> <fo:table-row> <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> </fo:table-row> </xsl:if> <!--brings back unique responses --> <fo:table-row> <fo:table-cell> <fo:block font="Arial" text-align="left" font-size="8pt" space-before="0px" font-weight="normal" space-after="0px" linefeed-treatment="ignore" white-space-collapse="true" white-space-treatment="ignore" wrap-option="no-wrap" > <xsl:for-each select="audit_response/resp[1][not(.=preceding::audit_response/resp[1])] | audit_response/resp[1][not(.=following::audit_response/resp[1])]"> <xsl:if test="not(../resp=following-sibling::audit_response/resp[1] )"> <text /><xsl:value-of select="child::text()" /><text /> </xsl:if> </xsl:for-each> </fo:block> </fo:table-cell> <!-- brings back a tally of the responses -->
<xsl:variable name="group"
select="audit_response/resp[1][not(.=preceding::audit_response/resp[1])]
| audit_response/resp[1][not(.=following::audit_response/resp[1])]"/>
<fo:table-cell />
<fo:table-cell>
<fo:block font="Arial" text-align="center"
font-size="8pt" font-weight="normal" space-after="0px"> <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="$group != ''">
<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="0px">
<xsl:variable name="sec_id" select="sec_id"/> <xsl:if
test="not(../resp=following-sibling::audit_response/resp[1] )">
<xsl:value-of
select="count(../question[sec_id =
$sec_id]/audit_response/resp[.=$group])"/>
</xsl:if>
</fo:block>
</xsl:when>
</xsl:choose>
</xsl:if>
</xsl:if>
</xsl:if>
</fo:block>
</fo:table-cell>
</fo:table-row>
</xsl:when>
</xsl:choose>
</xsl:for-each>
</fo:table-body>
</fo:table><fo:table table-layout="fixed" inline-progression-dimension="18.5cm"
cell-spacing="0" cell-padding="0" space-after="10px">
<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 number-columns-spanned="7">
<fo:block border-bottom-style="solid"
border-bottom-color="#000000" border-top-color="#000000"
border-bottom-width="thin"
border-top-width="thin" space-after="5px" >
</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" >
Results Tally Summary
</fo:block>
</fo:table-cell>
</fo:table-row>
<fo:table-row>
<fo:table-cell >
<fo:block font="Arial" text-align="left" 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: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"/>
<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: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:if
test="not(count(key('response2',audit_response/resp))=0)">
<xsl:value-of
select="count(key('response2',audit_response/resp))"/>
</xsl:if>
</xsl:if>
</xsl:for-each>
</fo:block>
</fo:table-cell>
</fo:table-row>
<fo:table-row>
<fo:table-cell >
<fo:block font="Arial" text-align="left"
font-size="10pt" font-weight="normal" space-after="6px" >
Corrective Action Records (CARs)
</fo:block>
</fo:table-cell>
<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>
<!--Ends Tally Report--><fo:table table-layout="fixed" inline-progression-dimension="18.5cm"
cell-spacing="0" cell-padding="0" space-after="10px">
<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 number-columns-spanned="7">
<fo:block border-bottom-style="solid"
border-bottom-color="#000000" border-top-color="#000000"
border-bottom-width="thin"
border-top-width="thin" space-after="5px" >
</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-before="4px" space-after="5px" >
Corrective Action Records
</fo:block>
</fo:table-cell>
</fo:table-row>
</fo:table-body>
</fo:table> <xsl:apply-templates select="report/audit/corr_acts/corr_act"/>
<fo:block id="last-page"/>
</fo:flow>
</fo:page-sequence>
</fo:root>
</xsl:template>
<fo:block font="Arial" font-size="10pt" background-color="rgb(200,200,200)"> Corrective Action Status: <fo:inline color="red"> <xsl:choose> <xsl:when test="status = 1"> Open </xsl:when> <xsl:when test="status = 2"> Interim Completed </xsl:when>
<xsl:when test="status = 3">
Final Completed
</xsl:when> <xsl:when test="status = 4">
Review
</xsl:when> <xsl:when test="status = 5">
Closed
</xsl:when>
</xsl:choose>
</fo:inline>
</fo:block>
<fo:block font="Arial" font-size="8pt" space-after="7px">
<fo:block font="Arial" font-size="10pt" font-weight="bold"
space-before="5px" space-after="3px"
text-decoration="underline" >
Basis For Corrective Action
</fo:block>
<fo:table table-layout="fixed" inline-progression-dimension="12cm">
<fo:table-column column-width="10cm" />
<fo:table-column column-width="3cm" />
<fo:table-column column-width="3cm" />
<fo:table-body>
<fo:table-row>
<fo:table-cell>
<fo:block font="Arial" font-size="8pt" space-after="3px" >
<fo:inline font-weight="bold">Initiated By: </fo:inline>
<xsl:call-template name="getUserName">
<xsl:with-param name="customerId"
select="/report/audit/cust_id" />
<xsl:with-param name="userId" select="init_by" />
</xsl:call-template>
</fo:block>
</fo:table-cell>
<fo:table-cell>
<fo:block font="Arial" font-size="8pt" space-after="3px" >
<fo:inline font-weight="bold">Date: </fo:inline>
<xsl:value-of select="date_init"/>
</fo:block>
</fo:table-cell>
<fo:table-cell>
<fo:block font="Arial" font-size="8pt" space-after="3px">
<fo:inline font-weight="bold">Priority: </fo:inline>
<xsl:choose>
<xsl:when test="priority = 1">
High
</xsl:when> <xsl:when test="priority = 2">
Medium
</xsl:when> <xsl:when test="priority = 3">
Low
</xsl:when>
</xsl:choose>
</fo:block>
</fo:table-cell>
</fo:table-row>
</fo:table-body>
</fo:table>
<fo:block font="Arial" font-size="8pt" space-after="3px" >
<fo:inline font-weight="bold">Type(s): </fo:inline>
<xsl:apply-templates select="types/type"/>
</fo:block>
<fo:block font="Arial" font-size="8pt" space-after="3px" >
<fo:inline font-weight="bold">
<xsl:call-template name="getSections">
<xsl:with-param name="caId" select="id" />
</xsl:call-template>
</fo:inline>
<xsl:call-template name="getQuestionText">
<xsl:with-param name="caId" select="id" />
</xsl:call-template>
</fo:block>
<fo:block font="Arial" font-size="8pt" space-after="3px" >
<fo:inline font-weight="bold">Description: </fo:inline>
<xsl:value-of select="act_desc"/>
</fo:block> </fo:block>
</xsl:template><xsl:template match="report/corr_acts/corr_act/types/type"> <xsl:variable name="cId" select="/report/audit/cust_id"/> <xsl:variable name="typeId" select="id"/> <xsl:if test="position() = last()"> <xsl:value-of select="/report/customer_info/customer[id=$cId]/ca_types/ca_type[id=$typeId]/type_name"/>
</xsl:if> <xsl:if test="position() != last()"> <xsl:value-of select="concat(/report/customer_info/customer[id=$cId]/ca_types/ca_type[id=$typeId]/type_name,', ')"/> </xsl:if> </xsl:template>
<xsl:template match="/report/audit/questions/question/audit_response/corr_acts/corr_act"> </xsl:template>
<!--Gets a user name based on CustomerId ans UserId--> <xsl:template match="node()" name="getUserName"> <xsl:param name="customerId" select="." /> <xsl:param name="userId" select="." />
<xsl:value-of select="concat(/report/customer_info/customer[id=$customerId]/users/user[id=$userId]/first_name,' ',/report/customer_info/customer[id=$customerId]/users/user[id=$userId]/last_name)" />
<!--Gets Question Text based on Corrective Action ID--> <xsl:template match="node()" name="getQuestionText"> <xsl:param name="caId" select="." />
<!--<xsl:if test="/report/audit/questions/question/audit_response/corr_acts/corr_act[id=$caId]/id = $caId">
<xsl:for-each select="/report/audit/questions/question/audit_response/corr_acts/corr_act[id=$caId]">
<fo:block>
<!--<xsl:value-of
select="concat(../../../sec_id,'-',../../../sub_sec_id,'-',../../../item_id,'
',../../../itemdescription)"/>-->
<xsl:value-of select="(../../../itemdescription)"/>
</fo:block>
</xsl:for-each><!--Gets sec-id,sub-sec-id and item-id Text based on Corrective Action ID--> <xsl:template match="node()" name="getSections"> <xsl:param name="caId" select="." />
<xsl:for-each
select="/report/audit/questions/question/audit_response/corr_acts/corr_act[id=$caId]">
<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:block>
Question(s): <xsl:value-of
select="concat(../../../sec_id,'-',../../../sub_sec_id,'-',../../../item_id)"
/>
</fo:block>
</xsl:for-each><xsl:template match="node()|@*"> <xsl:copy> <xsl:apply-templates select="@*|node()"/> </xsl:copy> </xsl:template>
| Current Thread |
|---|
|
| <- Previous | Index | Next -> |
|---|---|---|
| RE: [xsl] Xpath to count occurances, Michael Kay | Thread | [xsl] Transforming Multuple, Mohsen Saboorian |
| Re: [xsl] xinclude in xslt2, Oleg Tkachenko | Date | [xsl] Transforming Multuple, Mohsen Saboorian |
| Month |