﻿<?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" xmlns:maiden="http://xml-maiden.com"  version="1.0">
<xsl:output method="xml" encoding="utf-8"/>
<xsl:template match="maiden:article">
<fo:root>
	<fo:layout-master-set>
		<fo:simple-page-master master-name="my-page">
		<fo:region-body margin="0.5in"/>
		</fo:simple-page-master>
	</fo:layout-master-set>
	<fo:page-sequence master-reference="my-page">
		<fo:flow flow-name="xsl-region-body">
			<fo:block font-size="16pt" font-family="'Palatino Linotype', serif" line-height="1.5em">
			<xsl:apply-templates/>
			</fo:block>
		</fo:flow>
	</fo:page-sequence>
</fo:root>
</xsl:template>

<xsl:template match="maiden:a">
<fo:inline xmlns:xlink="http://www.w3.org/1999/xlink" xlink:type="simple" xlink:href="{@href}">
<xsl:if test="@title">
<xsl:attribute name="xlink:title"><xsl:value-of select="@title"/></xsl:attribute>
</xsl:if>
<xsl:apply-templates/>
</fo:inline>
</xsl:template>

<xsl:template match="maiden:abstract | maiden:author | maiden:authors | maiden:affiliation | maiden:reference | maiden:info  | maiden:date | maiden:subject | maiden:keywords | maiden:msc  | maiden:pacs">
<fo:block margin="0 10% 0.5ex 10%" font-size="0.9em" line-height="1.2em">
<xsl:if test="self::maiden:abstract">
<xsl:attribute name="text-align">justify</xsl:attribute>
<fo:inline font-weight="bold"><xsl:text>Abstract. </xsl:text></fo:inline></xsl:if>
<xsl:if test="self::maiden:msc"><fo:inline font-weight="bold"><xsl:text>MSC 2000: </xsl:text></fo:inline></xsl:if>
<xsl:if test="self::maiden:pacs"><fo:inline font-weight="bold"><xsl:text>PACS: </xsl:text></fo:inline></xsl:if>
<xsl:if test="self::maiden:subject"><fo:inline font-weight="bold"><xsl:text>Subject: </xsl:text></fo:inline></xsl:if>
<xsl:if test="self::maiden:keywords"><fo:inline font-weight="bold"><xsl:text>Keywords: </xsl:text></fo:inline></xsl:if>
<xsl:apply-templates/>
</fo:block>
</xsl:template>

<xsl:template match="maiden:acknowledgements">
<fo:block margin="1ex 0" text-align="justify">
<fo:inline font-weight="bold"><xsl:text>Acknowledgements. </xsl:text></fo:inline>
<xsl:apply-templates/>
</fo:block>
</xsl:template>

<xsl:template match="maiden:statement | maiden:appendix | maiden:front | maiden:section | maiden:subsection | maiden:segment | maiden:subsegment | maiden:paragraph | maiden:subparagraph | maiden:editor | maiden:referee | maiden:notes">
<fo:block margin="1ex 0"  text-align="justify"><xsl:apply-templates/></fo:block>
</xsl:template>

<xsl:template match="maiden:axiom">
<fo:block margin="1ex 0"  border="dashed 1px">
<fo:inline font-weight="bold"><xsl:text>Axiom </xsl:text><xsl:number level="any"/><xsl:text>. </xsl:text></fo:inline>
<xsl:apply-templates/>
</fo:block>
</xsl:template>

<xsl:template match="maiden:code"> 
<fo:block font-family="monospace" text-align="left" white-space="pre">
<xsl:apply-templates/>
</fo:block>
</xsl:template>

<xsl:template match="maiden:corollary">
<fo:block margin="1ex 0" border-bottom="dotted 1px">
<fo:inline font-weight="bold"><xsl:text>Corollary. </xsl:text></fo:inline>
<xsl:apply-templates/>
</fo:block>
</xsl:template>

<xsl:template match="maiden:definition">
<fo:block margin="1ex 0">
<fo:inline font-weight="bold"><xsl:text>Definition </xsl:text><xsl:number level="any"/><xsl:text>. </xsl:text></fo:inline>
<xsl:apply-templates/>
</fo:block>
</xsl:template>

<xsl:template match="maiden:em"> 
<fo:inline font-style="italic"><xsl:apply-templates/></fo:inline>
</xsl:template>

