<?xml version="1.0" encoding="utf-8"?>

<!--
 Feuille XSLT de transformation xHTML -> XSL-FO.
 Elle est pratique pour générer des rapports.

 @author Bieler Batiste
 @version 0.95
 @company http://dosimple.ch

Copyright (C) 2005  Bieler Batiste

This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 2.1 of the License, or (at your option) any later version.

This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
Lesser General Public License for more details.

You should have received a copy of the GNU Lesser General Public
License along with this library; if not, write to the Free Software
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
-->

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

<xsl:output method="html" encoding="utf-8" indent="yes" omit-xml-declaration="no"/>

<xsl:param name="page.width">210mm</xsl:param>
<xsl:param name="page.height">297mm</xsl:param>
<xsl:param name="page.margin.top">2cm</xsl:param>
<xsl:param name="page.margin.right">2cm</xsl:param>
<xsl:param name="page.margin.left">2cm</xsl:param>
<xsl:param name="page.margin.bottom">1.5cm</xsl:param>
<xsl:param name="page.body.margin.top">2.5cm</xsl:param>
<xsl:param name="page.body.margin.right">1cm</xsl:param>
<xsl:param name="page.body.margin.bottom">3cm</xsl:param>
<xsl:param name="page.body.margin.left">0cm</xsl:param>
<xsl:param name="page.before.extent">2cm</xsl:param>
<xsl:param name="page.after.extent">1cm</xsl:param>
<xsl:param name="page.title.font-size">24pt</xsl:param>
<xsl:param name="page.h1.font-size">20pt</xsl:param>
<xsl:param name="page.h2.font-size">16pt</xsl:param>
<xsl:param name="page.h3.font-size">14pt</xsl:param>
<xsl:param name="page.h4.font-size">12pt</xsl:param>
<xsl:param name="page.body.font-size">10pt</xsl:param>
<xsl:param name="page.code.font-size">9pt</xsl:param>
<xsl:param name="page.header.font-size">8pt</xsl:param>
<xsl:param name="page.footer.font-size">8pt</xsl:param>
<xsl:param name="page.p.margin-left">1cm</xsl:param>
<xsl:param name="page.link.color">#001199</xsl:param>

<xsl:template match="/xhtml:html">
	<fo:root font-selection-strategy="character-by-character"
	xmlns:fo="http://www.w3.org/1999/XSL/Format"
	xmlns:fox="http://xml.apache.org/fop/extensions">
	
		<fo:layout-master-set>
			<fo:simple-page-master
					master-name="front"
					page-height="{$page.height}"
					page-width="{$page.width}"
					margin-top="{$page.margin.top}"
					margin-bottom="{$page.margin.bottom}"
					margin-left="{$page.margin.left}"
					margin-right="{$page.margin.right}">
				<fo:region-body />
			</fo:simple-page-master>
			<fo:simple-page-master
					master-name="data"
					page-height="{$page.height}"
					page-width="{$page.width}"
					margin-top="{$page.margin.top}"
					margin-bottom="{$page.margin.bottom}"
					margin-left="{$page.margin.left}"
					margin-right="{$page.margin.right}">
				<fo:region-body
					margin-top="{$page.body.margin.top}"
					margin-right="{$page.body.margin.right}"
					margin-bottom="{$page.body.margin.bottom}"
					margin-left="{$page.body.margin.left}" />
				<fo:region-before
					region-name="header"
					extent="{$page.before.extent}"/>
				<fo:region-after
					region-name="footer"
					extent="{$page.after.extent}"/>
			</fo:simple-page-master>
		</fo:layout-master-set>
		
		<fox:bookmarks>
			<fox:outline internal-destination="toc">
				<fox:label>Table des matières</fox:label>
			</fox:outline>
			<xsl:for-each select="/xhtml:html/xhtml:body/xhtml:h1">
				<fox:outline>
					<xsl:attribute name="internal-destination">
						<xsl:choose>
							<xsl:when test="@id">
								<xsl:value-of select="@id"/>
							</xsl:when>
							<xsl:otherwise>
								<xsl:value-of select="generate-id()"/>
							</xsl:otherwise>
						</xsl:choose>
					</xsl:attribute>
					
					<xsl:variable name="h1-number" select="position()" />
					<xsl:variable name="preceding-h2" select="count(preceding-sibling::xhtml:h2)" />
					
					<fox:label>
						<xsl:value-of select="position()" />
						<xsl:text>. </xsl:text>
						<xsl:value-of select="."/>
					</fox:label>
					
						<xsl:for-each select="/xhtml:html/xhtml:body/xhtml:h2">
							<xsl:if test="count(preceding-sibling::xhtml:h1) = $h1-number">
								<fox:outline>
									<xsl:attribute name="internal-destination">
										<xsl:choose>
											<xsl:when test="@id">
												<xsl:value-of select="@id"/>
											</xsl:when>
											<xsl:otherwise>
												<xsl:value-of select="generate-id()"/>
											</xsl:otherwise>
										</xsl:choose>
									</xsl:attribute>
									<fox:label>
										<xsl:value-of select="position() - $preceding-h2" />
										<xsl:text>. </xsl:text>
										<xsl:value-of select="."/>
									</fox:label>
								</fox:outline>
							</xsl:if>
						</xsl:for-each>
				</fox:outline>
			</xsl:for-each>
			<fox:outline internal-destination="toi">
				<fox:label><xsl:value-of select="count(/xhtml:html/xhtml:body/xhtml:h1)+1"/>. Table des illustrations</fox:label>
			</fox:outline>
		</fox:bookmarks>
		
		<xsl:apply-templates select="xhtml:head" />
		<xsl:apply-templates select="xhtml:body" />

	</fo:root>
