<?xml version='1.0' encoding='ISO-8859-1'?>

<!-- =============================================================== -->
<!--                                                                 -->
<!-- Conversion of XSL FO from WD 1999-04-21 to CR 2000-11-21.       -->
<!-- This stylesheet tries to convert XSL FO documents; its proper   -->
<!-- operation on stylesheets is not guaranteed. In particular,      -->
<!-- heuristics for determining the missing fo:list-item are loose.  -->
<!--                                                                 -->
<!-- (c) RenderX, 2000                                               -->
<!--                                                                 -->
<!-- =============================================================== -->

<xsl:stylesheet version="1.0"
                xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
                xmlns:fo="http://www.w3.org/1999/XSL/Format"
                xmlns:oldfo="http://www.w3.org/XSL/Format/1.0"
                xmlns:oldrx="http://www.renderx.com/XSL/Extensions"
                exclude-result-prefixes="oldfo oldrx">

<xsl:output method="xml"
            version="1.0"
            indent="no"
            encoding="utf-8"
            doctype-system="fo.dtd"/>

<!-- =============================================================== -->
<!-- Default rule to copy everything through                         -->
<!-- This should help to handle stylesheets.                         -->
<!-- =============================================================== -->

<xsl:template match="@*|*|text()|comment()" priority="-1">
  <xsl:copy>
    <xsl:apply-templates select="@*|*|text()|comment()"/>
  </xsl:copy>
</xsl:template>


<!-- =============================================================== -->
<!-- Convert sequence specifiers to page sequence masters            -->
<!-- =============================================================== -->

<xsl:template match="oldfo:layout-master-set">
  <fo:layout-master-set>
    <xsl:apply-templates select="@*|*|text()|comment()"/>
    <xsl:apply-templates select="/descendant::oldfo:sequence-specification" mode="master"/>
  </fo:layout-master-set>
</xsl:template>

<xsl:template match="oldfo:sequence-specification"/>

<xsl:template match="oldfo:sequence-specification" mode="master">
  <fo:page-sequence-master master-name="{generate-id()}">
    <xsl:apply-templates select="*|text()|comment()"/>
  </fo:page-sequence-master>
</xsl:template>

<xsl:template match="oldfo:simple-page-master">
  <fo:simple-page-master>
    <xsl:apply-templates select="@*|*|text()|comment()"/>
  </fo:simple-page-master>
</xsl:template>

<xsl:template match="oldfo:page-sequence">
  <fo:page-sequence master-name="{generate-id(oldfo:sequence-specification)}">
    <xsl:apply-templates select="@*|*|text()|comment()"/>
  </fo:page-sequence>
</xsl:template>

<xsl:template match="oldfo:region-body">
  <fo:region-body><xsl:apply-templates select="@*"/></fo:region-body>
</xsl:template>

<xsl:template match="oldfo:region-before">
  <fo:region-before><xsl:apply-templates select="@*"/></fo:region-before>
</xsl:template>

<xsl:template match="oldfo:region-after">
  <fo:region-after><xsl:apply-templates select="@*"/></fo:region-after>
</xsl:template>

<xsl:template match="oldfo:region-start">
  <fo:region-start><xsl:apply-templates select="@*"/></fo:region-start>
</xsl:template>

<xsl:template match="oldfo:region-end">
  <fo:region-end><xsl:apply-templates select="@*"/></fo:region-end>
</xsl:template>

<xsl:template match="oldfo:sequence-specifier-single">
  <fo:single-page-master-reference master-name="{@page-master-name}"/>
</xsl:template>

<xsl:template match="oldfo:sequence-specifier-repeating">
  <xsl:if test="@page-master-first 
                and not (@page-master-first=@page-master-repeating)">
    <fo:single-page-master-reference master-name="{@page-master-first}"/>
  </xsl:if>
  <fo:repeatable-page-master-reference master-name="{@page-master-repeating}"/>
</xsl:template>