<xsl:template match="maiden:example">
<fo:block margin="1ex 0" border-bottom="dotted 1px">
<fo:inline font-weight="bold"><xsl:text>Example </xsl:text><xsl:number level="any"/><xsl:text>. </xsl:text></fo:inline>
<xsl:apply-templates/>
</fo:block>
</xsl:template>

<xsl:template match="maiden:exercise">
<fo:block margin="1ex 0">
<fo:inline font-weight="bold"><xsl:text>Exercise </xsl:text><xsl:number level="any"/><xsl:text>. </xsl:text></fo:inline>
<xsl:apply-templates/>
</fo:block>
</xsl:template>

<xsl:template match="maiden:header">
<fo:block margin="1ex 0" font-weight="bold" font-size="1.2em">
<fo:inline><xsl:number level="any"/><xsl:text>. </xsl:text></fo:inline>
<xsl:apply-templates/>
</fo:block>
</xsl:template>


<xsl:template match="maiden:lemma">
<fo:block margin="1ex 0"  border="dashed 1px">
<fo:inline font-weight="bold"><xsl:text>Lemma </xsl:text><xsl:number level="any"/><xsl:text>. </xsl:text></fo:inline>
<xsl:apply-templates/>
</fo:block>
</xsl:template>

<xsl:template match="maiden:problem">
<fo:block margin="1ex 0">
<fo:inline font-weight="bold"><xsl:text>Problem </xsl:text><xsl:number level="any"/><xsl:text>. </xsl:text></fo:inline>
<xsl:apply-templates/>
</fo:block>
</xsl:template>

<xsl:template match="maiden:proof">
<fo:block margin="1ex 0" border-bottom="dotted 1px">
<fo:inline font-weight="bold"><xsl:text>Proof. </xsl:text></fo:inline>
<xsl:apply-templates/>
</fo:block>
</xsl:template>

<xsl:template match="maiden:proposition">
<fo:block margin="1ex 0"  border="dashed 1px">
<fo:inline font-weight="bold"><xsl:text>Proposition </xsl:text><xsl:number level="any"/><xsl:text>. </xsl:text></fo:inline>
<xsl:apply-templates/>
</fo:block>
</xsl:template>

<xsl:template match="maiden:q"> 
<xsl:text>"</xsl:text><xsl:apply-templates/><xsl:text>"</xsl:text>
</xsl:template>

<xsl:template match="maiden:quote">
<fo:block margin="1ex 1em 0 1ex"  border="dashed 1px">
<xsl:apply-templates/>
</fo:block>
</xsl:template>

<xsl:template match="maiden:remark">
<fo:block margin="1ex 0" border-bottom="dotted 1px">
<fo:inline font-weight="bold"><xsl:text>Remark </xsl:text><xsl:number level="any"/><xsl:text>. </xsl:text></fo:inline>
<xsl:apply-templates/>
</fo:block>
</xsl:template>


<xsl:template match="maiden:subheader">
<fo:block margin="1ex 0" font-weight="bold" font-size="1.1em" text-align="left">
<xsl:apply-templates/>
</fo:block>
</xsl:template>

<xsl:template match="maiden:summary">
<fo:block margin="1ex 0">
<fo:inline font-weight="bold"><xsl:text>Summary. </xsl:text></fo:inline>
<xsl:apply-templates/>
</fo:block>
</xsl:template>

<xsl:template match="maiden:solution">
<fo:block margin="1ex 0" border-bottom="dotted 1px">
<fo:inline font-weight="bold"><xsl:text>Solution. </xsl:text></fo:inline>
<xsl:apply-templates/>
</fo:block>
</xsl:template>

<xsl:template match="maiden:stress"> 
<fo:inline font-weight="bold"><xsl:apply-templates/></fo:inline>
</xsl:template>

<xsl:template match="maiden:theorem">
<fo:block margin="1ex 0"  border="dashed 1px">
<fo:inline font-weight="bold"><xsl:text>Theorem </xsl:text><xsl:number level="any"/><xsl:text>. </xsl:text></fo:inline>
<xsl:apply-templates/>
</fo:block>
</xsl:template>

<xsl:template match="maiden:title">
<fo:block margin="1ex 0" font-weight="bold" font-size="1.3em" text-align="left">
<xsl:apply-templates/>
</fo:block>
</xsl:template>