</xsl:template>


<xsl:template match="xhtml:head">
	<fo:page-sequence master-reference="front">
		<fo:flow flow-name="xsl-region-body" >
		<fo:block
			border-after-style="solid"
			border-after-width="1pt"
			border-after-color="#cccccc"
			space-after="100pt">
			<fo:block font-size="{$page.title.font-size}" font-family="sans-serif">
				<xsl:value-of select="xhtml:title" />
			</fo:block>
		</fo:block>
		<fo:block>
			<xsl:apply-templates select="/xhtml:html/xhtml:body/xhtml:div[@id='subtitle']"/>
		</fo:block>
		<fo:block break-before="page"/>
		<fo:block>
			<xsl:apply-templates select="/xhtml:html/xhtml:body/xhtml:div[@id='abstract']"/>
		</fo:block>
		</fo:flow>
	</fo:page-sequence>
</xsl:template>

<!-- afin de gérer les symboles spéciaux -->
<xsl:template match="xhtml:span[@class = 'symbol']">
	<fo:inline font-family="Symbol">
		<xsl:apply-templates/>
	</fo:inline>
</xsl:template>

<xsl:template match="xhtml:div[@id='subtitle']">
	<fo:block text-align="right">
			<xsl:apply-templates/>
	</fo:block>
</xsl:template>

<xsl:template match="xhtml:div[@id='abstract']">
	<fo:block>
			<xsl:apply-templates/>
	</fo:block>
</xsl:template>