<xsl:template match="oldfo:sequence-specifier-alternating">
  <xsl:if test="@page-master-first 
                and not (@page-master-first=@page-master-odd)">
    <fo:single-page-master-reference master-name="{@page-master-first}"/>
  </xsl:if>
  <fo:repeatable-page-master-alternatives>
    <xsl:if test="@page-master-last-odd 
                  and not (@page-master-last-odd=@page-master-odd)">
      <fo:conditional-page-master-reference master-name="{@page-master-last-odd}"
                                            odd-or-even="odd"
                                            page-position="last"/>
    </xsl:if>
    <xsl:if test="@page-master-last-even 
                  and not (@page-master-last-even=@page-master-even)">
      <fo:conditional-page-master-reference master-name="{@page-master-last-even}"
                                            odd-or-even="even"
                                            page-position="last"/>
    </xsl:if>
    <xsl:if test="@page-master-blank-even 
                  and not (@page-master-blank-even=@page-master-even)">
      <fo:conditional-page-master-reference master-name="{@page-master-last-even}"
                                            odd-or-even="even"
                                            blank-or-not-blank="blank"/>
    </xsl:if>
    <fo:conditional-page-master-reference master-name="{@page-master-odd}"
                                          odd-or-even="odd"/>
    <fo:conditional-page-master-reference master-name="{@page-master-even}"
                                          odd-or-even="even"/>
  </fo:repeatable-page-master-alternatives>
</xsl:template>


<!-- =============================================================== -->
<!-- Create missing fo:list-items                                    -->
<!-- =============================================================== -->

<xsl:template match="oldfo:list-block/oldfo:list-item-label">
  <fo:list-item>
    <xsl:apply-templates select="../@space-between-list-rows.minimum" mode="list-row-space"/>
    <xsl:apply-templates select="../@space-between-list-rows.optimum" mode="list-row-space"/>
    <xsl:apply-templates select="../@space-between-list-rows.maximum" mode="list-row-space"/>
    <xsl:apply-templates select="../@space-between-list-rows.precedence" mode="list-row-space"/>
    <xsl:apply-templates select="../@space-between-list-rows.conditionality" mode="list-row-space"/>
    <fo:list-item-label>
      <xsl:if test="not(@end-indent)">
        <xsl:attribute name="end-indent">label-end()</xsl:attribute>
      </xsl:if>
      <xsl:apply-templates select="@*|*|text()|comment()"/>
    </fo:list-item-label>

    <xsl:apply-templates mode="draw-body" 
         select="following-sibling::oldfo:list-item-body[1]"/>
  </fo:list-item>
</xsl:template>

<xsl:template match="oldfo:list-block/oldfo:list-item-body"/>

<xsl:template mode="draw-body"
     match="oldfo:list-block/oldfo:list-item-body">
  <fo:list-item-body>
    <xsl:if test="not(@start-indent)">
      <xsl:attribute name="start-indent">body-start()</xsl:attribute>
    </xsl:if>
    <xsl:apply-templates select="@*|*|text()|comment()"/>
  </fo:list-item-body>
</xsl:template>


<!-- =============================================================== -->
<!-- Rearrange fo:footnote stuff                                     -->
<!-- =============================================================== -->

<xsl:template match="oldfo:footnote">
  <fo:footnote>
    <xsl:apply-templates select="oldfo:footnote-citation"/>
    <fo:footnote-body>
      <xsl:apply-templates select="@*|text()|comment()| 
                                   *[not(self::oldfo:footnote-citation)]"/>
    </fo:footnote-body>
  </fo:footnote>
</xsl:template>

<xsl:template match="oldfo:footnote-citation">
  <fo:inline>
    <xsl:apply-templates select="@*|*|text()|comment()"/>
  </fo:inline>
</xsl:template>

<!-- =============================================================== -->
<!-- Convert block-level images to inline elements                   -->
<!-- =============================================================== -->

<xsl:template match="oldfo:display-graphic">
  <fo:block>
    <xsl:apply-templates select="@text-align | @span |
                                 @position | @left | @right | @top | @bottom |
                                 @keep-with-next | @keep-with-previous | 
                                 @break-before | @break-after"/>
    <fo:external-graphic>
      <xsl:apply-templates select="@* [name() != 'text-align'
                                   and name() != 'span'
                                   and name() != 'position'
                                   and name() != 'left' 
                                   and name() != 'right' 
                                   and name() != 'top'
                                   and name() != 'bottom'
                                   and name() != 'keep-with-next'
                                   and name() != 'keep-with-previous'
                                   and name() != 'break-before'
                                   and name() != 'break-after']"/>
    </fo:external-graphic>
  </fo:block>
