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