home *** CD-ROM | disk | FTP | other *** search
/ Maximum CD 2011 January / maximum-cd-2011-01.iso / DiscContents / calibre-0.7.26.msi / file_4467 < prev    next >
Encoding:
Extensible Markup Language  |  2010-10-29  |  12.8 KB  |  377 lines

  1. <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">
  2. <!--
  3. #########################################################################
  4. #                                                                       #
  5. #                                                                       #
  6. #   copyright 2002 Paul Henry Tremblay                                  #
  7. #                                                                       #
  8. #   This program is distributed in the hope that it will be useful,     #
  9. #   but WITHOUT ANY WARRANTY; without even the implied warranty of      #
  10. #   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU    #
  11. #   General Public License for more details.                            #
  12. #                                                                       #
  13. #   You should have received a copy of the GNU General Public License   #
  14. #   along with this program; if not, write to the Free Software         #
  15. #   Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA            #
  16. #   02111-1307 USA                                                      #
  17. #                                                                       #
  18. #                                                                       #
  19. #########################################################################
  20.  
  21. -->
  22.     <xsl:output method="xml" encoding="UTF-8"/>
  23.     <xsl:key name="note-link" match="fb:section" use="@id"/>
  24.     <xsl:template match="/*">
  25.         <html>
  26.             <head>
  27.                 <xsl:if test="fb:description/fb:title-info/fb:lang = 'ru'">
  28.                     <meta HTTP-EQUIV="content-type" CONTENT="text/html; charset=UTF-8"/>
  29.                 </xsl:if>
  30.                 <title>
  31.                     <xsl:value-of select="fb:description/fb:title-info/fb:book-title"/>
  32.                 </title>
  33.                 <style type="text/css">
  34.                     a { color : #0002CC }
  35.  
  36.                     a:hover { color : #BF0000 }
  37.                     
  38.                     body { background-color : #FEFEFE; color : #000000; font-family : Verdana, Geneva, Arial, Helvetica, sans-serif; text-align : justify }
  39.                     
  40.                     h1{ font-size : 160%; font-style : normal; font-weight : bold; text-align : left; border : 1px solid Black;  background-color : #E7E7E7; margin-left : 0px;  page-break-before : always; }
  41.                     
  42.                     h2{ font-size : 130%; font-style : normal; font-weight : bold; text-align : left; background-color : #EEEEEE;  border : 1px solid Gray;  page-break-before : always; }
  43.                     
  44.                     h3{ font-size : 110%; font-style : normal; font-weight : bold; text-align : left;  background-color : #F1F1F1;  border : 1px solid Silver;}
  45.                     
  46.                     h4{ font-size : 100%; font-style : normal; font-weight : bold; text-align : left; border : 1px solid Gray;  background-color : #F4F4F4;}
  47.                     
  48.                     h5{ font-size : 100%; font-style : italic; font-weight : bold; text-align : left; border : 1px solid Gray;  background-color : #F4F4F4;}
  49.                     
  50.                     h6{ font-size : 100%; font-style : italic; font-weight : normal; text-align : left; border : 1px solid Gray;  background-color : #F4F4F4;}
  51.                     
  52.                     small { font-size : 80% }
  53.                     
  54.                     blockquote { margin-left :4em; margin-top:1em; margin-right:0.2em;}
  55.                     
  56.                     hr { color : Black }
  57.                     
  58.                     div {font-family : "Times New Roman", Times, serif; text-align : justify}
  59.                     
  60.                     ul {margin-left: 0}
  61.                     
  62.                     .epigraph{width:50%; margin-left : 35%;}
  63.                     
  64.                     div.paragraph { text-align: justify; text-indent: 2em; }
  65.                 </style>
  66.                 <link rel="stylesheet" type="text/css" href="inline-styles.css" />
  67.             </head>
  68.             <body>
  69.                 <xsl:for-each select="fb:description/fb:title-info/fb:annotation">
  70.                     <div>
  71.                         <xsl:call-template name="annotation"/>
  72.                     </div>
  73.                     <hr/>
  74.                 </xsl:for-each>
  75.                 <!-- BUILD TOC -->
  76.                 <ul>
  77.                     <xsl:apply-templates select="fb:body" mode="toc"/>
  78.                 </ul>
  79.                 <hr/>
  80.                 <!-- END BUILD TOC -->
  81.                 <!-- BUILD BOOK -->
  82.                 <xsl:for-each select="fb:body">
  83.                     <xsl:if test="position()!=1">
  84.                         <hr/>
  85.                     </xsl:if>
  86.                     <xsl:if test="@name">
  87.                         <h4 align="center">
  88.                             <xsl:value-of select="@name"/>
  89.                         </h4>
  90.                     </xsl:if>
  91.                     <!-- <xsl:apply-templates /> -->
  92.                     <xsl:apply-templates/>
  93.                 </xsl:for-each>
  94.             </body>
  95.         </html>
  96.     </xsl:template>
  97.     <!-- author template -->
  98.     <xsl:template name="author">
  99.         <xsl:value-of select="fb:first-name"/>
  100.         <xsl:text disable-output-escaping="no"> </xsl:text>
  101.         <xsl:value-of select="fb:middle-name"/>
  102.          <xsl:text disable-output-escaping="no"> </xsl:text>
  103.         <xsl:value-of select="fb:last-name"/>
  104.         <br/>
  105.     </xsl:template>
  106.     <!-- secuence template -->
  107.     <xsl:template name="sequence">
  108.         <LI/>
  109.         <xsl:value-of select="@name"/>
  110.         <xsl:if test="@number">
  111.             <xsl:text disable-output-escaping="no">, #</xsl:text>
  112.             <xsl:value-of select="@number"/>
  113.         </xsl:if>
  114.         <xsl:if test="fb:sequence">
  115.             <ul>
  116.                 <xsl:for-each select="fb:sequence">
  117.                     <xsl:call-template name="sequence"/>
  118.                 </xsl:for-each>
  119.             </ul>
  120.         </xsl:if>
  121.         <!--      <br/> -->
  122.     </xsl:template>
  123.     <!-- toc template -->
  124.     <xsl:template match="fb:section|fb:body" mode="toc">
  125.         <xsl:choose>
  126.             <xsl:when test="name()='body' and position()=1 and not(fb:title)">
  127.                 <xsl:apply-templates select="fb:section" mode="toc"/>
  128.             </xsl:when>
  129.             <xsl:otherwise>
  130.                 <li>
  131.                     <a href="#TOC_{generate-id()}"><xsl:value-of select="normalize-space(fb:title/fb:p[1] | @name)"/></a>
  132.                     <xsl:if test="fb:section">
  133.                         <ul><xsl:apply-templates select="fb:section" mode="toc"/></ul>
  134.                     </xsl:if>
  135.                 </li>
  136.             </xsl:otherwise>
  137.         </xsl:choose>
  138.     </xsl:template>
  139.     <!-- description -->
  140.     <xsl:template match="fb:description">
  141.         <xsl:apply-templates/>
  142.     </xsl:template>
  143.     <!-- body -->
  144.     <xsl:template match="fb:body">
  145.         <div><xsl:apply-templates/></div>
  146.     </xsl:template>
  147.  
  148.     <xsl:template match="fb:section">
  149.         <xsl:variable name="section_has_title">
  150.             <xsl:choose>
  151.                 <xsl:when test="./fb:title"><xsl:value-of select="generate-id()" /></xsl:when>
  152.                 <xsl:otherwise>None</xsl:otherwise>
  153.             </xsl:choose>
  154.         </xsl:variable>
  155.         <xsl:if test="$section_has_title = 'None'">
  156.             <div id="TOC_{generate-id()}">
  157.                 <xsl:if test="@id">
  158.                     <xsl:element name="a">
  159.                         <xsl:attribute name="id"><xsl:value-of select="@id"/></xsl:attribute>
  160.                     </xsl:element>
  161.                 </xsl:if>
  162.             </div>
  163.         </xsl:if>
  164.         <xsl:apply-templates>
  165.             <xsl:with-param name="section_toc_id" select="$section_has_title" />
  166.         </xsl:apply-templates>
  167.     </xsl:template>
  168.     
  169.     
  170.     <!-- section/title -->
  171.     <xsl:template match="fb:section/fb:title|fb:poem/fb:title">
  172.         <xsl:param name="section_toc_id" />
  173.         <xsl:choose>
  174.             <xsl:when test="count(ancestor::node()) < 9">
  175.                 <xsl:element name="{concat('h',count(ancestor::node())-3)}">
  176.                     <xsl:if test="../@id">
  177.                         <xsl:attribute name="id"><xsl:value-of select="../@id" /></xsl:attribute>
  178.                     </xsl:if>
  179.                     <xsl:if test="$section_toc_id != 'None'">
  180.                         <xsl:element name="a">
  181.                             <xsl:attribute name="id">TOC_<xsl:value-of select="$section_toc_id"/></xsl:attribute>
  182.                         </xsl:element>
  183.                     </xsl:if>
  184.                     <a name="TOC_{generate-id()}"></a>
  185.                     <xsl:if test="@id">
  186.                         <xsl:element name="a">
  187.                             <xsl:attribute name="id"><xsl:value-of select="@id"/></xsl:attribute>
  188.                         </xsl:element>
  189.                     </xsl:if>
  190.                     <xsl:apply-templates/>
  191.                 </xsl:element>
  192.             </xsl:when>
  193.             <xsl:otherwise>
  194.                 <xsl:element name="h6">
  195.                     <xsl:if test="@id">
  196.                         <xsl:element name="a">
  197.                             <xsl:attribute name="id"><xsl:value-of select="@id"/></xsl:attribute>
  198.                         </xsl:element>
  199.                     </xsl:if>
  200.                     <xsl:apply-templates/>
  201.                 </xsl:element>
  202.             </xsl:otherwise>
  203.         </xsl:choose>
  204.     </xsl:template>
  205.     <!-- section/title -->
  206.     <xsl:template match="fb:body/fb:title">
  207.         <xsl:element name="h1">
  208.             <xsl:apply-templates />
  209.         </xsl:element>
  210.     </xsl:template>
  211.  
  212.     <xsl:template match="fb:title/fb:p">
  213.         <xsl:apply-templates/><xsl:text disable-output-escaping="no"> </xsl:text><br/>
  214.     </xsl:template>
  215.     <!-- subtitle -->
  216.     <xsl:template match="fb:subtitle">
  217.         <xsl:if test="@id">
  218.             <xsl:element name="a">
  219.                 <xsl:attribute name="name"><xsl:value-of select="@id"/></xsl:attribute>
  220.             </xsl:element>
  221.         </xsl:if>
  222.         <h5>
  223.             <xsl:apply-templates/>
  224.         </h5>
  225.     </xsl:template>
  226.     <!-- p -->
  227.     <xsl:template match="fb:p">
  228.         <xsl:element name="div">
  229.             <xsl:attribute name="class">paragraph</xsl:attribute>
  230.             <xsl:if test="@id">
  231.                 <xsl:element name="a">
  232.                     <xsl:attribute name="name"><xsl:value-of select="@id"/></xsl:attribute>
  233.                 </xsl:element>
  234.             </xsl:if>
  235.             <xsl:if test="@style">
  236.                 <xsl:attribute name="style"><xsl:value-of select="@style"/></xsl:attribute>
  237.             </xsl:if>
  238.             <xsl:apply-templates/>
  239.         </xsl:element>
  240.     </xsl:template>
  241.     <!-- strong -->
  242.     <xsl:template match="fb:strong">
  243.         <b><xsl:apply-templates/></b>
  244.     </xsl:template>
  245.     <!-- emphasis -->
  246.     <xsl:template match="fb:emphasis">
  247.         <i>    <xsl:apply-templates/></i>
  248.     </xsl:template>
  249.     <!-- style -->
  250.     <xsl:template match="fb:style">
  251.         <span class="{@name}"><xsl:apply-templates/></span>
  252.     </xsl:template>
  253.     <!-- empty-line -->
  254.     <xsl:template match="fb:empty-line">
  255.         <br/>
  256.     </xsl:template>
  257.     <!-- link -->
  258.     <xsl:template match="fb:a">
  259.         <xsl:element name="a">
  260.             <xsl:attribute name="href"><xsl:value-of select="@xlink:href"/></xsl:attribute>
  261.             <xsl:attribute name="title">
  262.                 <xsl:choose>
  263.                     <xsl:when test="starts-with(@xlink:href,'#')"><xsl:value-of select="key('note-link',substring-after(@xlink:href,'#'))/fb:p"/></xsl:when>
  264.                     <xsl:otherwise><xsl:value-of select="key('note-link',@xlink:href)/fb:p"/></xsl:otherwise>
  265.                 </xsl:choose>
  266.             </xsl:attribute>
  267.             <xsl:choose>
  268.                 <xsl:when test="(@type) = 'note'">
  269.                     <sup>
  270.                         <xsl:apply-templates/>
  271.                     </sup>
  272.                 </xsl:when>
  273.                 <xsl:otherwise>
  274.                     <xsl:apply-templates/>
  275.                 </xsl:otherwise>
  276.             </xsl:choose>
  277.         </xsl:element>
  278.     </xsl:template>
  279.     <!-- annotation -->
  280.     <xsl:template name="annotation">
  281.         <xsl:if test="@id">
  282.             <xsl:element name="a">
  283.                 <xsl:attribute name="name"><xsl:value-of select="@id"/></xsl:attribute>
  284.             </xsl:element>
  285.         </xsl:if>
  286.         <h3>Annotation</h3>
  287.         <xsl:apply-templates/>
  288.     </xsl:template>
  289.     <!-- epigraph -->
  290.     <xsl:template match="fb:epigraph">
  291.         <blockquote class="epigraph">
  292.             <xsl:if test="@id">
  293.                 <xsl:element name="a">
  294.                     <xsl:attribute name="name"><xsl:value-of select="@id"/></xsl:attribute>
  295.                 </xsl:element>
  296.             </xsl:if>
  297.             <xsl:apply-templates/>
  298.         </blockquote>
  299.     </xsl:template>
  300.     <!-- epigraph/text-author -->
  301.     <xsl:template match="fb:epigraph/fb:text-author">
  302.         <blockquote>
  303.             <i><xsl:apply-templates/></i>
  304.         </blockquote>
  305.     </xsl:template>
  306.     <!-- cite -->
  307.     <xsl:template match="fb:cite">
  308.         <blockquote>
  309.         <xsl:if test="@id">
  310.             <xsl:element name="a">
  311.                 <xsl:attribute name="name"><xsl:value-of select="@id"/></xsl:attribute>
  312.             </xsl:element>
  313.         </xsl:if>
  314.         <xsl:apply-templates/>
  315.         </blockquote>
  316.     </xsl:template>
  317.     <!-- cite/text-author -->
  318.     <xsl:template match="fb:text-author">
  319.         <blockquote>
  320.         <i>    <xsl:apply-templates/></i></blockquote>
  321.     </xsl:template>
  322.     <!-- date -->
  323.     <xsl:template match="fb:date">
  324.         <xsl:choose>
  325.             <xsl:when test="not(@value)">
  326.                    <xsl:apply-templates/>
  327.                 <br/>
  328.             </xsl:when>
  329.             <xsl:otherwise>
  330.                    <xsl:value-of select="@value"/>
  331.                 <br/>
  332.             </xsl:otherwise>
  333.         </xsl:choose>
  334.     </xsl:template>
  335.     <!-- poem -->
  336.     <xsl:template match="fb:poem">
  337.         <blockquote>
  338.             <xsl:if test="@id">
  339.                 <xsl:element name="a">
  340.                     <xsl:attribute name="name"><xsl:value-of select="@id"/></xsl:attribute>
  341.                 </xsl:element>
  342.             </xsl:if>
  343.             <xsl:apply-templates/>
  344.         </blockquote>
  345.     </xsl:template>
  346.  
  347.     <!-- stanza -->
  348.     <xsl:template match="fb:stanza">
  349.         <xsl:apply-templates/>
  350.         <br/>
  351.     </xsl:template>
  352.     <!-- v -->
  353.     <xsl:template match="fb:v">
  354.         <xsl:if test="@id">
  355.             <xsl:element name="a">
  356.                 <xsl:attribute name="name"><xsl:value-of select="@id"/></xsl:attribute>
  357.             </xsl:element>
  358.         </xsl:if>
  359.         <xsl:apply-templates/><br/>
  360.     </xsl:template>
  361.     <!-- image -->
  362.     <xsl:template match="fb:image">
  363.         <div align="center">
  364.             <img border="1">
  365.                 <xsl:choose>
  366.                     <xsl:when test="starts-with(@xlink:href,'#')">
  367.                         <xsl:attribute name="src"><xsl:value-of select="substring-after(@xlink:href,'#')"/></xsl:attribute>
  368.                     </xsl:when>
  369.                     <xsl:otherwise>
  370.                         <xsl:attribute name="src"><xsl:value-of select="@xlink:href"/></xsl:attribute>
  371.                     </xsl:otherwise>
  372.                 </xsl:choose>
  373.             </img>
  374.         </div>
  375.     </xsl:template>
  376. </xsl:stylesheet>
  377.