</xsl:template>


<!-- =============================================================== -->
<!-- Convert horizontal block-level rules to leaders                 -->
<!-- =============================================================== -->

<xsl:template match="oldfo:display-rule">
  <fo:block>
    <xsl:apply-templates select="@text-align | @span |
                                 @position | @left | @right | @top | @bottom |
                                 @keep-with-next | @keep-with-previous | 
                                 @break-before | @break-after"/>
    <fo:leader leader-pattern="rule">
      <xsl:apply-templates select="@* [name() != 'text-align'
                                   and name() != 'span'
                                   and name() != 'position'
                                   and name() != 'left' 
                                   and name() != 'right' 
                                   and name() != 'top'
                                   and name() != 'bottom'
                                   and name() != 'keep-with-next'
                                   and name() != 'keep-with-previous'
                                   and name() != 'break-before'
                                   and name() != 'break-after']"/>
    </fo:leader>
  </fo:block>
</xsl:template>

<!-- =============================================================== -->
<!-- Suppress vertical rules                                         -->
<!-- =============================================================== -->

<xsl:template match="oldfo:display-rule[@rule-orientation='vertical' 
                                     or @rule-orientation='line-progression']"
              priority="2">
  <fo:block/>
</xsl:template>

<xsl:template match="oldfo:inline-rule[@rule-orientation='vertical' 
                                    or @rule-orientation='line-progression']"
              priority="2"/>



<!-- =============================================================== -->
<!-- Rename some elements                                            -->
<!-- =============================================================== -->

<xsl:template match="oldfo:display-included-container">
  <fo:block-container>
    <xsl:apply-templates select="@*|*|text()|comment()"/>
  </fo:block-container>
</xsl:template>

<xsl:template match="oldfo:inline-included-container">
  <fo:inline-container>
    <xsl:apply-templates select="@*|*|text()|comment()"/>
  </fo:inline-container>
</xsl:template>

<xsl:template match="oldfo:display-sequence">
  <fo:wrapper><xsl:apply-templates select="@*|*|text()|comment()"/></fo:wrapper>
</xsl:template>

<!-- If an inline-sequence contains block-level children, -->
<!-- make it a fo:wrapper; otherwise, an fo:inline        -->
<xsl:template priority="2"
     match="oldfo:inline-sequence[oldfo:block
                               or oldfo:display-sequence
                               or oldfo:display-graphic
                               or oldfo:display-rule
                               or oldfo:display-included-container
                               or oldfo:list-block
                               or oldfo:table-and-caption
                               or oldfo:table
                               or oldfo:multi-switch
                               or oldfo:multi-properties]">
  <fo:wrapper><xsl:apply-templates select="@*|*|text()|comment()"/></fo:wrapper>
</xsl:template>

<xsl:template match="oldfo:inline-sequence | oldrx:inline-span">
  <fo:inline><xsl:apply-templates select="@*|*|text()|comment()"/></fo:inline>
</xsl:template>

<xsl:template match="oldfo:inline-graphic">
  <fo:external-graphic>
    <xsl:apply-templates select="@*"/>
  </fo:external-graphic>
</xsl:template>

<xsl:template match="oldfo:inline-rule">
  <fo:leader leader-pattern="rule">
    <xsl:apply-templates select="@*"/>
  </fo:leader>
</xsl:template>

<xsl:template match="oldfo:first-line-marker">
  <fo:initial-property-set>
    <xsl:apply-templates select="@*"/>
  </fo:initial-property-set>
</xsl:template>


<!-- =============================================================== -->
<!-- All other templates just change namespace                       -->
<!-- =============================================================== -->

<xsl:template match="oldfo:root">
  <fo:root><xsl:apply-templates select="@*|*|text()|comment()"/></fo:root>
</xsl:template>

