<?xml version="1.0"?>
<!-- ============================================================ -->
<!--                                                              -->
<!-- 	This file makes a part of RenderX XSL Test Suite          -->
<!--                                                              -->
<!--    Author: Alexander Peshkov                                 -->
<!--                                                              -->
<!--    (c) RenderX, 2003                                         -->
<!--                                                              -->
<!-- ============================================================ -->

<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
                			  xmlns:fo="http://www.w3.org/1999/XSL/Format"
                			  xmlns:rx="http://www.renderx.com/XSL/Extensions">

	<xsl:template match="/">
		<fo:root xmlns:fo="http://www.w3.org/1999/XSL/Format" xmlns:rx="http://www.renderx.com/XSL/Extensions">
		  <xsl:apply-templates/>
		</fo:root>
	</xsl:template>

	<xsl:template match="document[not(./section)]">
	<fo:layout-master-set>
		<fo:simple-page-master master-name="document-master" margin="0.4in">
			<fo:region-body margin="20pt" padding="0pt"/>
		</fo:simple-page-master>
	</fo:layout-master-set>
	<fo:page-sequence master-reference="document-master">
	<fo:flow flow-name="xsl-region-body" padding="6pt">
		<xsl:apply-templates/>
	</fo:flow>
	</fo:page-sequence>
	</xsl:template>

	<xsl:template match="document">
	<fo:layout-master-set>
		<fo:simple-page-master master-name="document-master" margin="0.4in">
			<fo:region-body margin="20pt" padding="0pt"/>
		</fo:simple-page-master>
	</fo:layout-master-set>
	  <xsl:apply-templates/>
	</xsl:template>

	<xsl:template match="section">
	  <fo:page-sequence master-reference="document-master">
		<fo:flow flow-name="xsl-region-body" padding="6pt">
			<xsl:apply-templates/>
		</fo:flow>
	  </fo:page-sequence>
	</xsl:template>

	<xsl:template match="para">
		<fo:block font-size="12pt" space-before="6pt" space-after="6pt" text-align="justify" text-indent="16pt">
			<xsl:apply-templates select="@*|node()"/>
		</fo:block>
	</xsl:template>

	<xsl:template match="simpara">
	  <fo:block>
		<xsl:apply-templates select="@*|node()"/>
	  </fo:block>
	</xsl:template>
	
	<xsl:template match="figure/para">
		<fo:block font-size="10pt" text-align="justify">
			<xsl:apply-templates select="@*|node()"/>
		</fo:block>
	</xsl:template>

	<xsl:template match="citation">
	  <fo:block font-size="12pt" font-style="italic" space-before="6pt" space-after="6pt">
	    <xsl:apply-templates select="@*|node()"/>
	  </fo:block>
	</xsl:template>

	<xsl:template match="title">
		<fo:block font="bold 16pt Helvetica" space-before="16pt" space-after="16pt" text-align="center" span="all">
			<xsl:apply-templates select="@*|node()"/>
		</fo:block>
	</xsl:template>

	<xsl:template match="subtitle">
		<fo:block font="bold 12pt Helvetica" space-before="10pt" space-after="10pt" text-align="left" keep-with-next="always">
			<xsl:apply-templates select="@*|node()"/>
		</fo:block>
	</xsl:template>

	<xsl:template match="figure/subtitle">
		<fo:block font="bold 12pt Helvetica" space-after="10pt" text-align="center">
			<xsl:apply-templates select="@*|node()"/>
		</fo:block>
	</xsl:template>

	<!-- This one is in question -->
	<!--xsl:template match="figure">
		<fo:float float="left" clear="both" start-indent="0pt" end-indent="0pt" text-indent="0pt">
			<xsl:if test="@align"><xsl:attribute name="float"><xsl:value-of select="@align"/></xsl:attribute></xsl:if>
			<fo:block-container width="100pt" border="thin solid silver" padding="6pt" margin-left="6pt" margin-right="6pt">
				<xsl:apply-templates select="@*|node()"/>
			</fo:block-container>
		</fo:float>
	</xsl:template-->

	<xsl:template match="ulink">
	  <xsl:variable name="url" select="@url"/>
      <fo:basic-link external-destination="url({$url})"
                    color="#0000C0"
                    text-decoration="underline">
          <xsl:apply-templates select="@*[name()!='url']|node()"/>
	  </fo:basic-link>
	</xsl:template>


	<xsl:template match="code">
	  <fo:wrapper font-family="monospace"><xsl:apply-templates select="@*|node()"/></fo:wrapper>
	</xsl:template>

	<xsl:template match="codeblock">
	  <fo:block white-space="pre" font-family="monospace">
	    <xsl:apply-templates select="@*|node()"/>
	  </fo:block>
	</xsl:template>

	<xsl:template match="image">
	  <fo:block>
	        <fo:external-graphic>
	          <xsl:attribute name="src">url(<xsl:value-of select="@src"/>)</xsl:attribute>
            </fo:external-graphic>
      </fo:block>
	</xsl:template>

	<!-- Tables -->
	<xsl:template match="table">
	 <fo:table-and-caption space-after="4pt">
	    <fo:table-caption> 
	  	<fo:block font="bold 10pt Helvetica" keep-with-next="always" space-before="16pt" space-after="6pt" text-align="end">
	  		<xsl:value-of select="table-caption"/>
	  	</fo:block>
	    </fo:table-caption>
	    <fo:table border="0.75pt solid black"
       		      border-before-width.conditionality="retain"
            	  border-after-width.conditionality="retain">
  	      <xsl:apply-templates select="@*"/>
  	      <xsl:apply-templates select="colspec"/>
	      <xsl:apply-templates select="table-header"/>
  	      <xsl:apply-templates select="table-body"/>
      	</fo:table>
	 </fo:table-and-caption>
	</xsl:template>

	<xsl:template match="table-header">
	  <fo:table-header background-color="silver" font-size="110%" font-weight="bold">
	    <xsl:apply-templates select="@*|node()"/>
	  </fo:table-header>
	</xsl:template>

	<xsl:template match="table-body">
	  <fo:table-body>
	    <xsl:apply-templates select="@*|node()"/>
	  </fo:table-body>
	</xsl:template>

	<xsl:template match="row">
	  <fo:table-row>
	    <xsl:apply-templates select="@*|node()"/>
	  </fo:table-row>
	</xsl:template>

	<xsl:template match="entry">
	  <fo:table-cell border="0.25pt solid black"
      			     border-before-width.conditionality="retain"
            		 border-after-width.conditionality="retain"
            		 padding="3pt"
            		 text-align="from-table-column()"
            		 display-align="from-table-column()">
	    <xsl:apply-templates select="@*"/>
        <fo:block><xsl:apply-templates/></fo:block>
	  </fo:table-cell>
	</xsl:template>

	<xsl:template match="colspec">
	  <fo:table-column>
	    <xsl:apply-templates select="@*"/>
	  </fo:table-column>
	</xsl:template>

	<xsl:template match="@colwidth">
  	  <xsl:attribute name="column-width">
	    <xsl:choose>
	      <xsl:when test="contains(string(),'*')">
	        <xsl:text>proportional-column-width(</xsl:text>
	          <xsl:value-of select="substring-before(string(), '*')"/>
	          <xsl:text>)</xsl:text>
	      </xsl:when>
	      <xsl:otherwise>
	        <xsl:value-of select="."/>
	      </xsl:otherwise>
	    </xsl:choose>
	  </xsl:attribute>
	</xsl:template>

	<xsl:template match="@colspan">
	  <xsl:attribute name="number-columns-spanned"><xsl:value-of select="."/></xsl:attribute>
	</xsl:template>

    <!-- Other -->
	<xsl:template match="@*">
	  <xsl:copy/>
	</xsl:template>

	<xsl:template match="comment()">
      	  <xsl:text>&#xA;</xsl:text>
          <xsl:copy/>
	</xsl:template>

	<xsl:template match="*[namespace-uri()!='']"/>

</xsl:stylesheet>