Loading ...
Sorry, an error occurred while loading the content.

Stopping the repetition

Expand Messages
  • Colin Spear
    Hi Guys I have the XML and XSL below this message. They work fine together except for one small problem I can t seem to get past. The basic idea is that I
    Message 1 of 2 , Jul 11, 2006
    • 0 Attachment
      Hi Guys

      I have the XML and XSL below this message. They work fine together
      except for one small problem I can't seem to get past.
      The basic idea is that I should have a new table for each
      sales_person or church_code. The XML will *always* have the same
      sales_person and church_code grouped together, although I don't
      think this is all that relevant.
      My problem is that when it loops through it seems to create a new
      table for each group that has more than one row in it...so if I have
      a table with 2 rows in it, it creates the correct table twice and if
      I have a table with 3 rows in it it shows the correct table with 3
      rows but repeats it 3 times...I would like to put a test in to stop
      it from doing this but I am out of ideas on how to do this.

      Any help would be appreciated.

      XSL:
      <?xml version="1.0" encoding="utf-8"?>
      <xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
      xmlns:fo="http://www.w3.org/1999/XSL/Format"
      xmlns:java="http://xml.apache.org/xslt/java" exclude-result-
      prefixes="java" version="1.0">
      <xsl:decimal-format name="european" decimal-separator="."
      grouping-separator=" " NaN="N/A"/>
      <xsl:decimal-format name="zero" decimal-separator="."
      grouping-separator=" " NaN="0.00"/>
      <xsl:attribute-set name="font_styles">
      <xsl:attribute name="font-
      family">ArialNarrow</xsl:attribute>
      <xsl:attribute name="font-size">11pt</xsl:attribute>
      </xsl:attribute-set>
      <xsl:attribute-set name="font_style_2">
      <xsl:attribute name="font-size">7pt</xsl:attribute>
      <xsl:attribute name="font-
      family">ArialNarrow</xsl:attribute>
      <xsl:attribute name="line-height">80%</xsl:attribute>
      </xsl:attribute-set>
      <xsl:attribute-set name="fontStyleNormal">
      <xsl:attribute name="font-size">11pt</xsl:attribute>
      <xsl:attribute name="font-
      family">ArialNarrow</xsl:attribute>
      <xsl:attribute name="color">black</xsl:attribute>
      </xsl:attribute-set>
      <xsl:attribute-set name="fontStyleBold">
      <xsl:attribute name="font-size">11pt</xsl:attribute>
      <xsl:attribute name="font-
      family">ArialNarrow</xsl:attribute>
      <xsl:attribute name="color">black</xsl:attribute>
      <xsl:attribute name="font-
      weight">bold</xsl:attribute>
      </xsl:attribute-set>
      <xsl:variable name="lang">
      <xsl:choose>
      <xsl:when test="policy/absolute-cessionary-
      list/absolute-cessionary/language-id">
      <xsl:value-of select="number
      (policy/absolute-cessionary-list/absolute-cessionary/language-id)"/>
      </xsl:when>
      <xsl:otherwise>
      <xsl:value-of select="number
      (policy/owner-list/owner/language-id)"/>
      </xsl:otherwise>
      </xsl:choose>
      </xsl:variable>
      <xsl:variable name="ENGLISH">
      <xsl:value-of select="number(1)"/>
      </xsl:variable>
      <xsl:variable name="AFRIKAANS">
      <xsl:value-of select="number(2)"/>
      </xsl:variable>
      <xsl:variable name="nbsp"> </xsl:variable>
      <xsl:template match="/">
      <fo:root>
      <fo:layout-master-set>
      <fo:simple-page-master master-
      name="portrait" page-height="29.7cm" page-width="21cm">
      <fo:region-after
      extent="35mm" margin-left="20mm" margin-right="20mm"/>
      <fo:region-body margin-
      left="2cm" margin-bottom="2cm" margin-right="2cm"/>
      </fo:simple-page-master>
      <fo:simple-page-master master-
      name="landscape" page-height="21cm" page-width="29.7cm">
      <fo:region-after
      extent="35mm" margin-left="20mm" margin-right="20mm"/>
      <fo:region-body margin-
      left="2cm" margin-bottom="2cm" margin-top="30mm" margin-right="2cm"/>
      </fo:simple-page-master>
      </fo:layout-master-set>
      <fo:page-sequence master-
      reference="portrait">
      <fo:flow flow-name="xsl-region-body">
      <fo:block xsl:use-attribute-
      sets="fontStyleNormal" space-after.optimum="11pt">
      <xsl:call-template
      name="batchInvoice"/>
      </fo:block>
      </fo:flow>
      </fo:page-sequence>
      </fo:root>
      </xsl:template>
      <xsl:template name="batchInvoice">
      <xsl:for-each select="/snippet/invoice/row">
      <!--xsl:when test="generate-id(.)=generate-id
      (/snippet/invoice/row[sales_person=current()/sales_person])">
      <fo:block><xsl:value-
      of select="sales_person"/>BREAK</fo:block>

      </xsl:when-->
      <fo:table table-layout="fixed">
      <fo:table-column column-
      width="50mm"/>
      <fo:table-column column-
      width="50mm"/>
      <fo:table-header>
      <fo:table-row>
      <fo:table-cell
      background-color="silver">
      <fo:block
      font-weight="bold">Sales Person</fo:block>
      </fo:table-cell>
      <fo:table-cell
      background-color="silver">
      <fo:block
      font-weight="bold">Church</fo:block>
      </fo:table-cell>
      </fo:table-row>
      </fo:table-header>
      <fo:table-body>
      <xsl:for-each
      select="/snippet/invoice/row[sales_person=current()/sales_person and
      church_code=current()/church_code] ">
      <fo:table-row>
      <fo:table-
      cell>

      <fo:block>

      <xsl:value-of select="sales_person"/>

      </fo:block>
      </fo:table-
      cell>
      <fo:table-
      cell>

      <fo:block>

      <xsl:value-of select="church_code"/>::<xsl:value-of
      select="generate-id(.)"/>

      </fo:block>
      </fo:table-
      cell>
      </fo:table-row>
      </xsl:for-each>
      </fo:table-body>
      </fo:table>
      </xsl:for-each>
      </xsl:template>
      </xsl:stylesheet>



      XML:
      <?xml version="1.0" encoding="UTF-8"?>
      <snippet>
      <meta-info>
      <id>BatchReport</id>
      <version>1</version>
      <description>Batch Invoice</description>
      </meta-info>
      <date_invoiced>05-JUL-06</date_invoiced>
      <month_invoiced>05 JUL 2006</month_invoiced>
      <gsch_no>2800</gsch_no>
      <gsch_name>Darko Tst Bonang Two Ben</gsch_name>
      <policy>
      <planname>Family Funeral</planname>
      <discnumber>1000000002</discnumber>
      <policyholder>Employer</policyholder>
      </policy>
      <statementdate/>
      <invoice>
      <batch_invoice_no>34</batch_invoice_no>
      <batch_invoice_no>34</batch_invoice_no>
      <row>
      <sales_person>22</sales_person>
      <church_code>I</church_code>
      </row>
      <row>
      <sales_person>30</sales_person>
      <church_code>B</church_code>
      </row>
      <row>
      <sales_person>33</sales_person>
      <church_code>A</church_code>
      </row>
      <row>
      <sales_person>44</sales_person>
      <church_code>A</church_code>
      </row>
      <row>
      <sales_person>44</sales_person>
      <church_code>A</church_code>
      </row>
      <row>
      <sales_person>51</sales_person>
      <church_code>A</church_code>
      </row>
      <row>
      <sales_person>51</sales_person>
      <church_code>B</church_code>
      </row>
      <row>
      <sales_person>51</sales_person>
      <church_code>B</church_code>
      </row>
      <row>
      <sales_person>66</sales_person>
      <church_code>C</church_code>
      </row>
      <row>
      <sales_person>88</sales_person>
      <church_code>B</church_code>
      </row>
      <row>
      <sales_person>88</sales_person>
      <church_code>B</church_code>
      </row>
      <row>
      <sales_person>102</sales_person>
      <church_code>I</church_code>
      </row>
      <total/>
      </invoice>
      </snippet>
    • G. Ken Holman
      ... This is a classic grouping problem. Check out the following and if you have problems with the concepts, then post again:
      Message 2 of 2 , Jul 11, 2006
      • 0 Attachment
        At 2006-07-11 10:35 +0000, Colin Spear wrote:
        >My problem is that when it loops through it seems to create a new
        >table for each group that has more than one row in it...so if I have
        >a table with 2 rows in it, it creates the correct table twice and if
        >I have a table with 3 rows in it it shows the correct table with 3
        >rows but repeats it 3 times...I would like to put a test in to stop
        >it from doing this but I am out of ideas on how to do this.

        This is a classic grouping problem. Check out
        the following and if you have problems with the concepts, then post again:

        http://www.jenitennison.com/xslt/grouping/

        I hope this helps.

        . . . . . . . . . Ken

        --
        Registration open for UBL training: Montréal, Canada 2006-08-07
        Also for XSL-FO/XSLT training: Minneapolis, MN 2006-07-31/08-04
        Also for UBL/XML/XSLT/XSL-FO training: Varo,Denmark 06-09-25/10-06
        World-wide corporate, govt. & user group UBL, XSL, & XML training.
        G. Ken Holman mailto:gkholman@...
        Crane Softwrights Ltd. http://www.CraneSoftwrights.com/f/
        Box 266, Kars, Ontario CANADA K0A-2E0 +1(613)489-0999 (F:-0995)
        Male Cancer Awareness Aug'05 http://www.CraneSoftwrights.com/f/bc
        Legal business disclaimers: http://www.CraneSoftwrights.com/legal
      Your message has been successfully submitted and would be delivered to recipients shortly.