<xsl:template match="oldfo:flow">
  <fo:flow><xsl:apply-templates select="@*|*|text()|comment()"/></fo:flow>
</xsl:template>

<xsl:template match="oldfo:static-content">
  <fo:static-content><xsl:apply-templates select="@*|*|text()|comment()"/></fo:static-content>
</xsl:template>

<xsl:template match="oldfo:block">
  <fo:block><xsl:apply-templates select="@*|*|text()|comment()"/></fo:block>
</xsl:template>

<xsl:template match="oldfo:bidi-override">
  <fo:bidi-override><xsl:apply-templates select="@*|*|text()|comment()"/></fo:bidi-override>
</xsl:template>

<xsl:template match="oldfo:character">
  <fo:character><xsl:apply-templates select="@*"/></fo:character>
</xsl:template>

<xsl:template match="oldfo:page-number">
  <fo:page-number><xsl:apply-templates select="@*"/></fo:page-number>
</xsl:template>

<xsl:template match="oldfo:page-number-citation">
  <fo:page-number-citation><xsl:apply-templates select="@*"/></fo:page-number-citation>
</xsl:template>

<xsl:template match="oldfo:table-and-caption">
  <fo:table-and-caption><xsl:apply-templates select="@*|*|text()|comment()"/></fo:table-and-caption>
</xsl:template>

<xsl:template match="oldfo:table">
  <fo:table><xsl:apply-templates select="@*|*|text()|comment()"/></fo:table>
</xsl:template>

<xsl:template match="oldfo:table-caption">
  <fo:table-caption><xsl:apply-templates select="@*|*|text()|comment()"/></fo:table-caption>
</xsl:template>

<xsl:template match="oldfo:table-column">
  <fo:table-column><xsl:apply-templates select="@*"/></fo:table-column>
</xsl:template>

<xsl:template match="oldfo:table-header">
  <fo:table-header><xsl:apply-templates select="@*|*|text()|comment()"/></fo:table-header>
</xsl:template>

<xsl:template match="oldfo:table-footer">
  <fo:table-footer><xsl:apply-templates select="@*|*|text()|comment()"/></fo:table-footer>
</xsl:template>

<xsl:template match="oldfo:table-body">
  <fo:table-body><xsl:apply-templates select="@*|*|text()|comment()"/></fo:table-body>
</xsl:template>

<xsl:template match="oldfo:table-row">
  <fo:table-row><xsl:apply-templates select="@*|*|text()|comment()"/></fo:table-row>
</xsl:template>

<xsl:template match="oldfo:table-cell">
  <fo:table-cell><xsl:apply-templates select="@*|*|text()|comment()"/></fo:table-cell>
</xsl:template>

<xsl:template match="oldfo:list-block">
  <fo:list-block><xsl:apply-templates select="@*|*|text()|comment()"/></fo:list-block>
</xsl:template>

<xsl:template match="oldfo:list-item">
  <xsl:apply-templates select="../@space-between-list-rows.minimum" mode="list-row-space"/>
  <xsl:apply-templates select="../@space-between-list-rows.optimum" mode="list-row-space"/>
  <xsl:apply-templates select="../@space-between-list-rows.maximum" mode="list-row-space"/>
  <xsl:apply-templates select="../@space-between-list-rows.precedence" mode="list-row-space"/>
  <xsl:apply-templates select="../@space-between-list-rows.conditionality" mode="list-row-space"/>
  <fo:list-item><xsl:apply-templates select="@*|*|text()|comment()"/></fo:list-item>
</xsl:template>

<xsl:template match="oldfo:list-item/oldfo:list-item-label">
  <fo:list-item-label>
    <xsl:if test="not(@end-indent)">
      <xsl:attribute name="end-indent">label-end()</xsl:attribute>
    </xsl:if>
    <xsl:apply-templates select="@*|*|text()|comment()"/>
  </fo:list-item-label>
</xsl:template>

<xsl:template match="oldfo:list-item/oldfo:list-item-body">
  <fo:list-item-body>
    <xsl:if test="not(@start-indent)">
      <xsl:attribute name="start-indent">body-start()</xsl:attribute>
    </xsl:if>
    <xsl:apply-templates select="@*|*|text()|comment()"/>
  </fo:list-item-body>
