<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:xlink="http://www.w3.org/1999/xlink" xmlns:fb="http://www.gribuser.ru/xml/fictionbook/2.0">
	<xsl:output method="text" encoding="windows-1251"/>
	<xsl:key name="note-link" match="fb:section|fb:p|fb:subtitle" use="@id"/>

	<xsl:template match="/">{\rtf1\ansi\ansicpg1251\deff0\deflang1049\deflangfe1049\deftab708{\fonttbl{\f0\fswiss\fprq2\fcharset204{\*\fname Arial;}Arial CYR;}{\f1\froman\fprq2\fcharset204{\*\fname Times New Roman;}Times New Roman CYR;}{\f2\fmodern\fprq1\fcharset204{\*\fname Courier New;}Courier New CYR;}}
{\stylesheet{ Normal;}{\s1 heading 1;}{\s2 heading 2;}{\s3 heading 3;}{\s4 heading 4;}{\s5 heading 5;}{\s6 heading 6;}}
\viewkind4\uc1\pard\keepn\s1\sb240\sa60\lang1033\kerning32\b\f0\fs32 

<xsl:value-of select="fb:description/fb:title-info/fb:book-title"/>\par
<xsl:for-each select="fb:description/fb:title-info/fb:author">
<xsl:call-template name="author"/>
</xsl:for-each>

<xsl:if test="fb:description/fb:title-info/fb:sequence">
<xsl:for-each select="fb:description/fb:title-info/fb:sequence">
<xsl:call-template name="sequence"/>
</xsl:for-each>
</xsl:if>
<xsl:for-each select="fb:description/fb:title-info/fb:annotation">\pard\keepn\s2\sb240\sa60\b\fs28 Annotation\par\b0
<xsl:call-template name="annotation"/>
</xsl:for-each>

<xsl:for-each select="fb:body">
<xsl:if test="position()!=1">
\par
</xsl:if>
<xsl:if test="@name">\pard\keepn\s3\sb240\sa60\i0\fs26 <xsl:value-of select="@name"/>\par
</xsl:if>
<xsl:apply-templates/>
</xsl:for-each>}
</xsl:template>


	<!-- author template -->
<xsl:template name="author">\pard\s5\sa600\kerning0\b0\i\fs26 <xsl:value-of select="fb:first-name"/>
<xsl:text disable-output-escaping="no">&#032;</xsl:text><xsl:value-of select="fb:middle-name"/>
<xsl:text disable-output-escaping="no">&#032;</xsl:text>
<xsl:value-of select="fb:last-name"/>\par
</xsl:template>
	<!-- secuence template -->
<xsl:template name="sequence">\pard\lang1033\b0\fs24 
<xsl:value-of select="@name"/>
<xsl:if test="@number">
<xsl:text disable-output-escaping="no">&#032;#</xsl:text>
<xsl:value-of select="@number"/>
</xsl:if>\par
<xsl:if test="fb:sequence">
<xsl:for-each select="fb:sequence">
<xsl:call-template name="sequence"/>
</xsl:for-each>
</xsl:if>
</xsl:template>

	<!-- annotation -->
<xsl:template name="annotation">
<xsl:apply-templates/>
</xsl:template>

<!-- description -->
<xsl:template match="fb:description">
<xsl:apply-templates/>
</xsl:template>
<!-- body -->
<xsl:template match="fb:body">
<xsl:apply-templates/>
</xsl:template>

<xsl:template match="fb:section">
<xsl:apply-templates/>
</xsl:template>
	
	
	<!-- section/title -->