<xsl:template match="xhtml:body">

	<fo:page-sequence master-reference="data">
		<fo:static-content flow-name="header">
			<fo:block font-size="{$page.header.font-size}">
				<fo:table table-layout="fixed">
				<fo:table-column column-width="220pt"/>
				<fo:table-column column-width="220pt"/>
				<fo:table-body>
					<fo:table-row>
						<fo:table-cell>
							<fo:external-graphic src="images/logo-hearc.png" height="25pt"/>
						</fo:table-cell>
						<fo:table-cell>
							<fo:block text-align="right">
								<fo:external-graphic src="images/logobig.png" height="30pt"/>
							</fo:block>
						</fo:table-cell>
					</fo:table-row>
					<fo:table-row>
					<fo:table-cell>
						<fo:block>
							<xsl:value-of select="/xhtml:html/xhtml:head/xhtml:title"/>
						</fo:block>
					</fo:table-cell>
					<fo:table-cell>
						<fo:block text-align="right">
							<fo:retrieve-marker retrieve-class-name="header1" 
							retrieve-position="first-starting-within-page"
							retrieve-boundary="page-sequence"
							/>
						</fo:block>
						<!--<fo:block text-align="right">
								<fo:retrieve-marker retrieve-class-name="header2" 
								retrieve-position="first-starting-within-page"
								retrieve-boundary="page-sequence"/>
						</fo:block>-->
					</fo:table-cell>
					</fo:table-row>
				</fo:table-body>
				</fo:table>
			</fo:block>
		</fo:static-content>
		
		<fo:static-content flow-name="footer">
			<fo:block text-align="center" font-size="{$page.footer.font-size}">
				<fo:page-number/> sur
				<fo:page-number-citation ref-id="lastPage"/>
			</fo:block>
		</fo:static-content>
		
		<fo:flow flow-name="xsl-region-body">
			<xsl:call-template name="toc"/>
			<xsl:apply-templates select="/xhtml:html/xhtml:body/*[count(@id)=0 or (@id!='subtitle' and @id!='abstract')]" />
			<xsl:call-template name="toi"/>
			<fo:block id="lastPage" font-size="0pt" line-height="0pt" space-after="0pt"/>
		</fo:flow>
		
	</fo:page-sequence>
	
</xsl:template>

<xsl:template match="xhtml:p">
	<fo:block space-after="1em" text-align="justify" font-size="{$page.body.font-size}">
		<xsl:if test="name(..)='body' or name(..)='div'">
			<xsl:attribute name="margin-left">
				<xsl:value-of select="$page.p.margin-left"/>
			</xsl:attribute>
		</xsl:if>
		<xsl:apply-templates/>
	</fo:block>
</xsl:template>

<xsl:template match="xhtml:blockquote">
	<fo:block margin-left="{$page.p.margin-left}" font-style="italic" font-family="Times" space-after="1em" font-size="{$page.body.font-size}">
	«<xsl:apply-templates/>»
	</fo:block>
	<fo:block margin-left="{$page.p.margin-left}" text-align="right" font-size="90%" space-after="2em">
		<xsl:text>— </xsl:text>
		<xsl:value-of select="@cite" />
	</fo:block>
</xsl:template>

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

<xsl:template match="xhtml:h1">
	<xsl:if test="name(..)='body'">
		<fo:block break-before="page"/>
	</xsl:if>
	
	<fo:block font-size="{$page.header.font-size}">
		<fo:marker marker-class-name="header1">
			<xsl:value-of select="."/>
		</fo:marker>
	</fo:block>

	<fo:block font-size="{$page.h1.font-size}" space-after="1em">
		<xsl:attribute name="id">
		<xsl:choose>
			<xsl:when test="@id">
				<xsl:value-of select="@id"/>
			</xsl:when>
			<xsl:otherwise>
				<xsl:value-of select="generate-id()"/>
			</xsl:otherwise>
		</xsl:choose>
		</xsl:attribute>
		<xsl:if test="name(..)='body'">
			<xsl:number/>.
		</xsl:if>

		<xsl:apply-templates/>
	</fo:block>
</xsl:template>

<xsl:template match="xhtml:h2">
	<fo:block font-size="{$page.header.font-size}">
		<fo:marker marker-class-name="header2">
			<xsl:value-of select="."/>
		</fo:marker>
	</fo:block>
	<fo:block font-size="{$page.h2.font-size}" space-after="1em">
		<xsl:attribute name="id">
			<xsl:choose>
			<xsl:when test="@id">
				<xsl:value-of select="@id"/>
			</xsl:when>
			<xsl:otherwise>
				<xsl:value-of select="generate-id()"/>
			</xsl:otherwise>
			</xsl:choose>
		</xsl:attribute>
	<xsl:value-of select="count(preceding-sibling::xhtml:h1)"/>.<xsl:value-of select="1+count(preceding-sibling::xhtml:h2)-count(preceding-sibling::xhtml:h1/preceding-sibling::xhtml:h2)"/>.
		<xsl:apply-templates/>
	</fo:block>