<xsl:template match="maiden:warning">
<fo:block margin="1ex 0">
<fo:inline font-weight="bold"><xsl:text>Warning. </xsl:text></fo:inline>
<xsl:apply-templates/>
</fo:block>
</xsl:template>

<xsl:template match="maiden:list">
<fo:table>
<fo:table-body>
<xsl:apply-templates/>
</fo:table-body>
</fo:table>
</xsl:template>

<xsl:template match="maiden:table[not(child::maiden:caption)]">
<fo:table>
<fo:table-body>
<xsl:apply-templates/>
</fo:table-body>
</fo:table>
</xsl:template>

<xsl:template match="maiden:table[maiden:caption]">
<fo:table-and-caption>
<fo:table-body>
<xsl:apply-templates/>
</fo:table-body>
</fo:table-and-caption>
</xsl:template>

<xsl:template match="maiden:tr">
<fo:table-row>
<xsl:apply-templates/>
</fo:table-row>
</xsl:template>

<xsl:template match="maiden:td">
<fo:table-cell>
<fo:block>
<xsl:apply-templates/>
</fo:block>
</fo:table-cell>
</xsl:template>

<xsl:template match="maiden:th">
<fo:table-cell font-weight="bold">
<fo:block>
<xsl:apply-templates/>
</fo:block>
</fo:table-cell>
</xsl:template>

<xsl:template match="maiden:caption">
<fo:table-caption>
<fo:block>
<xsl:apply-templates/>
</fo:block>
</fo:table-caption>
</xsl:template>

<xsl:template match="maiden:list | maiden:references">
<fo:list-block provisional-distance-between-starts="2em" provisional-label-separation="1em">
<xsl:apply-templates/>
</fo:list-block>
</xsl:template>

<xsl:template match="maiden:item | maiden:ref | maiden:cite">
<fo:list-item>
<fo:list-item-label start-indent="1em" end-indent="label-end()">
<fo:block wrap-option="no-wrap">
<xsl:choose>
<xsl:when test="self::maiden:list">
<xsl:number/><xsl:text>.</xsl:text>
</xsl:when>
<xsl:otherwise>
<xsl:text>[</xsl:text><xsl:number/><xsl:text>]</xsl:text>
</xsl:otherwise>
</xsl:choose>
</fo:block>
</fo:list-item-label>
<fo:list-item-body start-indent="body-start()">
<fo:block>
<xsl:apply-templates/>
</fo:block>
</fo:list-item-body>
</fo:list-item>
</xsl:template>

<xsl:template match="maiden:who | maiden:what | maiden:where">
<xsl:apply-templates/><xsl:text>, </xsl:text>
</xsl:template>

<xsl:template match="maiden:name | maiden:key | maiden:shell | maiden:when">
<xsl:apply-templates/>
</xsl:template>

<xsl:template match="maiden:formulae | maiden:subformula">
<fo:block wrap-option="no-wrap"><xsl:apply-templates/></fo:block>
</xsl:template>

<xsl:template match="maiden:formula">
<fo:table width="100%">
<fo:table-body>
<fo:table-row>
<fo:table-cell width="10%">
<fo:block><xsl:text>&#xA0;</xsl:text></fo:block>
</fo:table-cell>
<fo:table-cell width="85%">
<fo:block wrap-option="no-wrap" text-align="left"><xsl:apply-templates/></fo:block>
</fo:table-cell>
<fo:table-cell width="5%">
<fo:block wrap-option="no-wrap">
<xsl:text>(</xsl:text><xsl:number level="any"/><xsl:text>)</xsl:text>
</fo:block>
</fo:table-cell>
</fo:table-row>
</fo:table-body>
</fo:table>
</xsl:template>

<xsl:template match="maiden:math">
<fo:inline-container wrap-option="no-wrap" text-align="left"><fo:block><xsl:apply-templates/></fo:block></fo:inline-container>
</xsl:template>

<xsl:template match="maiden:fraction">
<fo:inline-container text-align="center" line-height="1.5em" baseline-shift="0.7em">
<fo:block border-bottom="solid 1px black">
<fo:inline-container alignment-adjust="after-edge">
<fo:block>
<xsl:apply-templates select="maiden:num/node()"/>
</fo:block>
</fo:inline-container>
</fo:block>
<fo:block><xsl:apply-templates select="maiden:den/node()"/></fo:block>
</fo:inline-container>
</xsl:template>