<xsl:template match="fb:section/fb:title">
<xsl:choose>
<xsl:when test="count(ancestor::node()) &lt;= 3">
\pard\keepn\s2\sb240\sa60\b\f0\fs28 <xsl:apply-templates/>\par
</xsl:when>
<xsl:when test="count(ancestor::node()) = 4">
\pard\keepn\s3\sb240\sa60\i0\fs26  <xsl:apply-templates/>\par
</xsl:when>
<xsl:when test="count(ancestor::node()) = 5">
\pard\keepn\s4\sb240\sa60\lang1049\f1\fs28 <xsl:apply-templates/>\par
</xsl:when>
<xsl:when test="count(ancestor::node()) = 6">
\pard\s5\sb240\sa60\i\fs26 <xsl:apply-templates/>\par
</xsl:when>
<xsl:otherwise>
\pard\s6\sb240\sa60 <xsl:apply-templates/>\par
</xsl:otherwise>
</xsl:choose>
</xsl:template>

<!-- section/title -->
<xsl:template match="fb:body/fb:title">\pard\keepn\s1\sb240\sa60\lang1033\kerning32\b\f0\fs32<xsl:apply-templates/>\par
</xsl:template>

<xsl:template match="fb:title/fb:p|fb:epigraph/fb:p"><xsl:apply-templates/>\line </xsl:template>
<!-- subtitle -->
<xsl:template match="fb:subtitle">\pard\keepn\s4\sb240\sa60\lang1049\f1\fs28 <xsl:apply-templates/>\par
</xsl:template>
<!-- p -->
<xsl:template match="fb:p">\pard\qj\f1\fs24\b0 <xsl:apply-templates/>\par</xsl:template>
<!-- strong -->
<xsl:template match="fb:strong">\b <xsl:apply-templates/>\b0</xsl:template>
<!-- emphasis -->
<xsl:template match="fb:emphasis">\i <xsl:apply-templates/>\i0</xsl:template>
<!-- style -->
<xsl:template match="fb:style"><xsl:apply-templates/></xsl:template>
<!-- empty-line -->
<xsl:template match="fb:empty-line">\par
</xsl:template>
	<!-- link -->
	<xsl:template match="fb:a">
		<xsl:choose>
			<xsl:when test="(@type) = 'note'">
				<xsl:for-each select="key('note-link',@xlink:href)">
				[<xsl:apply-templates/>]
				</xsl:for-each>
			</xsl:when>
			<xsl:otherwise>
				<xsl:apply-templates/>
			</xsl:otherwise>
		</xsl:choose>
	</xsl:template>
	<!-- epigraph -->
<xsl:template match="fb:epigraph">\pard\li720\ri4749\b0\f1\fs24 <xsl:apply-templates/>\par
</xsl:template>
<!-- epigraph/text-author -->
<xsl:template match="fb:epigraph/fb:text-author">\pard\li900\ri3775\i <xsl:apply-templates/>\par
</xsl:template>
	<!-- cite -->
<xsl:template match="fb:cite">
"...\line
<xsl:apply-templates/>
<xsl:for-each select="fb:text-author">
<xsl:call-template name="text-author"/>
</xsl:for-each>
</xsl:template>
	<!-- cite/text-author -->
<xsl:template name="text-author">
\line\i <xsl:apply-templates/>\i0\line
</xsl:template>
	<!-- date -->
<xsl:template match="fb:date">
<xsl:choose>
<xsl:when test="not(@value)">
&#160;&#160;&#160;<xsl:apply-templates/>
\line
</xsl:when>
<xsl:otherwise>
&#160;&#160;&#160;<xsl:value-of select="@value"/>
\line
</xsl:otherwise>
</xsl:choose>
</xsl:template>
	<!-- poem -->
<xsl:template match="fb:poem"><xsl:apply-templates/></xsl:template>
<!-- poem/title -->
<xsl:template match="fb:poem/fb:title">\pard\keepn\s4\sb240\sa60\lang1049\f1\fs28 <xsl:apply-templates/>\par
</xsl:template>
<!-- stanza -->
<xsl:template match="fb:stanza"><xsl:apply-templates/>\par
</xsl:template>
<!-- v -->
<xsl:template match="fb:v">\pard\li720\f2 <xsl:apply-templates/>\par
</xsl:template>
</xsl:stylesheet>