</xsl:template>

<xsl:template match="xhtml:h3">
	<fo:block font-size="{$page.h3.font-size}" space-after="1em">
		<xsl:attribute name="id">
			<xsl:choose>
			<xsl:when test="@id">
				<xsl:value-of select="@id"/>
			</xsl:when>
			<xsl:otherwise>
				<xsl:value-of select="generate-id()"/>
			</xsl:otherwise>
			</xsl:choose>
		</xsl:attribute>
	<xsl:value-of select="count(preceding-sibling::xhtml:h1)"/>.<xsl:value-of select="count(preceding-sibling::xhtml:h2)-count(preceding-sibling::xhtml:h1/preceding-sibling::xhtml:h2)"/>.<xsl:value-of select="1+count(preceding-sibling::xhtml:h3)-count(preceding-sibling::xhtml:h2/preceding-sibling::xhtml:h3)"/>.
		<xsl:apply-templates/>
	</fo:block>
</xsl:template>

<xsl:template match="xhtml:h4">
	<fo:block font-size="{$page.h4.font-size}" space-after="1em">
		<xsl:attribute name="id">
			<xsl:choose>
			<xsl:when test="@id">
				<xsl:value-of select="@id"/>
			</xsl:when>
			<xsl:otherwise>
				<xsl:value-of select="generate-id()"/>
			</xsl:otherwise>
			</xsl:choose>
		</xsl:attribute>
		<xsl:apply-templates/>
	</fo:block>
</xsl:template>

<xsl:template match="xhtml:h5">
	<fo:block font-size="{$page.h4.font-size}" space-after="1em">
		<xsl:attribute name="id">
			<xsl:choose>
			<xsl:when test="@id">
				<xsl:value-of select="@id"/>
			</xsl:when>
			<xsl:otherwise>
				<xsl:value-of select="generate-id()"/>
			</xsl:otherwise>
			</xsl:choose>
		</xsl:attribute>
		<xsl:apply-templates/>
	</fo:block>
</xsl:template>

<xsl:template match="xhtml:h6">
	<fo:block font-size="{$page.h4.font-size}" space-after="1em">
		<xsl:attribute name="id">
			<xsl:choose>
			<xsl:when test="@id">
				<xsl:value-of select="@id"/>
			</xsl:when>
			<xsl:otherwise>
				<xsl:value-of select="generate-id()"/>
			</xsl:otherwise>
			</xsl:choose>
		</xsl:attribute>
		<xsl:apply-templates/>
	</fo:block>
</xsl:template>

<xsl:template match="xhtml:dl">
	<fo:block  space-after="1em" font-size="{$page.body.font-size}">
		<xsl:apply-templates/>
	</fo:block>
</xsl:template>

<xsl:template match="xhtml:dt">
	<fo:block  font-weight="bold" space-before="0.8em" space-after="0.1em">
		<xsl:apply-templates/>
	</fo:block>
</xsl:template>

<xsl:template match="xhtml:dd">
	<fo:block margin-left="2cm">
		<xsl:apply-templates/>
	</fo:block>
</xsl:template>

<xsl:template match="xhtml:ul">
	<fo:block space-after="1em" 
		margin-left="inherited-property-value('margin-left')+1.5cm" 
		font-size="{$page.body.font-size}" relative-position = "relative">
		<xsl:apply-templates />
	</fo:block>
</xsl:template>

<xsl:template match="xhtml:ol">
	<fo:block space-after="1em" 
		margin-left="inherited-property-value('margin-left')+1.5cm"
		font-size="{$page.body.font-size}" relative-position = "relative">
		<xsl:apply-templates/>
	</fo:block>
</xsl:template>