</xsl:template>

<xsl:template match="oldfo:simple-link">
  <fo:basic-link><xsl:apply-templates select="@*|*|text()|comment()"/></fo:basic-link>
</xsl:template>

<xsl:template match="oldfo:multi-switch">
  <fo:multi-switch><xsl:apply-templates select="@*|*|text()|comment()"/></fo:multi-switch>
</xsl:template>

<xsl:template match="oldfo:multi-case">
  <fo:multi-case><xsl:apply-templates select="@*|*|text()|comment()"/></fo:multi-case>
</xsl:template>

<xsl:template match="oldfo:multi-toggle">
  <fo:multi-toggle><xsl:apply-templates select="@*|*|text()|comment()"/></fo:multi-toggle>
</xsl:template>

<xsl:template match="oldfo:multi-properties">
  <fo:multi-properties><xsl:apply-templates select="@*|*|text()|comment()"/></fo:multi-properties>
</xsl:template>

<xsl:template match="oldfo:multi-property-set">
  <fo:multi-property-set><xsl:apply-templates select="@*|*|text()|comment()"/></fo:multi-property-set>
</xsl:template>

<xsl:template match="oldfo:float">
  <fo:float><xsl:apply-templates select="@*|*|text()|comment()"/></fo:float>
</xsl:template>


<!-- *************************************************************** -->
<!--                                                                 -->
<!-- Processing attributes                                           -->
<!--                                                                 -->
<!-- *************************************************************** -->

<!-- =============================================================== -->
<!-- Page master name                                                -->
<!-- =============================================================== -->

<xsl:template match="oldfo:simple-page-master/@page-master-name">
  <xsl:attribute name="master-name">
    <xsl:value-of select="."/>
  </xsl:attribute>
</xsl:template>

<!-- =============================================================== -->
<!-- Suppress margins on side regions                                -->
<!-- =============================================================== -->

<xsl:template match="@*[starts-with(name(), 'margin')]
                       [parent::oldfo:region-before 
                        or parent::oldfo:region-after
                        or parent::oldfo:region-start
                        or parent::oldfo:region-end]">
  <xsl:message>
    WARNING: suppressed attribute &apos;<xsl:value-of select="name()"/>&apos; on element fo:<xsl:value-of select="local-name(..)"/>
  </xsl:message>
</xsl:template>


<!-- =============================================================== -->
<!-- Position                                                        -->
<!-- =============================================================== -->

<xsl:template match="@position[.='absolute' or .='fixed']">
  <xsl:attribute name="absolute-position">
    <xsl:value-of select="."/>
  </xsl:attribute>
</xsl:template>

<xsl:template match="@position[.='static' or .='relative']">
  <xsl:attribute name="relative-position">
    <xsl:value-of select="."/>
  </xsl:attribute>
</xsl:template>


<!-- =============================================================== -->
<!-- Reference-orientation: add units (degrees)                      -->
<!-- =============================================================== -->

<xsl:template match="@reference-orientation">
  <xsl:attribute name="reference-orientation">
    <xsl:value-of select="concat(., 'deg')"/>
  </xsl:attribute>
</xsl:template>


<!-- =============================================================== -->
<!-- Add url('') around URLs                                         -->
<!-- =============================================================== -->

<xsl:template match="@href">
  <xsl:attribute name="src">
    <xsl:call-template name="add-url-brackets"/>
  </xsl:attribute>
</xsl:template>

<xsl:template match="@background-image">
  <xsl:attribute name="background-image">
    <xsl:call-template name="add-url-brackets"/>
  </xsl:attribute>
</xsl:template>

<xsl:template match="@external-destination">
  <xsl:attribute name="external-destination">
    <xsl:call-template name="add-url-brackets"/>
  </xsl:attribute>
</xsl:template>

<xsl:template name="add-url-brackets">
  <xsl:variable name="url-text" select="normalize-space(.)"/>
  <xsl:choose>
    <xsl:when test="starts-with($url-text, 'url(') or starts-with($url-text, 'url (')">
      <xsl:value-of select="$url-text"/>
    </xsl:when>
    <xsl:otherwise>
      <xsl:value-of select="concat('url(', $url-text, ')')"/>
    </xsl:otherwise>
  </xsl:choose>
