martin quensel - 2011-06-20

Hello all!

I had a lot of trouble getting printing to work, and also when i got it to work i did not like the result.
Since jdivelog stores in a xml file i created a xsl-fo file that can be used with "apache fop" for example to render divelogs in pdf format.
It is a bit "cludgy" right now, since it depends on the jpeg images of the downloaded logs. So you need to export to HTML format, and then in the xsl-fo file write the path to the export directory:

here it is, for your amusement.:

<?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" indent="yes"/>
  <xsl:template match="/">
  <fo:root>
    <fo:layout-master-set>
      <fo:simple-page-master 
    master-name="A4-portrait" 
    page-height="29.7cm" 
    page-width="21.0cm" margin="2cm">
    <fo:region-body/> 
      </fo:simple-page-master>
    </fo:layout-master-set>
    <xsl:apply-templates select="JDiveLog/JDive"/>
    </fo:root>
  </xsl:template>
  <xsl:template match="JDive">
    <!-- this is the per page template.. -->
    <fo:page-sequence master-reference="A4-portrait">
      <fo:flow flow-name="xsl-region-body">
      <fo:block>
        <fo:table table-layout="fixed" width="100%">
          <fo:table-column column-width="15mm"/>
          <fo:table-column column-width="130mm"/>
          <fo:table-column column-width="25mm"/>
          <fo:table-body>
        <fo:table-row> <!-- border-width="0.5mm" border-style="solid"> -->
          <fo:table-cell border-width="0.1mm" border-style="solid" padding="0.5mm">
            <fo:block font-size="8pt">Dive nr:</fo:block>
            <fo:block font-size="12pt"><xsl:value-of select="current()/DiveNum"/></fo:block>
          </fo:table-cell>
          <fo:table-cell border-width="0.1mm" border-style="solid" padding="0.5mm">
            <fo:block font-size="8pt">Divespot / Water / Town / Country </fo:block>
            <fo:block font-size="12pt">
               <xsl:variable name="di" select="current()/diveSiteId"/>
              <xsl:value-of select="/JDiveLog/Masterdata/DiveSites/DiveSite[privateId=$di]/spot"/> / 
              <xsl:value-of select="/JDiveLog/Masterdata/DiveSites/DiveSite[privateId=$di]/waters"/> /
              <xsl:value-of select="/JDiveLog/Masterdata/DiveSites/DiveSite[privateId=$di]/city"/> /
              <xsl:value-of select="/JDiveLog/Masterdata/DiveSites/DiveSite[privateId=$di]/country"/> 
            </fo:block>
          </fo:table-cell>
          <fo:table-cell border-width="0.1mm" border-style="solid" padding="0.5mm">
            <fo:block font-size="8pt">Date:</fo:block>
            <fo:block font-size="12pt"> 
              <xsl:value-of select="current()/DATE/YEAR"/>-<xsl:value-of select="format-number(current()/DATE/MONTH,'00')"/>-<xsl:value-of select="format-number(current()/DATE/DAY,'00')"/>
            </fo:block>
          </fo:table-cell>
        </fo:table-row>
          </fo:table-body>
        </fo:table>
      </fo:block>
      <!-- next table with info -->
      <fo:block>
        <fo:table table-layout="fixed" width="100%">
          <fo:table-column column-width="90mm"/>
          <fo:table-column column-width="16mm"/>
          <fo:table-column column-width="17mm"/>
          <fo:table-column column-width="22mm"/>
          <fo:table-column column-width="25mm"/>
          <fo:table-body>
        <fo:table-row>
          <fo:table-cell border-width="0.1mm" border-style="solid" padding="0.5mm">
            <fo:block font-size="8pt">Buddy/Buddies | Team members</fo:block>
            <fo:block font-size="12pt">
              <xsl:value-of select="current()/Buddy"/>
            </fo:block>
          </fo:table-cell>
          <fo:table-cell border-width="0.1mm" border-style="solid" padding="0.5mm">
            <fo:block font-size="8pt">Time:</fo:block>
            <fo:block font-size="12pt">
              <xsl:value-of select="format-number(current()/TIME/HOUR,'00')"/>:<xsl:value-of select="format-number(current()/TIME/MINUTE,'00')"/>
            </fo:block>
          </fo:table-cell>
          <fo:table-cell border-width="0.1mm" border-style="solid" padding="0.5mm">
            <fo:block font-size="8pt">Depth [m]:</fo:block>
            <fo:block font-size="12pt">
              <xsl:value-of select="current()/Depth"/>
            </fo:block>
          </fo:table-cell>
          <fo:table-cell border-width="0.1mm" border-style="solid" padding="0.5mm">
            <fo:block font-size="8pt">Avg Depth [m]:</fo:block>
            <fo:block font-size="12pt">
              <xsl:value-of select="current()/Average_Depth"/>
            </fo:block>
          </fo:table-cell>
          <fo:table-cell border-width="0.1mm" border-style="solid" padding="0.5mm">
            <fo:block font-size="8pt">Duration:</fo:block>
            <fo:block font-size="12pt">
              <!-- om detta kommer frn dykdatorn eller inte r viktigt. -->
              <xsl:choose>
               <xsl:when test="current()/DIVE">
                <xsl:value-of select="floor(current()/Duration div 60)"/>:<xsl:value-of select="floor(current()/Duration mod 60)"/>
               </xsl:when>
               <xsl:otherwise>
            <xsl:value-of select="current()/Duration"/>
               </xsl:otherwise>
              </xsl:choose>           
            </fo:block>
          </fo:table-cell>
        </fo:table-row>
          </fo:table-body>
        </fo:table>
      </fo:block>   
      <!-- last part of tableish surface.. here goes the picture and other stuff. -->
      <fo:block>
        <fo:table table-layout="fixed" width="100%">
          <fo:table-column column-width="106mm"/>
          <fo:table-column column-width="64mm"/>
          <fo:table-body>
        <fo:table-row>
          <fo:table-cell border-width="0.1mm" border-style="solid"> 
            <fo:block>
              <xsl:variable name="fp" select="concat('../exportlogs/org/exportlogs/public_html/',current()/DiveNum - 1,'/profile.jpg')"/>
              <fo:external-graphic src="{$fp}" content-height="50%" content-width="50%"/>
            </fo:block>
          </fo:table-cell>
          <fo:table-cell>
            <!-- we need a table inside here -->
            <fo:block>
              <fo:table table-layout="fixed" width="64mm">
            <fo:table-column column-width="100%"/>
            <fo:table-body>           
              <xsl:if test="current()/Equipment/Tanks/Tank/MIX/MIXNAME">
              <fo:table-row>
                <fo:table-cell border-width="0.1mm" border-style="solid" padding="0.5mm">
                  <fo:block font-size="8pt">GAS:</fo:block>
                  <fo:block font-size="12pt">
                <xsl:value-of select="current()/Equipment/Tanks/Tank/MIX/MIXNAME"/>
                  </fo:block>
                </fo:table-cell>
              </fo:table-row>
              </xsl:if>         
              <xsl:if test="normalize-space(current()/DiveType)">
              <fo:table-row>
                <fo:table-cell border-width="0.1mm" border-style="solid" padding="0.5mm">
                  <fo:block font-size="8pt">DIVE TYPE:</fo:block>
                  <fo:block font-size="12pt">
                <xsl:value-of select="current()/DiveType"/>
                  </fo:block>
                </fo:table-cell>
              </fo:table-row>
              </xsl:if>
              <xsl:if test="normalize-space(current()/DiveActivity)">
              <fo:table-row>
                <fo:table-cell border-width="0.1mm" border-style="solid" padding="0.5mm">
                  <fo:block font-size="8pt">DIVE ACTIVITY:</fo:block>
                  <fo:block font-size="12pt">
                <xsl:value-of select="current()/DiveActivity"/> 
                  </fo:block>
                </fo:table-cell>
              </fo:table-row>
              </xsl:if>           
              <!-- if visability has been added -->
              <xsl:if test="normalize-space(current()/Visibility)">
              <fo:table-row>
                <fo:table-cell border-width="0.1mm" border-style="solid" padding="0.5mm">
                  <fo:block font-size="8pt">Visibility:</fo:block>
                  <fo:block font-size="12pt">
                <xsl:value-of select="current()/Visibility"/>
                  </fo:block>
                </fo:table-cell>
              </fo:table-row>
              </xsl:if>
              <xsl:if test="normalize-space(current()/TEMPERATURE)">
              <fo:table-row>
                <fo:table-cell border-width="0.1mm" border-style="solid" padding="0.5mm">
                  <fo:block font-size="8pt">WATER TEMP [Celcius]:</fo:block>
                  <fo:block font-size="12pt">
                <xsl:if test="current()/TEMPERATURE &gt; '200'">
                  <xsl:value-of select="floor(current()/TEMPERATURE - 273)"/>
                </xsl:if>
                <xsl:if test="current()/TEMPERATURE &lt; '200'">
                  <xsl:value-of select="current()/TEMPERATURE"/>
                </xsl:if>
                  </fo:block>
                </fo:table-cell>
              </fo:table-row>
              </xsl:if>
            </fo:table-body>
              </fo:table>
            </fo:block>
          </fo:table-cell>
        </fo:table-row>
          </fo:table-body>
        </fo:table>
      </fo:block>
      <fo:block font-size="10pt">
      <xsl:value-of select="current()/Comment"/>
      </fo:block>
      </fo:flow>
    </fo:page-sequence>
  </xsl:template>
</xsl:stylesheet>