<?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"
	version="1.0">
	
<xsl:template match="/">

<fo:root xmlns:fo="http://www.w3.org/1999/XSL/Format">

  <fo:layout-master-set>
  <!-- fo:layout-master-set defines in its children the page layout: 
       the pagination and layout specifications
      - page-masters: have the role of describing the intended subdivisions 
                       of a page and the geometry of these subdivisions 
                      In this case there is only a simple-page-master which defines the 
                      layout for all pages of the text
  -->
    <!-- layout information -->
    <fo:simple-page-master master-name="simple"
                  page-height="29.7cm" 
                  page-width="21cm"
                  margin-top="2cm" 
                  margin-bottom="2cm" 
                  margin-left="2.5cm" 
                  margin-right="2.5cm">
      <fo:region-body margin-top="0cm"/>
      <fo:region-before extent="2cm"/>
      <fo:region-after extent="1.5cm"/>
    </fo:simple-page-master>
  </fo:layout-master-set>
  <!-- end: defines page layout -->

  <!-- start page-sequence
       here comes the text (contained in flow objects)
       the page-sequence can contain different fo:flows 
       the attribute value of master-name refers to the page layout
       which is to be used to layout the text contained in this
       page-sequence-->
  <fo:page-sequence master-reference="simple">

      <!-- start fo:flow
           each flow is targeted 
           at one (and only one) of the following:
           xsl-region-body (usually: normal text)
           xsl-region-before (usually: header)
           xsl-region-after  (usually: footer)
           xsl-region-start  (usually: left margin) 
           xsl-region-end    (usually: right margin)
           ['usually' applies here to languages with left-right and top-down 
            writing direction like English]
           in this case there is only one target: xsl-region-body
        -->
    <fo:flow flow-name="xsl-region-body">
      <xsl:apply-templates />
    </fo:flow> <!-- closes the flow element-->
  </fo:page-sequence> <!-- closes the page-sequence -->

</fo:root>

</xsl:template>

<!-- ###################################################################### -->
<!-- ### ZMSContainerObject                                                 -->
<!-- ###################################################################### -->
<xsl:template match="ZMS|ZMSRubrik|ZMSDocument">

  <!-- each paragraph is encapsulated in a block element
       the attributes of the block define
       font-family and size, line-heigth etc. -->

  <!-- this defines a heading_1-->
  <fo:block font-size="18pt" 
            font-family="sans-serif" 
            line-height="24pt"
            space-after.optimum="15pt"
            color="#000090"
            text-align="left"
            padding-top="3pt">
    <xsl:for-each select="title/lang">
      <xsl:apply-templates />
    </xsl:for-each>    
  </fo:block>

  <!-- Process child-nodes -->
  <xsl:apply-templates select="*[substring(name(),1,3)='ZMS']" />

</xsl:template>



<!-- ###################################################################### -->
<!-- ### ZMSTextarea                                                        -->
<!-- ###################################################################### -->
<xsl:template match="ZMSTextarea">

  <!-- each paragraph is encapsulated in a block element
       the attributes of the block define
       font-family and size, line-heigth etc. -->

  <xsl:choose>
    <xsl:when test="format='headline_1'">
      <!-- this defines a headline_1 -->
      <fo:block font-size="18pt" 
          font-family="sans-serif" 
          line-height="24pt"
          space-after.optimum="15pt"
          color="#000090"
          text-align="justify"
          padding-top="3pt">
        <xsl:for-each select="text/lang">
          <xsl:apply-templates />
        </xsl:for-each>
      </fo:block>
    </xsl:when>
    <xsl:when test="format='headline_2'">
      <!-- this defines a headline_2 -->
      <fo:block font-size="16pt" 
          font-family="sans-serif" 
          line-height="24pt"
          space-after.optimum="15pt"
          text-align="left"
          padding-top="3pt">
        <xsl:for-each select="text/lang">
          <xsl:apply-templates />
        </xsl:for-each>
      </fo:block>
    </xsl:when>
    <xsl:when test="format='headline_3'">
      <!-- this defines a headline_3 -->
      <fo:block font-size="16pt" 
          font-family="sans-serif" 
          font-style="italic"
          line-height="24pt"
          space-after.optimum="15pt"
          text-align="left"
          padding-top="3pt">
        <xsl:for-each select="text/lang">
          <xsl:apply-templates />
        </xsl:for-each>
      </fo:block>
    </xsl:when>
    <xsl:when test="format='headline_4'">
      <!-- this defines a headline_4 -->
      <fo:block font-size="14pt" 
          font-family="sans-serif" 
          line-height="18pt"
          space-after.optimum="15pt"
          text-align="left"
          padding-top="3pt">
        <xsl:for-each select="text/lang">
          <xsl:apply-templates />
        </xsl:for-each>
      </fo:block>
    </xsl:when>
    <xsl:when test="format='headline_5'">
      <!-- this defines a headline_5 -->
      <fo:block font-size="14pt" 
          font-family="sans-serif" 
          font-style="italic"
          line-height="18pt"
          space-after.optimum="15pt"
          text-align="left"
          padding-top="3pt">
        <xsl:for-each select="text/lang">
          <xsl:apply-templates />
        </xsl:for-each>
      </fo:block>
    </xsl:when>
    <xsl:when test="format='headline_6'">
      <!-- this defines a headline_6 -->
      <fo:block font-size="11pt" 
          font-family="sans-serif" 
          font-weight="bold"
          line-height="16pt"
          space-after.optimum="15pt"
          text-align="left"
          padding-top="3pt">
        <xsl:for-each select="text/lang">
          <xsl:apply-templates />
        </xsl:for-each>
      </fo:block>
    </xsl:when>
    <xsl:when test="format='caption'">
      <!-- this defines a caption -->
      <fo:block font-size="11pt" 
          font-family="sans-serif" 
          font-style="italic"
          line-height="14pt"
          space-after.optimum="15pt"
          text-align="center"
          padding-top="3pt">
        <xsl:for-each select="text/lang">
          <xsl:apply-templates />
        </xsl:for-each>
      </fo:block>
    </xsl:when>
    <xsl:otherwise>
      <!-- this defines a paragraph -->
      <fo:block font-size="11pt" 
          font-family="sans-serif" 
          line-height="14pt"
          space-after.optimum="15pt"
          text-align="justify"
          padding-top="3pt">
        <xsl:for-each select="text/lang">
          <xsl:apply-templates />
        </xsl:for-each>
      </fo:block>
    </xsl:otherwise>
  </xsl:choose>
    