</xsl:template>


<!-- =============================================================== -->
<!-- Flow names                                                      -->
<!-- =============================================================== -->

<xsl:template match="@flow-name">
  <xsl:attribute name="flow-name">
    <xsl:choose>
      <xsl:when test=".='xsl-body'">xsl-region-body</xsl:when>
      <xsl:when test=".='xsl-before'">xsl-region-before</xsl:when>
      <xsl:when test=".='xsl-after'">xsl-region-after</xsl:when>
      <xsl:when test=".='xsl-start'">xsl-region-start</xsl:when>
      <xsl:when test=".='xsl-end'">xsl-region-end</xsl:when>
      <xsl:otherwise><xsl:value-of select="."/></xsl:otherwise>
    </xsl:choose>
  </xsl:attribute>
</xsl:template>

<!-- =============================================================== -->
<!-- Whitespace-treatment (XEP) or white-space-treatment (FOP) -->
<!-- =============================================================== -->

<xsl:template match="@whitespace-treatment[.='ignore' or .='preserve'] | 
                     @white-space-treatment[.='ignore' or .='preserve']">
  <xsl:attribute name="space-treatment">
    <xsl:value-of select="."/>
  </xsl:attribute>
  <xsl:attribute name="linefeed-treatment">
    <xsl:value-of select="."/>
  </xsl:attribute>
  <xsl:attribute name="white-space-collapse">false</xsl:attribute>
</xsl:template>

<xsl:template match="@whitespace-treatment[.='collapse'] | 
                     @white-space-treatment[.='collapse']">
  <xsl:attribute name="space-treatment">preserve</xsl:attribute>
  <xsl:attribute name="linefeed-treatment">treat-as-space</xsl:attribute>
  <xsl:attribute name="white-space-collapse">true</xsl:attribute>
</xsl:template>


<!-- =============================================================== -->
<!-- List row attributes                                             -->
<!-- =============================================================== -->

<xsl:template match="@space-between-list-rows.minimum"/>
<xsl:template match="@space-between-list-rows.optimum"/>
<xsl:template match="@space-between-list-rows.maximum"/>
<xsl:template match="@space-between-list-rows.precedence"/>
<xsl:template match="@space-between-list-rows.conditionality"/>

<xsl:template match="@space-between-list-rows.minimum" mode="list-row-space">
  <xsl:attribute name="space-after.minimum"><xsl:value-of select="."/></xsl:attribute>
  <xsl:attribute name="space-before.minimum"><xsl:value-of select="."/></xsl:attribute>
</xsl:template>

<xsl:template match="@space-between-list-rows.optimum" mode="list-row-space">
  <xsl:attribute name="space-after.optimum"><xsl:value-of select="."/></xsl:attribute>
  <xsl:attribute name="space-before.optimum"><xsl:value-of select="."/></xsl:attribute>
</xsl:template>

<xsl:template match="@space-between-list-rows.maximum" mode="list-row-space">
  <xsl:attribute name="space-after.maximum"><xsl:value-of select="."/></xsl:attribute>
  <xsl:attribute name="space-before.maximum"><xsl:value-of select="."/></xsl:attribute>
</xsl:template>

<xsl:template match="@space-between-list-rows.precedence" mode="list-row-space">
  <xsl:attribute name="space-after.precedence"><xsl:value-of select="."/></xsl:attribute>
  <xsl:attribute name="space-before.precedence"><xsl:value-of select="."/></xsl:attribute>
</xsl:template>

<xsl:template match="@space-between-list-rows.conditionality" mode="list-row-space">
  <xsl:attribute name="space-after.conditionality"><xsl:value-of select="."/></xsl:attribute>
  <xsl:attribute name="space-before.conditionality"><xsl:value-of select="."/></xsl:attribute>
</xsl:template>

<!-- =============================================================== -->
<!-- Table attributes                                                -->
<!-- =============================================================== -->

<xsl:template match="@n-columns-repeated">
  <xsl:attribute name="number-columns-repeated">
    <xsl:value-of select="."/>
  </xsl:attribute>
