<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0">
<xsl:output method="xml" encoding="windows-1251"/>


<xsl:template match="*"/>

   <xsl:template match="/BOOK | /book | /ClearTXTeBook ">
	<FictionBook>
		<xsl:apply-templates />
        </FictionBook>
   </xsl:template>

<!-- DESCRIPTION -->

   <xsl:template match="DESCRIPTION | description">
	<description>
	  <title-info>
		<xsl:apply-templates select="GENRE | genre" />
		<xsl:apply-templates select="AUTHOR | author" />
	 	<book-title>
		   <xsl:value-of select="TITLE | title"/>
	        </book-title>
		<xsl:apply-templates select="ANNOTATION | annotation" />
		<xsl:if test="IMAGE">
		    <coverpage>
			<xsl:apply-templates select="IMAGE" />
        	    </coverpage>
		</xsl:if>

	  </title-info>
        </description>
   </xsl:template>

   <xsl:template match="GENRE | genre">
	<genre>
		<xsl:apply-templates />
        </genre>
   </xsl:template>

   <!-- AUTHOR -->
   <xsl:template match="AUTHOR | author">
	<author>
		<xsl:apply-templates />
        </author>
   </xsl:template>


   <xsl:template match="FIRST-NAME | first-name">
	<first-name>
		<xsl:apply-templates />
        </first-name>
   </xsl:template>

   <xsl:template match="MIDDLE-NAME | middle-name">
	<middle-name>
		<xsl:apply-templates />
        </middle-name>
   </xsl:template>

   <xsl:template match="LAST-NAME | last-name">
	<last-name>
		<xsl:apply-templates />
        </last-name>
   </xsl:template>


<!--
   <xsl:template match="TITLE | title">
	<book-title>
		<xsl:apply-templates />
        </book-title>
   </xsl:template>

-->

   <xsl:template match="annotation | ANNOTATION">
	<annotation>
		<xsl:if test="PARAGRAPH | P | EMPTYLINE | p | emptyline">
		    <xsl:apply-templates select="PARAGRAPH | P | EMPTYLINE | p | emptyline"/>
		<!--
	            <xsl:for-each select="PARAGRAPH | P | EMPTYLINE | p | emptyline">
			<p><xsl:apply-templates /></p>
	            </xsl:for-each>
		-->
		</xsl:if>
		<xsl:if test="not(PARAGRAPH | P | EMPTYLINE | p | emptyline)">
		  <p>
		    <xsl:value-of select="."/>
		    <!--  <xsl:apply-templates select="ANNOTATION | annotation"/> -->
		    <!-- <xsl:copy-of select="ANNOTATION | annotation"/> -->
		  </p>
		</xsl:if>
        </annotation>
   </xsl:template>




<!-- BODY -->

   <xsl:template match="BODY | body">
	<body>
		<xsl:apply-templates />
        </body>
   </xsl:template>

   <xsl:template match="PART | part | CHAPTER | chapter">
	<xsl:if test="@title">
	    <xsl:element name = "section">
	        <xsl:attribute name = "title" >
                    <xsl:value-of select="@title"/>
                </xsl:attribute>
		<xsl:apply-templates />
	    </xsl:element>
	</xsl:if>
	<xsl:if test="@TITLE">
	    <xsl:element name = "section">
	        <xsl:attribute name = "title" >
                    <xsl:value-of select="@TITLE"/>
                </xsl:attribute>
		<xsl:apply-templates />
	    </xsl:element>
	</xsl:if>
	<xsl:if test="not(@title | @TITLE)">
	      <section title="">
		<xsl:apply-templates />
      	      </section>
	</xsl:if>
   </xsl:template>



   <xsl:template match="EPIGRAPH | epigraph">
	<epigraph>
	    <p>
		<xsl:apply-templates />
            </p>
            <xsl:for-each select="EPIGRAPHAUTHOR | epigraphauthor">
	      <text-author>
		<xsl:apply-templates />
	      </text-author>
            </xsl:for-each>
        </epigraph>
   </xsl:template>

   <xsl:template match="SUBHEADING | subheading">
	<subtitle>
		<xsl:apply-templates />
        </subtitle>
   </xsl:template>


   <xsl:template match="NOTE | note">
	<xsl:if test="@name | @NAME">
	    <xsl:element name = "note">
	        <xsl:attribute name = "name" >
                    <xsl:value-of select="@name | @NAME"/>
                </xsl:attribute>
		<p><xsl:apply-templates /></p>
	    </xsl:element>
	</xsl:if>
	<xsl:if test="not(@name | @NAME)">
	      <note name="*">
		<xsl:apply-templates />
      	      </note>
	</xsl:if>
   </xsl:template>



   <xsl:template match="EMPTYLINE | emptyline">
	<empty-line>
		<!--
		<xsl:apply-templates />
		-->
        </empty-line>
   </xsl:template>


   <xsl:template match="PAGEBREAK | pagebreak">
		<!--
	<empty-line>
        </empty-line>
		-->
   </xsl:template>


   <xsl:template match="IMAGE | image">
	    <xsl:element name = "image">
	        <xsl:attribute name = "name" >
                    <xsl:value-of select="@name | @NAME"/>
                </xsl:attribute>
	    </xsl:element>
   </xsl:template>



   <xsl:template match="STANZA | stanza">
	<poem>
            <xsl:for-each select="P | p">
	      <!--
	      <stanza>
		<xsl:apply-templates />
	      </stanza>
	      -->
	      <v>
		<xsl:apply-templates />
	      </v>
            </xsl:for-each>
        </poem>
   </xsl:template>

	
   <xsl:template match="EMPHASIS | emphasis">
	<emphasis>
		<xsl:apply-templates />
        </emphasis>
   </xsl:template>


   <xsl:template match="P | p | PARAGRAPH | paragraph">
	<p>
		<xsl:apply-templates />
        </p>
   </xsl:template>

   <xsl:template match="BINARY">
	<xsl:element name = "binary">
	    <xsl:attribute name = "name" >
                    <xsl:value-of select="@name | @NAME"/>
	    </xsl:attribute>
	    <xsl:apply-templates />
	</xsl:element>
   </xsl:template>

   <xsl:template match="binary">
	<binary name="">
		<xsl:apply-templates />
        </binary>
   </xsl:template>


</xsl:stylesheet>