<xsl:template match="maiden:float | maiden:markers">
<fo:inline-container text-align="left" line-height="0.9em" baseline-shift="0.3em">
<fo:block>
<fo:inline-container alignment-adjust="after-edge">
<fo:block font-size="0.7em">
<xsl:apply-templates select="maiden:sup/node() | maiden:sur/node() | maiden:marker/node()"/>
</fo:block>
</fo:inline-container>
</fo:block>
<fo:block font-size="0.7em">
<xsl:apply-templates select="maiden:sub/node() | maiden:inf/node() | maiden:submarker/node()"/>
</fo:block>
</fo:inline-container>
</xsl:template>

<xsl:template match="maiden:sup | maiden:sur | maiden:marker">
<fo:inline baseline-shift="1.4ex" font-size="0.7em"><xsl:apply-templates/></fo:inline>
</xsl:template>

<xsl:template match="maiden:sub | maiden:inf | maiden:submarker">
<fo:inline baseline-shift="-0.8ex"  font-size="0.7em"><xsl:apply-templates/></fo:inline>
</xsl:template>

<xsl:template match="maiden:under">
<fo:inline-container text-align="center" line-height="1.3em">
<fo:block><xsl:apply-templates select="maiden:ope | maiden:ker | maiden:over"/></fo:block>
<xsl:if test="maiden:underbrace">
<fo:block border-style="solid" border-width="0 1px 1px 1px" line-height="0.5ex">&#xA0;</fo:block>
</xsl:if>
<xsl:for-each select="maiden:sat">
<fo:block font-size="0.7em"><xsl:apply-templates select="."/></fo:block>
</xsl:for-each>
</fo:inline-container>
</xsl:template>

<xsl:template match="maiden:over">
<fo:inline-container text-align="center" line-height="1.3em" baseline-shift="1.3em">
<fo:block>
<fo:inline-container alignment-adjust="after-edge">
<fo:block font-size="0.7em">
<xsl:for-each select="maiden:sat">
<fo:block font-size="0.7em"><xsl:apply-templates select="."/></fo:block>
</xsl:for-each>
<xsl:if test="maiden:overbrace">
<fo:block border-style="solid" border-width="1px 1px 0 1px" line-height="0.5ex">&#xA0;</fo:block>
</xsl:if>
</fo:block>
</fo:inline-container>
</fo:block>
<fo:block><xsl:apply-templates select="maiden:ope | maiden:ker | maiden:under"/></fo:block>
</fo:inline-container>
</xsl:template>

<xsl:template match="maiden:cases">
<fo:inline-container line-height="1.5em" font-size="0.9em" alignment-adjust="middle" border="dashed 1px">
<fo:table>
<fo:table-body>
<xsl:apply-templates/>
</fo:table-body>
</fo:table>
</fo:inline-container>
</xsl:template>

<xsl:template match="maiden:det">
<fo:inline-container line-height="1.5em" font-size="0.9em" alignment-adjust="middle" border-style="solid" border-width="0 1px">
<fo:table>
<fo:table-body>
<xsl:apply-templates/>
</fo:table-body>
</fo:table>
</fo:inline-container>
</xsl:template>

<xsl:template match="maiden:matrix | maiden:vector">
<fo:inline-container line-height="1.5em" font-size="0.9em" alignment-adjust="middle">
<fo:table>
<fo:table-body>
<fo:table-row>
<fo:table-cell border-style="solid" border-width="1px 0 1px 1px"><fo:block>&#xA0;</fo:block></fo:table-cell>
<fo:table-cell>
<fo:block>
<fo:table>
<fo:table-body>
<xsl:apply-templates/>
</fo:table-body>
</fo:table>
</fo:block>
</fo:table-cell>
<fo:table-cell border-style="solid" border-width="1px 1px 1px 0"><fo:block>&#xA0;</fo:block></fo:table-cell>
</fo:table-row>
</fo:table-body>
</fo:table>
</fo:inline-container>
</xsl:template>

<xsl:template match="maiden:case | maiden:row">
<fo:table-row>
<xsl:apply-templates/>
</fo:table-row>
</xsl:template>