</xsl:template>

<xsl:template match="@n-columns-spanned">
  <xsl:attribute name="number-columns-spanned">
    <xsl:value-of select="."/>
  </xsl:attribute>
</xsl:template>

<xsl:template match="@n-rows-spanned">
  <xsl:attribute name="number-rows-spanned">
    <xsl:value-of select="."/>
  </xsl:attribute>
</xsl:template>

<xsl:template match="@table-omit-middle-footer">
  <xsl:attribute name="table-omit-footer-at-break">
    <xsl:value-of select="."/>
  </xsl:attribute>
</xsl:template>

<xsl:template match="@table-omit-middle-header">
  <xsl:attribute name="table-omit-header-at-break">
    <xsl:value-of select="."/>
  </xsl:attribute>
</xsl:template>

<xsl:template match="@cell-height | @row-height | @table-height">
  <xsl:attribute name="height">
    <xsl:value-of select="."/>
  </xsl:attribute>
</xsl:template>

<xsl:template match="@caption-width | @table-width">
  <xsl:attribute name="width">
    <xsl:value-of select="."/>
  </xsl:attribute>
</xsl:template>

<xsl:template match="@may-break-after-row[.='yes']">
  <xsl:attribute name="keep-with-next">auto</xsl:attribute>
</xsl:template>

<xsl:template match="@may-break-after-row[.='no']">
  <xsl:attribute name="keep-with-next">always</xsl:attribute>
</xsl:template>

<xsl:template match="@may-break-before-row[.='yes']">
  <xsl:attribute name="keep-with-previous">auto</xsl:attribute>
</xsl:template>

<xsl:template match="@may-break-before-row[.='no']">
  <xsl:attribute name="keep-with-previous">always</xsl:attribute>
</xsl:template>


<!-- =============================================================== -->
<!-- Hyphenation attributes                                          -->
<!-- =============================================================== -->

<xsl:template match="@hyphenation-char">
  <xsl:attribute name="hyphenation-character">
    <xsl:value-of select="."/>
  </xsl:attribute>
</xsl:template>

<xsl:template match="@hyphenation-push-char-count">
  <xsl:attribute name="hyphenation-push-character-count">
    <xsl:value-of select="."/>
  </xsl:attribute>
</xsl:template>

<xsl:template match="@hyphenation-remain-char-count">
  <xsl:attribute name="hyphenation-remain-character-count">
    <xsl:value-of select="."/>
  </xsl:attribute>
</xsl:template>

<!-- =============================================================== -->
<!-- Page number format attributes                                   -->
<!-- =============================================================== -->

<xsl:template match="@digit-group-sep">
  <xsl:attribute name="grouping-separator">
    <xsl:value-of select="."/>
  </xsl:attribute>
</xsl:template>

<xsl:template match="@n-digits-per-group">
  <xsl:attribute name="grouping-size">
    <xsl:value-of select="."/>
  </xsl:attribute>
</xsl:template>

<xsl:template match="sequence-src"/>

<!-- =============================================================== -->
<!-- Leader attributes                                               -->
<!-- =============================================================== -->

<xsl:template match="@length">
  <xsl:attribute name="leader-length">
    <xsl:value-of select="."/>
  </xsl:attribute>
</xsl:template>

<xsl:template match="@rule-orientation"/>

<!-- =============================================================== -->
<!-- Keeps and breaks                                                -->
<!-- =============================================================== -->

<xsl:template match="@keep-with-next[.='true']">
  <xsl:attribute name="keep-with-next.within-column">always</xsl:attribute>
</xsl:template>

<xsl:template match="@keep-with-previous[.='true']">
  <xsl:attribute name="keep-with-previous.within-column">always</xsl:attribute>
</xsl:template>

<xsl:template match="@keep-with-next[.='false']">
  <xsl:attribute name="keep-with-next.within-column">auto</xsl:attribute>
</xsl:template>

<xsl:template match="@keep-with-previous[.='false']">
  <xsl:attribute name="keep-with-previous.within-column">auto</xsl:attribute>
</xsl:template>

