xsl-list
[Top] [All Lists]

Re: Different (body) layout on odd and even pages in XSL-FO?

2004-12-15 03:30:17
Hi again,

I think you need to post your stylesheet so that people out here can analyse and point the the problem.

here I have some simplified code for those interested in the problem. Using the code below I get the products listed twice, at first - all products with images to the left and then all product again with the images to the right (which make sense since I call the apply-template twice, using different modes). Is there any way that I can split upp the flow making half of the products "left-aligned" (odd pages) and the other half "right-aligned" (even pages).

A nice feature (not) in this code is also that it only renders odd-headers and on the last page it renders double odd headers??

Regards Christian


--------- products.xml ------------

<?xml version="1.0" encoding="UTF-8"?>
<products>
<product>
 <name>Product 1</name>
 <description>Description</description>
 <image>image1.jpg</image>
</product>
<product>
 <name>Product 2</name>
 <description>Description</description>
 <image>image2.jpg</image>
</product>
...
...
...
</products>


--------- products.xsl ------------

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

<xsl:output method="xml" version="1.0" encoding="utf-8" indent="yes"/>

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

  <!-- Master-set -->
  <fo:layout-master-set>
   <fo:page-sequence-master master-name="products">
    <fo:repeatable-page-master-alternatives>
<fo:conditional-page-master-reference master-reference="products-odd" odd-or-even="odd"/> <fo:conditional-page-master-reference master-reference="products-even" odd-or-even="even"/>
    </fo:repeatable-page-master-alternatives>
   </fo:page-sequence-master>
   <fo:simple-page-master master-name="products-odd">
    <fo:region-before extent='20mm' region-name="header-odd"/>
    <fo:region-body region-name="body-odd" margin="20mm"/>
    <fo:region-after extent='20mm' region-name="footer-odd"/>
   </fo:simple-page-master>
   <fo:simple-page-master master-name="products-even">
    <fo:region-before extent='20mm' region-name="header-even"/>
    <fo:region-body region-name="body-even" margin="20mm"/>
    <fo:region-after extent='20mm' region-name="footer-even"/>
   </fo:simple-page-master>
  </fo:layout-master-set>

  <!-- Products -->
  <fo:page-sequence master-reference="products">
   <fo:static-content flow-name="header-odd">
    <fo:block text-align="left">
     <xsl:text>Header odd</xsl:text>
    </fo:block>
   </fo:static-content>
   <fo:static-content flow-name="header-even">
    <fo:block text-align="right">
     <xsl:text>Header even</xsl:text>
    </fo:block>
   </fo:static-content>
   <fo:static-content flow-name="footer-odd">
    <fo:block text-align="left">
     <xsl:text>Footer odd</xsl:text>
    </fo:block>
   </fo:static-content>
   <fo:static-content flow-name="footer-even">
    <fo:block text-align="right">
     <xsl:text>Footer even</xsl:text>
    </fo:block>
   </fo:static-content>
   <fo:flow flow-name="body-odd">
    <fo:block>
     <xsl:apply-templates select="products/product" mode="odd"/>
    </fo:block>
   </fo:flow>
   <fo:flow flow-name="body-even">
    <fo:block>
     <xsl:apply-templates select="products/product" mode="even"/>
    </fo:block>
   </fo:flow>
  </fo:page-sequence>

 </fo:root>
</xsl:template>

<xsl:template match="products/product" mode="odd">
 <fo:block margin-top="20mm">
  <fo:table>
   <fo:table-body>
    <fo:table-row>
     <fo:table-cell width="30%">
      <fo:block>
<fo:external-graphic src="image" content-width="30mm" content-height="30mm"/>
      </fo:block>
     </fo:table-cell>
     <fo:table-cell width="70%">
      <fo:block>
       <xsl:value-of select="concat(name, ' - ', description)" />
      </fo:block>
     </fo:table-cell>
    </fo:table-row>
   </fo:table-body>
  </fo:table>
 </fo:block>
</xsl:template>

<xsl:template match="products/product" mode="even">
 <fo:block margin-top="20mm">
  <fo:table>
   <fo:table-body>
    <fo:table-row>
     <fo:table-cell width="70%">
      <fo:block>
       <xsl:value-of select="concat(name, ' - ', description)" />
      </fo:block>
     </fo:table-cell>
     <fo:table-cell width="30%">
      <fo:block>
<fo:external-graphic src="image" content-width="30mm" content-height="30mm"/>
      </fo:block>
     </fo:table-cell>
    </fo:table-row>
   </fo:table-body>
  </fo:table>
 </fo:block>
</xsl:template>

</xsl:stylesheet>

--~------------------------------------------------------------------
XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list
To unsubscribe, go to: http://lists.mulberrytech.com/xsl-list/
or e-mail: <mailto:xsl-list-unsubscribe(_at_)lists(_dot_)mulberrytech(_dot_)com>
--~--