<xsl:template match="xhtml:li">
	<fo:list-item>
		<fo:list-item-label text-align="end" end-indent="label-end()">
			<fo:block>
				<xsl:choose>
					<xsl:when test="name(..)='ol'">
						<xsl:number/><xsl:text>.</xsl:text>
					</xsl:when>
					<xsl:otherwise>
						<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="xhtml:pre">
	<fo:block font-family="monospace" white-space-collapse="false"
	space-after="1em" font-size="{$page.code.font-size}">
		<xsl:if test="name(..)='body'">
			<xsl:attribute name="margin-left">
				<xsl:text>1cm</xsl:text>
			</xsl:attribute>
		</xsl:if>
		<xsl:apply-templates/>
	</fo:block>
</xsl:template>

<xsl:template match="xhtml:code">
	<fo:inline font-family="monospace">
		<xsl:apply-templates/>
	</fo:inline>
</xsl:template>

<xsl:template match="xhtml:table">
	<xsl:param name="td-set" select="xhtml:tr[1]/xhtml:td|xhtml:tr[1]/xhtml:th" />
	<xsl:variable name="col-width" select="round(100 div(count($td-set)))"/>
	<fo:block space-after="1em" font-size="{$page.body.font-size}">
	<fo:block space-after="1em" font-weight="bold" text-align="center"><xsl:value-of select="xhtml:caption"/></fo:block>
	<fo:table width="350pt" start-indent="50pt">
		<xsl:for-each select="$td-set">
			<fo:table-column width="{$col-width}pt" />
		</xsl:for-each>
		<fo:table-body>
			<xsl:apply-templates/>
		</fo:table-body>
	</fo:table>
	</fo:block>
</xsl:template>

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

<xsl:template match="xhtml:th">
	<fo:table-cell>
		<fo:block space-after="0.5em">
			<fo:inline font-weight="bold">
				<xsl:apply-templates/>
			</fo:inline>
		</fo:block>
	</fo:table-cell>
</xsl:template>

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

<xsl:template match="xhtml:img">
<fo:block space-after="1em" text-align="center">
	<xsl:attribute name="id">
		<xsl:choose>
			<xsl:when test="@id">
				<xsl:value-of select="@id"/>
			</xsl:when>
			<xsl:otherwise>
				<xsl:value-of select="generate-id()"/>
			</xsl:otherwise>
		</xsl:choose>
	</xsl:attribute>
	<fo:external-graphic src="{@src}" width="{@width}pt"/>
	<xsl:if test="count(@alt)=1">
		<fo:block space-after="1em" space-before="1em" text-align="center" font-size="{$page.body.font-size}">
			<fo:inline font-weight="bold">
				<xsl:text>Figure </xsl:text><xsl:number/><xsl:text> : </xsl:text>
			</fo:inline>
			<xsl:value-of select="@alt"/>
		</fo:block>
	</xsl:if>
</fo:block>
</xsl:template>

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

<xsl:template match="xhtml:sup">
<fo:inline baseline-shift="super" vertical-align="super" font-size="0.7em">
		<xsl:apply-templates/>
</fo:inline>
</xsl:template>

<xsl:template match="xhtml:a">
<fo:inline font-style="italic">
		<xsl:apply-templates/>
		<xsl:text> (</xsl:text><xsl:value-of select="@href"/><xsl:text>)</xsl:text>
</fo:inline>
</xsl:template>

<xsl:template match="xhtml:a">
<fo:inline>
<xsl:choose>
	<xsl:when test="@href">
		<fo:basic-link color="{$page.link.color}">
			<xsl:choose>
				<xsl:when test="starts-with(@href, '#')">
					<xsl:attribute name="internal-destination">
						<xsl:value-of select="substring(@href, 2)"/>
					</xsl:attribute>
				</xsl:when> 
				<xsl:otherwise>
					<xsl:attribute name="external-destination">
						<xsl:value-of select="@href"/>
					</xsl:attribute>
				</xsl:otherwise>
			</xsl:choose>
			<xsl:apply-templates select="*|text()"/>
		</fo:basic-link>
	</xsl:when>
