You are viewing a plain text version of this content. The canonical link for it is here.
Posted to fop-users@xmlgraphics.apache.org by "Lee, Insoo" <In...@gs.com> on 2003/02/20 18:01:18 UTC

Writing efficient XSL

Could you please take a quick look at my XSL and see where I can improve
it?...
I know it's a very vague request, but I would appreciate any comments or
advice...
I can generate FO object relative quickly, but when generating 20 pages, it
takes about 5 minutes.. (Driver.run()) and I think my XSL is not efficiently
written..  I basically have one big table because I need to repeat column
headings.. people say I need to make smaller tables, but how would I do that
without counting lines to be on one page... (without relying on page header)
Thanks


<?xml version="1.0"?>
<xsl:stylesheet version="1.0"
  xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
  xmlns:fo="http://www.w3.org/1999/XSL/Format"> 

<xsl:attribute-set name="column-heading">
    <xsl:attribute name="font-family">Helvetica</xsl:attribute>
    <xsl:attribute name="font-weight">bold</xsl:attribute>
    <xsl:attribute name="font-size">8pt</xsl:attribute>
    <xsl:attribute name="text-align">left</xsl:attribute>
</xsl:attribute-set>

<xsl:attribute-set name="table-content">
    <xsl:attribute name="font-family">Helvetica</xsl:attribute>
    <xsl:attribute name="font-size">8pt</xsl:attribute>
</xsl:attribute-set>

<xsl:attribute-set name="table-content-right"> 
    <xsl:attribute name="font-family">Helvetica</xsl:attribute>
    <xsl:attribute name="font-size">8pt</xsl:attribute>
    <xsl:attribute name="text-align">right</xsl:attribute>
</xsl:attribute-set>

<xsl:attribute-set name="table-content-bold">
    <xsl:attribute name="font-family">Helvetica</xsl:attribute>
    <xsl:attribute name="font-weight">bold</xsl:attribute>
    <xsl:attribute name="font-size">8pt</xsl:attribute>
</xsl:attribute-set> 

<xsl:template match="/REPORT">
    <fo:root xmlns:fo="http://www.w3.org/1999/XSL/Format">

        <!-- START OF LAYOUT-MASTER-SET --> 
        <fo:layout-master-set>
            <fo:simple-page-master master-name="anypage"
                page-width="29.7cm"  
                page-height="21.0cm"
                margin-top="0.5cm"  
                margin-bottom="0.5cm"
                margin-left="1.5cm"
                margin-right="1.5cm">
                <fo:region-body
                    margin-top="0.5cm" 
                    margin-bottom="1.5cm"/>
                <fo:region-before
                    extent="0cm"/>
                <fo:region-after
                    extent="0.5cm"/>
            </fo:simple-page-master>
    
        </fo:layout-master-set>
            <!-- END OF LAYOUT-MASTER-SET -->

            <fo:page-sequence master-reference="anypage">

                <fo:flow flow-name="xsl-region-body">

                    <xsl:apply-templates select="REPORT_NAME"/>
                    <xsl:apply-templates select="CREATED_BY"/>

            <xsl:for-each select="FUND_GROUP">

                    <fo:table table-omit-header-at-break="false"
table-layout="fixed">

                    <fo:table-header>

                        <fo:table-row>
                            <fo:table-cell 
                                border-collapse="collapse" 
                                number-columns-spanned="11">

                            <fo:block font-size="12pt" text-align="left"
                                font-family="Helvetica"
                                space-after="0pt" font-weight="bold">
                                <xsl:choose>
                                    <xsl:when test="@STATUS!='Single'">
                                        <xsl:value-of select="@STATUS"/>
 
<xsl:text>&#160;</xsl:text><xsl:value-of select="@CURRENCY"/> Funds
                                    </xsl:when>
                                    <xsl:otherwise> 
                                        Single Fund Report
                                    </xsl:otherwise>
                                </xsl:choose>
                            </fo:block>
                            </fo:table-cell>
                        </fo:table-row>

                        <fo:table-row>
                            <fo:table-cell 
                                border-collapse="collapse"
                                space-before="0pt"
                                number-columns-spanned="11">
                               <fo:block>
                                    <fo:leader leader-length="100%"
leader-pattern="rule"/>
                               </fo:block>
                            </fo:table-cell>
                        </fo:table-row>

                        <fo:table-row>
                            <fo:table-cell display-align="center">
                                <fo:block
xsl:use-attribute-sets="column-heading">
                                    Fund
                                </fo:block>
                            </fo:table-cell>

                            <fo:table-cell display-align="center"
                                           number-columns-spanned="2">
                                <fo:block
xsl:use-attribute-sets="column-heading">
                                    Date
                                </fo:block>
                            </fo:table-cell>

                            <fo:table-cell display-align="center">
                                <fo:block