<xsl:template match="maiden:entry">
<fo:table-row>
<fo:table-cell padding="0.5ex">
<fo:block><xsl:apply-templates/></fo:block>
</fo:table-cell>
</fo:table-row>
</xsl:template>

<xsl:template match="maiden:cell">
<fo:table-cell padding="0.5ex">
<fo:block><xsl:apply-templates/></fo:block>
</fo:table-cell>
</xsl:template>

<xsl:template match="maiden:scope">
<fo:table-cell text-align="left" padding="0.5ex">
<fo:block><xsl:apply-templates/></fo:block>
</fo:table-cell>
</xsl:template>

<xsl:template match="maiden:value">
<fo:table-cell text-align="right" padding="0.5ex">
<fo:block><xsl:apply-templates/></fo:block>
</fo:table-cell>
</xsl:template>

<xsl:template match="maiden:radical">
<xsl:choose>
<xsl:when test="descendant::maiden:fraction or descendant::maiden:under or descendant::maiden:over or descendant::maiden:matrix or descendant::maiden:vector or descendant::maiden:det or descendant::maiden:cases">
<fo:inline font-size="2em" baseline-shift="-0.2ex">(</fo:inline>
<xsl:apply-templates select="maiden:radicand"/>
<fo:inline font-size="2em" baseline-shift="-0.2ex">)</fo:inline>
</xsl:when>
<xsl:otherwise><xsl:text>(</xsl:text><xsl:apply-templates select="maiden:radicand"/>
<xsl:text>)</xsl:text></xsl:otherwise>
</xsl:choose>
<fo:inline baseline-shift="0.8ex" font-size="0.7em"><xsl:text>1/</xsl:text><xsl:choose>
<xsl:when test="maiden:radix/text() or maiden:radix/maiden:*"><xsl:apply-templates select="maiden:radix"/></xsl:when>
<xsl:otherwise><xsl:text>2</xsl:text></xsl:otherwise>
</xsl:choose>
</fo:inline>
</xsl:template>

<xsl:template match="maiden:fence">
<fo:inline font-size="2em" baseline-shift="-0.2ex">
<xsl:choose>
<xsl:when test="@left"><xsl:value-of select="translate(substring(@left,4,1),'bihlane','∥|¦{[(')"/></xsl:when>
<xsl:otherwise><xsl:text>[</xsl:text></xsl:otherwise>
</xsl:choose>
</fo:inline>
<xsl:apply-templates/>
<fo:inline font-size="2em" baseline-shift="-0.2ex">
<xsl:choose>
<xsl:when test="@right"><xsl:value-of select="translate(substring(@right,4,1),'bihlan','∥|¦}])')"/></xsl:when>
<xsl:otherwise><xsl:text>]</xsl:text></xsl:otherwise>
</xsl:choose>
</fo:inline>
</xsl:template>

<xsl:template match="maiden:bold">
<fo:inline font-weight="bold"><xsl:apply-templates/></fo:inline>
</xsl:template>

<xsl:template match="maiden:italic">
<fo:inline font-style="italic"><xsl:apply-templates/></fo:inline>
</xsl:template>

<xsl:template match="maiden:overline">
<fo:inline text-decoration="overline"><xsl:apply-templates/></fo:inline>
</xsl:template>

<xsl:template match="maiden:underline">
<fo:inline text-decoration="underline"><xsl:apply-templates/></fo:inline>
</xsl:template>

<xsl:template match="maiden:strike">
<fo:inline text-decoration="line-through"><xsl:apply-templates/></fo:inline>
</xsl:template>

<xsl:template match="maiden:group">
<xsl:apply-templates/>
</xsl:template>

<xsl:template match="maiden:line">
<fo:block height="1em"/>
</xsl:template>

<xsl:template match="maiden:wrap">
<fo:inline wrap-option="wrap">&#x200B;</fo:inline>
</xsl:template>
<!-- 
XSLT style sheet for XML MAIDEN mathematical articles. Converts XML MAIDEN 2.1 to XSL FO 1.0.
Note that in present version of style sheet element 'apply' is ignored, while content of element 'ker' is assumed to be (#PCDATA).
Designed by George Chavchanidze as a part of XML MAIDEN project http://xml-maiden.com
Last modified 16:52 30/05/2006 Tested in Antenna XSL Formatter V4 Beta
-->
</xsl:stylesheet>