<xsl:template match="@page-break-inside[.='avoid']">
  <xsl:attribute name="keep-together.within-column">always</xsl:attribute>
</xsl:template>

<xsl:template match="@page-break-inside[.='auto']">
  <xsl:attribute name="keep-together.within-column">auto</xsl:attribute>
</xsl:template>

<xsl:template match="@inhibit-line-breaks[.='false']">
  <xsl:attribute name="keep-together.within-line">auto</xsl:attribute>
</xsl:template>

<xsl:template match="@inhibit-line-breaks[.='true']">
  <xsl:attribute name="keep-together.within-line">always</xsl:attribute>
</xsl:template>

<!-- =============================================================== -->
<!-- Text align                                                      -->
<!-- =============================================================== -->

<xsl:template match="@text-align[.='centered']">
  <xsl:attribute name="text-align">center</xsl:attribute>
</xsl:template>

<xsl:template match="@text-align[.='justified']">
  <xsl:attribute name="text-align">justify</xsl:attribute>
</xsl:template>


<!-- =============================================================== -->
<!-- Image attributes                                                -->
<!-- =============================================================== -->

<xsl:template match="@scale">
  <xsl:variable name="scale-value" select="normalize-space(.)"/>

  <xsl:choose>
    <xsl:when test="contains($scale-value, ' ')">
      <xsl:variable name="scale-horz" select="substring-before($scale-value, ' ')"/>
      <xsl:variable name="scale-vert" select="substring-after($scale-value, ' ')"/>
      <xsl:attribute name="content-width"><xsl:value-of select="100*number($scale-horz)"/>%</xsl:attribute>
      <xsl:attribute name="content-height"><xsl:value-of select="100*number($scale-vert)"/>%</xsl:attribute>
    </xsl:when>
    <xsl:otherwise>
      <xsl:attribute name="content-width"><xsl:value-of select="100*number(.)"/>%</xsl:attribute>
      <xsl:attribute name="content-height"><xsl:value-of select="100*number(.)"/>%</xsl:attribute>
    </xsl:otherwise>
  </xsl:choose>
</xsl:template>

<xsl:template match="oldfo:display-graphic/@width | oldfo:inline-graphic/@width">
  <xsl:attribute name="content-width"><xsl:value-of select="."/></xsl:attribute>
</xsl:template>

<xsl:template match="oldfo:display-graphic/@height | oldfo:inline-graphic/@height">
  <xsl:attribute name="content-height"><xsl:value-of select="."/></xsl:attribute>
</xsl:template>


<!-- =============================================================== -->
<!-- Vertical align on table cells, lists and regions                -->
<!-- =============================================================== -->

<xsl:template match="oldfo:region-body/@vertical-align |
                     oldfo:region-before/@vertical-align |
                     oldfo:region-after/@vertical-align |
                     oldfo:region-start/@vertical-align |
                     oldfo:region-end/@vertical-align |
                     oldfo:table-cell/@vertical-align |
                     oldfo:table-row/@vertical-align |
                     oldfo:table-header/@vertical-align |
                     oldfo:table-footer/@vertical-align |
                     oldfo:table-body/@vertical-align |
                     oldfo:table/@vertical-align">
  <xsl:attribute name="display-align">
    <xsl:choose>
      <xsl:when test=".='top'">before</xsl:when>
      <xsl:when test=".='middle'">center</xsl:when>
      <xsl:when test=".='bottom'">after</xsl:when>
      <xsl:otherwise>auto</xsl:otherwise>
    </xsl:choose>
  </xsl:attribute>
</xsl:template>

<!-- Vertical-align values other than 'top' and 'baseline' -->
<!-- aren't supported in the new draft                     --> 
<xsl:template match="@vertical-align[parent::oldfo:list-item
                                  or parent::oldfo:list-block]">
  <xsl:choose>
    <xsl:when test=".='top'">
      <xsl:attribute name="relative-align">before</xsl:attribute>
    </xsl:when>
    <xsl:when test=".='baseline'">
      <xsl:attribute name="relative-align">baseline</xsl:attribute>
    </xsl:when>
  </xsl:choose>
</xsl:template>

</xsl:stylesheet>