</xsl:choose>
</fo:inline>
</xsl:template>

<xsl:template name="toi">
	<fo:block break-before="page"/>
	<fo:block font-size="{$page.header.font-size}" id="toi">
		<fo:marker marker-class-name="header1">
			<xsl:text>Table des illustrations</xsl:text>
		</fo:marker>
	</fo:block>
	<fo:block id="tableOfIllustrations" font-size="0pt" line-height="0pt" space-after="0pt"/>
	<fo:block space-after="1em" font-size="{$page.h1.font-size}">
		<xsl:value-of select="count(xhtml:h1)+1" /><xsl:text>. Table des illustrations</xsl:text>
	</fo:block>
	<fo:block>
	<xsl:for-each select="xhtml:img">
		<fo:block text-align-last="justify" margin-left="{$page.p.margin-left}" font-size="{$page.body.font-size}">
		<fo:basic-link color="{$page.link.color}">
			<xsl:attribute name="internal-destination">
				<xsl:choose>
					<xsl:when test="@id">
						<xsl:value-of select="@id"/>
					</xsl:when>
					<xsl:otherwise>
						<xsl:value-of select="generate-id()"/>
					</xsl:otherwise>
				</xsl:choose>
			</xsl:attribute>
			<fo:inline font-weight="bold">
				<xsl:text>Figure </xsl:text>
				<xsl:number/>
			</fo:inline>
			<fo:inline>
				<xsl:text> : </xsl:text>
				<xsl:value-of select="@alt" />
			</fo:inline>
			<xsl:text> </xsl:text>
			</fo:basic-link>
			<fo:leader leader-pattern="dots" leader-pattern-width="5pt"/>
			<fo:page-number-citation>
				<xsl:attribute name="ref-id">
					<xsl:choose>
						<xsl:when test="@id">
							<xsl:value-of select="@id"/>
						</xsl:when>
						<xsl:otherwise>
							<xsl:value-of select="generate-id()"/>
						</xsl:otherwise>
					</xsl:choose>
				</xsl:attribute>
			</fo:page-number-citation>
		</fo:block>
	</xsl:for-each>
	</fo:block>
</xsl:template>