</xsl:template>



<!-- ###################################################################### -->
<!-- ### ZMSGraphic                                                         -->
<!-- ###################################################################### -->
<xsl:template match="ZMSGraphic">

  <xsl:for-each select="img/lang/data">
    <fo:block text-align="center">
      <fo:external-graphic>
        <xsl:attribute name="src">
          file:<xsl:value-of select="@filename"/>
        </xsl:attribute>
      </fo:external-graphic>
    </fo:block>
  </xsl:for-each>

</xsl:template>


      
<!-- ###################################################################### -->
<!-- ### HTML-Tags                                                          -->
<!-- ###################################################################### -->

<!-- ====== -->
<!-- Anchor -->
<!-- ====== -->
<xsl:template match="a">
  <fo:basic-link>
    <xsl:attribute name="external-destination">
      <xsl:value-of select="@href"/>
    </xsl:attribute>
    <fo:inline color="#0000ff" text-decoration="underline">
      <xsl:apply-templates />    
    </fo:inline>
  </fo:basic-link>
</xsl:template>

<!-- ================== -->
<!-- Font.Style.Italics -->
<!-- ================== -->
<xsl:template match="i">
  <fo:inline font-style="italic">
    <xsl:apply-templates />
  </fo:inline>
</xsl:template>

<!-- ================ -->
<!-- Font.Weight.Bold -->
<!-- ================ -->
<xsl:template match="b">
  <fo:inline font-weight="bold">
    <xsl:apply-templates />
  </fo:inline>
</xsl:template>

<!-- ===== -->
<!-- Table -->
<!-- ===== -->
<xsl:template match="table">
  <fo:table border-collapse="separate">
    <fo:table-body>
      <xsl:apply-templates />
    </fo:table-body>
  </fo:table>
</xsl:template>

<!-- ========= -->
<!-- Table.Row -->
<!-- ========= -->
<xsl:template match="tr">
  <fo:table-row>
    <xsl:apply-templates />
  </fo:table-row>
</xsl:template>

<!-- ========== -->
<!-- Table.Data -->
<!-- ========== -->
<xsl:template match="td">
  <fo:table-cell>
    <fo:block font-size="11pt" 
        font-family="sans-serif" 
        line-height="14pt"
        space-after.optimum="15pt"
        text-align="justify"
        padding-top="3pt">
      <xsl:apply-templates />
    </fo:block>
  </fo:table-cell>
</xsl:template>

<!-- ============ -->
<!-- Table.Header -->
<!-- ============ -->
<xsl:template match="th">
  <fo:table-cell>
    <fo:block font-size="11pt" 
        font-family="sans-serif" 
        font-weight="bold"
        line-height="14pt"
        space-after.optimum="15pt"
        text-align="justify"
        padding-top="3pt">
      <xsl:apply-templates />
    </fo:block>
  </fo:table-cell>
</xsl:template>



</xsl:stylesheet>