xsl:use-attribute-sets="column-heading">
                                    Daily Factor
                                </fo:block>
                            </fo:table-cell>

                     <fo:table-cell display-align="center"
                                           number-columns-spanned="2">
                                <fo:block
xsl:use-attribute-sets="column-heading">
                                    1-Day Yield (365 Day Rate)
                                </fo:block>

                                <fo:block
xsl:use-attribute-sets="column-heading">
                                    <fo:leader leader-length="85%"
leader-pattern="rule"/>
                                </fo:block>

                                <fo:block
xsl:use-attribute-sets="column-heading">
                                    Short
 
<xsl:text>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;
&#160;&#160;&#160;&#160;&#160;&#160;&#160;</xsl:text>
                                    Long
                                </fo:block>
                            </fo:table-cell>

                            <fo:table-cell display-align="center">
                                <fo:block
xsl:use-attribute-sets="column-heading">
                                    360 Day
                                </fo:block>
                                <fo:block
xsl:use-attribute-sets="column-heading">
                                    Rates
                                </fo:block>

                            </fo:table-cell>

                            <fo:table-cell display-align="center">
                                <fo:block
xsl:use-attribute-sets="column-heading">
                                    7-Day
                                </fo:block> 
                                <fo:block
xsl:use-attribute-sets="column-heading">
                                    Current
                                </fo:block> 
                                <fo:block
xsl:use-attribute-sets="column-heading">
                                    Yield
                                </fo:block>

                            </fo:table-cell>

                            <fo:table-cell display-align="center">
                                <fo:block
xsl:use-attribute-sets="column-heading">
                                    7-Day
                                </fo:block>
                                <fo:block
xsl:use-attribute-sets="column-heading">
                                    Effective
                                </fo:block> 
                                <fo:block
xsl:use-attribute-sets="column-heading">
                                    Yield
                                </fo:block> 
                            </fo:table-cell>

                            <fo:table-cell display-align="center">
                                <fo:block
xsl:use-attribute-sets="column-heading">
                                    30-Day
                                </fo:block>
                                <fo:block
xsl:use-attribute-sets="column-heading">
                                    Yield
                                </fo:block>
                            </fo:table-cell>

                            <fo:table-cell display-align="center">
                                <fo:block
xsl:use-attribute-sets="column-heading">
                                    NAV<fo:inline vertical-align="super"
font-size="8pt">1</fo:inline>
                                </fo:block>
                                <fo:block
xsl:use-attribute-sets="column-heading">
                                    (<xsl:value-of select="@CURRENCY"/>)
                                </fo:block>
                            </fo:table-cell>
                    </fo:table-row>

                        <fo:table-row>
                            <fo:table-cell
                                border-collapse="collapse"
                                number-columns-spanned="11"
                                display-align="before">
                               <fo:block space-before="0pt">
                                    <fo:leader leader-length="100%"
leader-pattern="rule"/>
                               </fo:block>
                            </fo:table-cell>
                        </fo:table-row>

            </fo:table-header>

            <fo:table-column column-width="70mm"/>
            <fo:table-column column-width="18mm"/>
            <fo:table-column column-width="5mm"/>
            <fo:table-column column-width="35mm"/>
            <fo:table-column column-width="23mm"/>
            <fo:table-column column-width="19mm"/>
            <fo:table-column column-width="17mm"/>
            <fo:table-column column-width="17mm"/>
            <fo:table-column column-width="17mm"/>
            <fo:table-column column-width="17mm"/>
            <fo:table-column column-width="19mm"/>

            <fo:table-body>
                <xsl:call-template name="FUND_GROUP_ROWS"/>
            </fo:table-body>

        </fo:table>
        </xsl:for-each>
        <!-- End of TALBE 1 : Active EUR -->


            <xsl:apply-templates select="DISCLAIMER"/>

        </fo:flow>

      </fo:page-sequence>

    </fo:root>

  </xsl:template>
  <!-- END OF template REPORT -->


 <xsl:template match="REPORT_NAME">
    <fo:block border-style="solid"
             border-width=".6mm"
             text-align="center"
             font-family="Helvetica"
             space-after.optimum="5pt"
             padding-top="5pt"
             line-height="20pt">

       <fo:block font-size="16pt"
                font-weight="bold"
            space-after.minimum="2pt">
         <xsl:value-of select="."/>
        </fo:block>

        <fo:block font-size="9pt"
            space-before.minimum="0pt">
         <xsl:value-of select="/REPORT/DATE_RANGE"/>
       </fo:block>

    </fo:block>
 </xsl:template>

 <xsl:template match="CREATED_BY">
    <fo:block font-family="Helvetica"
            font-size="9pt" text-align="right" space-after.optimum="10pt">
         Created by <xsl:value-of select="."/>
         on <xsl:value-of select="/REPORT/CREATED_DATE_AND_TIME"/>
    </fo:block>
 </xsl:template>



  <xsl:template name="FUND_GROUP_ROWS">

      <xsl:for-each select="FUND_ROW">

    <!-- this is just to create a empty line between funds -->
      <xsl:for-each select="TA_FUND_CODE">
    <xsl:choose>
        <xsl:when test=".=../preceding-sibling::FUND_ROW[1]/TA_FUND_CODE">
        </xsl:when>
        <xsl:otherwise>
            <fo:table-row>
                <fo:table-cell
                    border-collapse="collapse"
                    number-columns-spanned="11"
                    display-align="before">
                    <fo:block>
                        <xsl:text>&#160;</xsl:text>
                    </fo:block>
                </fo:table-cell>
            </fo:table-row>
        </xsl:otherwise>
    </xsl:choose>
    </xsl:for-each>

    <fo:table-row>

      <xsl:for-each select="TA_FUND_CODE">
      <fo:table-cell>
        <xsl:choose>
            <xsl:when
