home *** CD-ROM | disk | FTP | other *** search
/ Chip 2011 November / CHIP_2011_11.iso / Programy / Narzedzia / Calibre / calibre-0.8.18.msi / file_561 < prev    next >
Extensible Markup Language  |  2011-05-02  |  17KB  |  476 lines

  1. <?xml version="1.0"?>
  2. <xsl:stylesheet version="1.0"
  3.     xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
  4.     xmlns:html="http://www.w3.org/1999/xhtml"
  5.     xmlns:rtf="http://rtf2xml.sourceforge.net/"
  6.     xmlns:c="calibre"
  7.     extension-element-prefixes="c"
  8.     exclude-result-prefixes="rtf"
  9. >
  10.  
  11.     <xsl:template match = "rtf:para">
  12.         <xsl:choose>
  13.             <xsl:when test = "parent::rtf:paragraph-definition[@name='heading 1']|
  14.                               parent::rtf:paragraph-definition[@name='heading 2']|
  15.                               parent::rtf:paragraph-definition[@name='heading 3']|
  16.                               parent::rtf:paragraph-definition[@name='heading 4']|
  17.                               parent::rtf:paragraph-definition[@name='heading 5']|
  18.                               parent::rtf:paragraph-definition[@name='heading 6']|
  19.                               parent::rtf:paragraph-definition[@name='heading 7']|
  20.                               parent::rtf:paragraph-definition[@name='heading 8']|
  21.                               parent::rtf:paragraph-definition[@name='heading 9']
  22.  
  23.             ">
  24.                 <xsl:variable name="head-number" select="substring(parent::rtf:paragraph-definition/@name, 9)"/>
  25.                 <xsl:element name="h{$head-number}">
  26.                     <xsl:apply-templates/>
  27.                 </xsl:element>
  28.             </xsl:when>
  29.             <xsl:otherwise>
  30.                 <xsl:call-template name = "para"/>
  31.             </xsl:otherwise>
  32.         </xsl:choose>
  33.     </xsl:template>
  34.  
  35.     <xsl:template match="rtf:style-group">
  36.         <xsl:apply-templates/>
  37.     </xsl:template>
  38.  
  39.     <xsl:template match="rtf:paragraph-definition">
  40.         <xsl:choose>
  41.             <xsl:when test = "parent::rtf:paragraph-definition[@name='heading 1']|
  42.                               parent::rtf:paragraph-definition[@name='heading 2']|
  43.                               parent::rtf:paragraph-definition[@name='heading 3']|
  44.                               parent::rtf:paragraph-definition[@name='heading 4']|
  45.                               parent::rtf:paragraph-definition[@name='heading 5']|
  46.                               parent::rtf:paragraph-definition[@name='heading 6']|
  47.                               parent::rtf:paragraph-definition[@name='heading 7']|
  48.                               parent::rtf:paragraph-definition[@name='heading 8']|
  49.                               parent::rtf:paragraph-definition[@name='heading 9']
  50.  
  51.             ">
  52.                 <xsl:apply-templates/>
  53.             </xsl:when>
  54.             <xsl:otherwise>
  55.                 <xsl:element name="div">
  56.                     <xsl:attribute name="class">
  57.                         <xsl:value-of select="@style-number"/>
  58.                     </xsl:attribute>
  59.                     <xsl:apply-templates/>
  60.                 </xsl:element>
  61.             </xsl:otherwise>
  62.         </xsl:choose>
  63.     </xsl:template>
  64.  
  65.     <xsl:template name = "para">
  66.         <xsl:if test = "normalize-space(.) or child::*">
  67.             <xsl:element name = "p">
  68.                 <xsl:call-template name = "para-content"/>
  69.             </xsl:element>
  70.         </xsl:if>
  71.     </xsl:template>
  72.  
  73.     <xsl:template name = "para_off">
  74.         <xsl:if test = "normalize-space(.) or child::*">
  75.             <xsl:element name = "p">
  76.                 <xsl:attribute name = "class">
  77.                     <xsl:value-of select = "../@style-number"/>
  78.                 </xsl:attribute>
  79.                 <xsl:call-template name = "para-content"/>
  80.             </xsl:element>
  81.         </xsl:if>
  82.     </xsl:template>
  83.  
  84.  
  85.     <xsl:template name = "para-content">
  86.         <xsl:apply-templates/>
  87.     </xsl:template>
  88.  
  89.     <xsl:template name = "para-content_off">
  90.         <xsl:choose>
  91.             <xsl:when test = "@italics = 'true' ">
  92.                <emph rend = "paragraph-emph-italics">
  93.                     <xsl:apply-templates/>
  94.                </emph>
  95.             </xsl:when>
  96.             <xsl:when test = "@bold = 'true' ">
  97.                <emph rend = "paragraph-emph-bold">
  98.                     <xsl:apply-templates/>
  99.                </emph>
  100.             </xsl:when>
  101.             <xsl:when test = "@underlined">
  102.                <emph rend = "paragraph-emph-underlined">
  103.                     <xsl:apply-templates/>
  104.                </emph>
  105.             </xsl:when>
  106.             <xsl:when test = "(@strike-through = 'true')
  107.                 or (@double-strike-through = 'true')
  108.                 or (@emboss = 'true')
  109.                 or (@engrave = 'true')
  110.                 or (@small-caps = 'true')
  111.                 or (@shadow = 'true')
  112.                 or (@hidden = 'true')
  113.                 or (@outline = 'true')
  114.                 ">
  115.                <emph rend = "paragraph-emph">
  116.                     <xsl:apply-templates/>
  117.                </emph>
  118.             </xsl:when>
  119.             <xsl:otherwise>
  120.                 <xsl:apply-templates/>
  121.             </xsl:otherwise>
  122.         </xsl:choose>
  123.     </xsl:template>
  124.  
  125.     <xsl:template name="make-header">
  126.         <head>
  127.             <xsl:element name="meta">
  128.                 <xsl:attribute name="name">
  129.                     <xsl:text>generator</xsl:text>
  130.                 </xsl:attribute>
  131.                 <xsl:attribute name="content">
  132.                     <xsl:text>http://calibre-ebook.com</xsl:text>
  133.                 </xsl:attribute>
  134.             </xsl:element>
  135.  
  136.             <xsl:choose>
  137.                 <xsl:when test="/rtf:doc/rtf:preamble/rtf:doc-information">
  138.                     <xsl:apply-templates select="/rtf:doc/rtf:preamble/rtf:doc-information" mode="header"/>
  139.                 </xsl:when>
  140.                 <xsl:otherwise>
  141.                     <xsl:call-template name="html-head"/>
  142.                 </xsl:otherwise>
  143.             </xsl:choose>
  144.         </head>
  145.     </xsl:template>
  146.  
  147.     <xsl:template match="rtf:doc-information"/>
  148.  
  149.     <xsl:template match="rtf:doc-information" mode="header">
  150.           <link rel="stylesheet" type="text/css" href="styles.css"/>
  151.           <xsl:if test="not(rtf:title)">
  152.               <title>unamed</title>
  153.           </xsl:if>
  154.         <xsl:apply-templates/>
  155.     </xsl:template>
  156.  
  157.     <xsl:template match="rtf:creation-time|rtf:doc-notes|rtf:author|rtf:revision-time">
  158.         <xsl:element name="meta">
  159.             <xsl:attribute name="name">
  160.                 <xsl:value-of select="name(.)"/>
  161.             </xsl:attribute>
  162.             <xsl:attribute name="content">
  163.                 <xsl:apply-templates/>
  164.             </xsl:attribute>
  165.         </xsl:element>
  166.     </xsl:template>
  167.  
  168.     <xsl:template match="rtf:creation-time|rtf:revision-time">
  169.         <xsl:element name="meta">
  170.             <xsl:attribute name="name">
  171.                 <xsl:value-of select="name(.)"/>
  172.             </xsl:attribute>
  173.             <xsl:attribute name="content">
  174.                 <xsl:value-of select="@year"/>
  175.                 <xsl:text>-</xsl:text>
  176.                 <xsl:value-of select="@month"/>
  177.                 <xsl:text>-</xsl:text>
  178.                 <xsl:value-of select="@day"/>
  179.             </xsl:attribute>
  180.         </xsl:element>
  181.     </xsl:template>
  182.  
  183.     <xsl:template match="rtf:operator|rtf:editing-time|rtf:number-of-pages|rtf:number-of-words|rtf:number-of-characters"/>
  184.  
  185.  
  186.     <xsl:template match="rtf:title">
  187.         <xsl:element name="title">
  188.             <xsl:apply-templates/>
  189.         </xsl:element>
  190.     </xsl:template>
  191.  
  192.  
  193.     <xsl:template name="html-head">
  194.         <title>unnamed</title>
  195.           <link rel="stylesheet" type="text/css" href="styles.css"/>
  196.     </xsl:template>
  197.  
  198.     <xsl:template name="make-css-stylesheet">
  199.         <xsl:document href="styles.css" method="text">
  200.             <xsl:for-each select="//rtf:paragraph-definition">
  201.                 <xsl:if test = "generate-id(.) = generate-id(key('style-types', @style-number))">
  202.                     <xsl:text>div.</xsl:text>
  203.                     <xsl:value-of select="@style-number"/>
  204.                     <xsl:text>{</xsl:text>
  205.                     <xsl:call-template name="parse-styles-attrs"/>
  206.                     <xsl:text>} </xsl:text>
  207.                 </xsl:if>
  208.             </xsl:for-each>
  209.             <xsl:text>span.italic{font-style:italic} </xsl:text>
  210.             <xsl:text>span.no-italic{font-style:normal} </xsl:text>
  211.             <xsl:text>span.bold{font-weight:bold} </xsl:text>
  212.             <xsl:text>span.no-bold{font-weight:normal} </xsl:text>
  213.             <xsl:text>span.underline{text-decoration:underline} </xsl:text>
  214.             <xsl:text>span.no-underline{text-decoration:none} </xsl:text>
  215.             <xsl:text>span.italic-bold{font-style:italic;font-weight:bold} </xsl:text>
  216.             <xsl:text>span.italic-underline{font-style:italic;text-decoration:underline} </xsl:text>
  217.             <xsl:text>span.bold-underline{font-weight:bold;text-decoration:underline} </xsl:text>
  218.             <xsl:text> </xsl:text>
  219.         </xsl:document>
  220.     </xsl:template>
  221.  
  222.     <xsl:template name="parse-styles-attrs">
  223.         <!--<xsl:text>position:relative;</xsl:text>-->
  224.         <xsl:if test="@space-before">
  225.             <xsl:text>padding-top:</xsl:text>
  226.             <xsl:value-of select="@space-before"/>
  227.             <xsl:text>pt;</xsl:text>
  228.         </xsl:if>
  229.         <xsl:if test="@space-after">
  230.             <xsl:text>padding-bottom:</xsl:text>
  231.             <xsl:value-of select="@space-after"/>
  232.             <xsl:text>pt;</xsl:text>
  233.         </xsl:if>
  234.         <xsl:if test="@left-indent">
  235.             <xsl:text>padding-left:</xsl:text>
  236.             <xsl:value-of select="@left-indent"/>
  237.             <xsl:text>pt;</xsl:text>
  238.         </xsl:if>
  239.         <xsl:if test="@right-indent">
  240.             <xsl:text>padding-right:</xsl:text>
  241.             <xsl:value-of select="@right-indent"/>
  242.             <xsl:text>pt;</xsl:text>
  243.         </xsl:if>
  244.         <xsl:if test="@first-line-indent">
  245.             <xsl:text>text-indent:</xsl:text>
  246.             <xsl:value-of select="@first-line-indent"/>
  247.             <xsl:text>pt;</xsl:text>
  248.         </xsl:if>
  249.         <xsl:if test="@bold='true'">
  250.             <xsl:text>font-weight:</xsl:text>
  251.             <xsl:value-of select="'bold'"/>
  252.             <xsl:text>;</xsl:text>
  253.         </xsl:if>
  254.         <xsl:if test="@italics='true'">
  255.             <xsl:text>font-style:</xsl:text>
  256.             <xsl:value-of select="'italic'"/>
  257.             <xsl:text>;</xsl:text>
  258.         </xsl:if>
  259.         <xsl:if test="@underline and @underline != 'false'">
  260.             <xsl:text>text-decoration:underline</xsl:text>
  261.             <xsl:text>;</xsl:text>
  262.         </xsl:if>
  263.         <xsl:if test="@line-spacing">
  264.             <xsl:text>line-height:</xsl:text>
  265.             <xsl:value-of select="@line-spacing"/>
  266.             <xsl:text>pt;</xsl:text>
  267.         </xsl:if>
  268.         <xsl:if test="(@align = 'just')">
  269.             <xsl:text>text-align: justify;</xsl:text>
  270.         </xsl:if>
  271.         <xsl:if test="(@align = 'cent')">
  272.             <xsl:text>text-align: center;</xsl:text>
  273.         </xsl:if>
  274.         <xsl:if test="(@align = 'left')">
  275.             <xsl:text>text-align: left;</xsl:text>
  276.         </xsl:if>
  277.         <xsl:if test="(@align = 'right')">
  278.             <xsl:text>text-align: right;</xsl:text>
  279.         </xsl:if>
  280.     </xsl:template>
  281.  
  282.     <xsl:template match="rtf:inline">
  283.         <xsl:variable name="num-attrs" select="count(@*)"/>
  284.         <xsl:choose>
  285.             <xsl:when test="@footnote-marker">
  286.                 <xsl:text>[</xsl:text>
  287.                 <xsl:value-of select="count(preceding::rtf:footnote) + 1"/>
  288.                 <xsl:text>]</xsl:text>
  289.             </xsl:when>
  290.             <xsl:when test="(@superscript)">
  291.                 <xsl:element name="sup">
  292.                     <xsl:element name="span">
  293.                         <xsl:attribute name="class">
  294.                             <c:inline-class/>
  295.                         </xsl:attribute>
  296.                         <xsl:apply-templates/>
  297.                     </xsl:element>
  298.                 </xsl:element>
  299.             </xsl:when>
  300.             <xsl:when test="(@underscript or @subscript)">
  301.                 <xsl:element name="sub">
  302.                     <xsl:element name="span">
  303.                         <xsl:attribute name="class">
  304.                             <c:inline-class/>
  305.                         </xsl:attribute>
  306.                         <xsl:apply-templates/>
  307.                     </xsl:element>
  308.                 </xsl:element>
  309.             </xsl:when>
  310.             <xsl:otherwise>
  311.                 <xsl:element name="span">
  312.                     <xsl:attribute name="class">
  313.                         <c:inline-class/>
  314.                     </xsl:attribute>
  315.                     <xsl:apply-templates/>
  316.                 </xsl:element>
  317.  
  318.             </xsl:otherwise>
  319.         </xsl:choose>
  320.     </xsl:template>
  321.  
  322.     <xsl:template match="rtf:footnote"/>
  323.  
  324.     <xsl:template match="rtf:footnote" mode="bottom">
  325.         <xsl:element name="div">
  326.             <xsl:attribute name="class">
  327.                 <xsl:text>footnote</xsl:text>
  328.             </xsl:attribute>
  329.             <xsl:apply-templates/>
  330.         </xsl:element>
  331.  
  332.     </xsl:template>
  333.  
  334.        <xsl:template match="rtf:list[@list-type='unordered']">
  335.        <xsl:element name="ul">
  336.            <xsl:apply-templates/>
  337.        </xsl:element>
  338.    </xsl:template>
  339.  
  340.    <xsl:template match="rtf:list[@list-type='ordered']">
  341.        <xsl:element name="ol">
  342.            <xsl:apply-templates/>
  343.        </xsl:element>
  344.    </xsl:template>
  345.  
  346.    <xsl:template match="rtf:item">
  347.        <xsl:element name="li">
  348.            <xsl:apply-templates/>
  349.        </xsl:element>
  350.    </xsl:template>
  351.  
  352.    <xsl:template match="rtf:item/rtf:style-group/rtf:paragraph-definition/rtf:para" priority="2">
  353.        <xsl:apply-templates/>
  354.    </xsl:template>
  355.  
  356.        <xsl:template match="rtf:table">
  357.         <xsl:element name="table">
  358.             <xsl:attribute name="id">
  359.                 <xsl:value-of select="generate-id(.)"/>
  360.             </xsl:attribute>
  361.             <xsl:apply-templates/>
  362.         </xsl:element>
  363.     </xsl:template>
  364.  
  365.     <xsl:template match="rtf:row">
  366.         <xsl:element name="tr">
  367.             <xsl:apply-templates/>
  368.         </xsl:element>
  369.     </xsl:template>
  370.  
  371.     <xsl:template match="rtf:cell">
  372.         <xsl:element name="td">
  373.             <xsl:if test="@class">
  374.                 <xsl:attribute name="class"><xsl:value-of select="@class"/></xsl:attribute>
  375.             </xsl:if>
  376.             <xsl:apply-templates/>
  377.         </xsl:element>
  378.     </xsl:template>
  379.  
  380.     <!--
  381.     <xsl:include href="blocks.xsl"/>
  382.     <xsl:include href="fields.xsl"/>
  383.     -->
  384.  
  385.  
  386.  
  387.  
  388.     <xsl:output method = "xml"/>
  389.  
  390.     <xsl:key name="style-types" match="rtf:paragraph-definition" use="@style-number"/>
  391.  
  392.  
  393.     <xsl:variable name = "delete-list-text">true</xsl:variable>
  394.     <xsl:variable name = "delete-field-blocks">true</xsl:variable>
  395.     <xsl:variable name = "delete-annotation">false</xsl:variable>
  396.  
  397.     <xsl:template match="/">
  398.         <xsl:call-template name="make-css-stylesheet"/>
  399.         <html>
  400.             <xsl:call-template name="make-header"/>
  401.             <xsl:apply-templates/>
  402.         </html>
  403.     </xsl:template>
  404.  
  405.     <xsl:template match="rtf:doc">
  406.         <xsl:apply-templates/>
  407.     </xsl:template>
  408.  
  409.     <xsl:template match="rtf:preamble">
  410.         <xsl:apply-templates/>
  411.     </xsl:template>
  412.  
  413.     <xsl:template match="rtf:page-break">
  414.         <xsl:element name="br">
  415.             <xsl:attribute name="style">page-break-after:always</xsl:attribute>
  416.         </xsl:element>
  417.     </xsl:template>
  418.     
  419.     <xsl:template match="rtf:hardline-break">
  420.         <xsl:element name="br"/>
  421.     </xsl:template>
  422.  
  423.     <xsl:template match="rtf:rtf-definition|rtf:font-table|rtf:color-table|rtf:style-table|rtf:page-definition|rtf:list-table|rtf:override-table|rtf:override-list|rtf:list-text"/>
  424.  
  425.     <xsl:template match="rtf:body">
  426.         <xsl:element name="body">
  427.             <xsl:apply-templates/>
  428.             <xsl:if test = "//rtf:footnote">
  429.                 <hr/>
  430.             </xsl:if>
  431.             <xsl:for-each select="//rtf:footnote">
  432.                 <xsl:apply-templates select="." mode="bottom"/>
  433.             </xsl:for-each>
  434.         </xsl:element>
  435.     </xsl:template>
  436.  
  437.     <xsl:template match="rtf:section">
  438.         <xsl:element name="div">
  439.             <xsl:apply-templates/>
  440.         </xsl:element>
  441.     </xsl:template>
  442.  
  443.     <xsl:template match = "rtf:field-block">
  444.       <xsl:apply-templates/>
  445.     </xsl:template>
  446.  
  447.     <xsl:template match = "rtf:field[@type='hyperlink']">
  448.         <xsl:element name ="a">
  449.             <xsl:attribute name = "href">
  450.                <xsl:value-of select = "@link"/>
  451.             </xsl:attribute>
  452.             <xsl:apply-templates/>
  453.         </xsl:element>
  454.     </xsl:template>
  455.  
  456.     <xsl:template match = "rtf:field">
  457.         <xsl:apply-templates/>
  458.     </xsl:template>
  459.  
  460.     <xsl:template match="rtf:pict">
  461.         <xsl:element name="img">
  462.             <xsl:attribute name="src"><xsl:value-of select="@num" /></xsl:attribute>
  463.         </xsl:element>
  464.     </xsl:template>
  465.  
  466.     <xsl:template match="*">
  467.         <xsl:message>
  468.             <xsl:text>no match for element: "</xsl:text>
  469.             <xsl:value-of select="name(.)"/>
  470.             <xsl:text>"  </xsl:text>
  471.         </xsl:message>
  472.         <xsl:apply-templates/>
  473.     </xsl:template>
  474.  
  475. </xsl:stylesheet>
  476.