<xsl:template name="toc">
	<fo:block break-before="page"/>
	<fo:block space-after="1em" font-size="{$page.h1.font-size}" id="toc">
		Table des matières
	</fo:block>
	<fo:block>
	<xsl:for-each select="xhtml:h1|xhtml:h2|xhtml:h3">
		<fo:block text-align-last="justify" font-size="{$page.body.font-size}">
			<xsl:attribute name="start-indent">
				<xsl:choose>
				<xsl:when test="name() = 'h1'">
					<xsl:text>1cm</xsl:text>
				</xsl:when>
				<xsl:when test="name() = 'h2'">
					<xsl:text>2cm</xsl:text>
				</xsl:when>
				<xsl:when test="name() = 'h3'">
					<xsl:text>3cm</xsl:text>
				</xsl:when>
				<xsl:otherwise>
					<xsl:text>4cm</xsl:text>
				</xsl:otherwise>
				</xsl:choose>
			</xsl:attribute>
				<xsl:choose>
				<xsl:when test="name() = 'h1'">
				<xsl:number/>.
				</xsl:when>
				<xsl:when test="name() = 'h2'">
	<xsl:value-of select="count(preceding-sibling::xhtml:h1)"/>.<xsl:value-of select="1+count(preceding-sibling::xhtml:h2)-count(preceding-sibling::xhtml:h1/preceding-sibling::xhtml:h2)"/>.
				</xsl:when>
				<xsl:when test="name() = 'h3'">
	<xsl:value-of select="count(preceding-sibling::xhtml:h1)"/>.<xsl:value-of select="count(preceding-sibling::xhtml:h2)-count(preceding-sibling::xhtml:h1/preceding-sibling::xhtml:h2)"/>.<xsl:value-of select="1+count(preceding-sibling::xhtml:h3)-count(preceding-sibling::xhtml:h2/preceding-sibling::xhtml:h3)"/>.
				</xsl:when>
				<!--<xsl:otherwise>
	<xsl:value-of select="count(preceding-sibling::xhtml:h1)"/>.<xsl:value-of select="count(preceding-sibling::xhtml:h2)-count(preceding-sibling::xhtml:h1/preceding-sibling::xhtml:h2)"/>.<xsl:value-of select="count(preceding-sibling::xhtml:h3)-count(preceding-sibling::xhtml:h2/preceding-sibling::xhtml:h3)"/>.
				</xsl:otherwise>-->
				</xsl:choose>
		<fo:basic-link color="{$page.link.color}">
			<xsl:attribute name="internal-destination">
				<xsl:choose>
					<xsl:when test="@id">
						<xsl:value-of select="@id"/>
					</xsl:when>
					<xsl:otherwise>
						<xsl:value-of select="generate-id()"/>
					</xsl:otherwise>
				</xsl:choose>
			</xsl:attribute>
			<xsl:value-of select="."/>
			<fo:leader leader-pattern="dots"
			leader-pattern-width="5pt"/>
			<fo:page-number-citation ref-id="@id">
			<xsl:attribute name="ref-id">
				<xsl:choose>
					<xsl:when test="@id">
						<xsl:value-of select="@id"/>
					</xsl:when>
					<xsl:otherwise>
						<xsl:value-of select="generate-id()"/>
					</xsl:otherwise>
				</xsl:choose>
			</xsl:attribute>
			</fo:page-number-citation>
		</fo:basic-link>
		</fo:block>
	</xsl:for-each>
	</fo:block>
	<fo:block text-align-last="justify" font-size="{$page.body.font-size}" start-indent="1cm">
		<xsl:value-of select="count(xhtml:h1)+1" />
		<xsl:text>. </xsl:text>
		<fo:basic-link color="{$page.link.color}" internal-destination="tableOfIllustrations">
			<xsl:text>Table des illustrations</xsl:text>
		</fo:basic-link>
		<fo:leader leader-pattern="dots" leader-pattern-width="5pt"/>
		<fo:page-number-citation ref-id="tableOfIllustration" />
	</fo:block>
</xsl:template>

<xsl:template match="xhtml:div">
	<fo:block>
		<xsl:if test="@id='bibliographie'">
			<xsl:call-template name="bibliographie"/>
		</xsl:if>
	</fo:block>
</xsl:template>

<xsl:template name="bibliographie">
	<xsl:for-each select="xhtml:dl">
		<fo:list-item space-after="1em">
			<fo:list-item-label text-align="end" end-indent="label-end()">
				<fo:block>
					<xsl:text>•</xsl:text>
				</fo:block>
			</fo:list-item-label>
			<fo:list-item-body start-indent="body-start()">
				<fo:block>
					<xsl:for-each select="xhtml:dd[@class='nom']">
						<fo:inline font-variant="small-caps"><xsl:value-of select="."/></fo:inline>
						<xsl:text> (</xsl:text>
						<xsl:value-of select="following-sibling::xhtml:dd[@class='prenom']"/>
						<xsl:text>), </xsl:text>
					</xsl:for-each>
					<fo:inline font-style="italic"><xsl:value-of select="xhtml:dd[@class = 'titre']"/></fo:inline>
					<xsl:text>, </xsl:text>
					<xsl:for-each select="xhtml:dd[count(@class) = 0]">
						<xsl:apply-templates/>
						<!--<xsl:value-of select="."/>-->
						<xsl:if test="position() != last()">
							<xsl:text>, </xsl:text>
						</xsl:if>
					</xsl:for-each>
					<xsl:apply-templates select="xhtml:dd[@class = 'couverture']/*" />
				</fo:block>
			</fo:list-item-body>
		</fo:list-item>
	</xsl:for-each>
</xsl:template>

</xsl:stylesheet>