test=".=../preceding-sibling::FUND_ROW[1]/TA_FUND_CODE">
            </xsl:when>
            <xsl:otherwise>

                <fo:block xsl:use-attribute-sets="table-content-bold">
                    <xsl:value-of select="../LONG_NAME"/> -
                    <xsl:value-of select="."/>
                </fo:block>

            </xsl:otherwise>
        </xsl:choose>
      </fo:table-cell>
      </xsl:for-each>

      <fo:table-cell>
        <fo:block xsl:use-attribute-sets="table-content-right">
            <xsl:value-of select="RATE_DATE"/>
        </fo:block>
      </fo:table-cell>

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

      <fo:table-cell>
        <fo:block xsl:use-attribute-sets="table-content">
          <xsl:value-of select="DAILY_FACTOR"/>
        </fo:block>
      </fo:table-cell>
      <fo:table-cell>
        <fo:block xsl:use-attribute-sets="table-content">
          <xsl:value-of select="SHORT_RATE_365"/>
        </fo:block>
      </fo:table-cell>
      <fo:table-cell>
        <fo:block xsl:use-attribute-sets="table-content">
          <xsl:value-of select="LONG_RATE_365"/>
        </fo:block>
      </fo:table-cell>
      <fo:table-cell>
        <fo:block xsl:use-attribute-sets="table-content">
            <xsl:value-of select="RATE_360"/>
        </fo:block>
      </fo:table-cell>
      <fo:table-cell>
        <fo:block xsl:use-attribute-sets="table-content">
          <xsl:value-of select="CURR_7_DAY_YIELD"/>
        </fo:block>
      </fo:table-cell>
      <fo:table-cell>
        <fo:block xsl:use-attribute-sets="table-content">
          <xsl:value-of select="SEVEN_DAY_EFF_YIELD"/>
        </fo:block>
      </fo:table-cell>

    <fo:table-cell>
        <fo:block xsl:use-attribute-sets="table-content">
          <xsl:value-of select="AVG_30_DAY_RATE"/>
        </fo:block>
      </fo:table-cell>
      <fo:table-cell>
        <fo:block xsl:use-attribute-sets="table-content">
          <xsl:value-of select="PRICE"/>
        </fo:block>
      </fo:table-cell>
    </fo:table-row>

    </xsl:for-each>
  </xsl:template>
  <!-- ROW_ACTIVE_EUR -->

 <xsl:template match="DISCLAIMER">
    <fo:block font-size="10pt" space-before="3cm">
    <fo:inline vertical-align="super" font-size="8pt">+</fo:inline>
        The investment return and principal value of an investment in a Fund
        will fluctuate and, therefore, an investor's shares when redeemed,
may be worth
        more or less than their original cost. Past performance is no
guarantee of future
        results which will fluctuate as market conditions change.
    </fo:block>

 </xsl:template>

</xsl:stylesheet>



---------------------------------------------------------------------
To unsubscribe, e-mail: fop-user-unsubscribe@xml.apache.org
For additional commands, e-mail: fop-user-help@xml.apache.org


Re: Writing efficient XSL

Posted by "J.Pietschmann" <j3...@yahoo.de>.
Lee, Insoo wrote:
> I basically have one big table because I need to repeat column
> headings.. 
Have you checked whether you can put the repeating header into
the static-content of the region-before?

 > I can generate FO object relative quickly, but when generating 20 pages, it
 > takes about 5 minutes.. (Driver.run())
Depending on your environment, this is not necessarily a bad time.

J.Pietschmann



---------------------------------------------------------------------
To unsubscribe, e-mail: fop-user-unsubscribe@xml.apache.org
For additional commands, e-mail: fop-user-help@xml.apache.org