home *** CD-ROM | disk | FTP | other *** search
/ Maximum CD 2011 July / maximum-cd-2011-07.iso / DiscContents / LibO_3.3.2_Win_x86_install_multi.exe / libreoffice1.cab / style_mapping_css.xsl < prev    next >
Encoding:
Extensible Markup Language  |  2010-12-01  |  13.9 KB  |  356 lines

  1. <?xml version="1.0" encoding="UTF-8"?>
  2. <!--
  3.  
  4.   DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
  5.   
  6.   Copyright 2000, 2010 Oracle and/or its affiliates.
  7.  
  8.   OpenOffice.org - a multi-platform office productivity suite
  9.  
  10.   This file is part of OpenOffice.org.
  11.  
  12.   OpenOffice.org is free software: you can redistribute it and/or modify
  13.   it under the terms of the GNU Lesser General Public License version 3
  14.   only, as published by the Free Software Foundation.
  15.  
  16.   OpenOffice.org is distributed in the hope that it will be useful,
  17.   but WITHOUT ANY WARRANTY; without even the implied warranty of
  18.   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  19.   GNU Lesser General Public License version 3 for more details
  20.   (a copy is included in the LICENSE file that accompanied this code).
  21.  
  22.   You should have received a copy of the GNU Lesser General Public License
  23.   version 3 along with OpenOffice.org.  If not, see
  24.   <http://www.openoffice.org/license.html>
  25.   for a copy of the LGPLv3 License.
  26.  
  27. -->
  28. <!--
  29.     For further documentation and updates visit http://xml.openoffice.org/odf2xhtml
  30. -->
  31. <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:chart="urn:oasis:names:tc:opendocument:xmlns:chart:1.0" xmlns:config="urn:oasis:names:tc:opendocument:xmlns:config:1.0" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:dom="http://www.w3.org/2001/xml-events" xmlns:dr3d="urn:oasis:names:tc:opendocument:xmlns:dr3d:1.0" xmlns:draw="urn:oasis:names:tc:opendocument:xmlns:drawing:1.0" xmlns:fo="urn:oasis:names:tc:opendocument:xmlns:xsl-fo-compatible:1.0" xmlns:form="urn:oasis:names:tc:opendocument:xmlns:form:1.0" xmlns:math="http://www.w3.org/1998/Math/MathML" xmlns:meta="urn:oasis:names:tc:opendocument:xmlns:meta:1.0" xmlns:number="urn:oasis:names:tc:opendocument:xmlns:datastyle:1.0" xmlns:office="urn:oasis:names:tc:opendocument:xmlns:office:1.0" xmlns:ooo="http://openoffice.org/2004/office" xmlns:oooc="http://openoffice.org/2004/calc" xmlns:ooow="http://openoffice.org/2004/writer" xmlns:script="urn:oasis:names:tc:opendocument:xmlns:script:1.0" xmlns:style="urn:oasis:names:tc:opendocument:xmlns:style:1.0" xmlns:svg="urn:oasis:names:tc:opendocument:xmlns:svg-compatible:1.0" xmlns:table="urn:oasis:names:tc:opendocument:xmlns:table:1.0" xmlns:text="urn:oasis:names:tc:opendocument:xmlns:text:1.0" xmlns:xforms="http://www.w3.org/2002/xforms" xmlns:xlink="http://www.w3.org/1999/xlink" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" exclude-result-prefixes="chart config dc dom dr3d draw fo form math meta number office ooo oooc ooow script style svg table text xforms xlink xsd xsi">
  32.  
  33.  
  34.     <!-- *** Properties with a 'fo:' prefix *** -->
  35.     <xsl:template match="@fo:background-color">
  36.         <xsl:text>background-color:</xsl:text>
  37.         <xsl:value-of select="."/>
  38.         <xsl:text>; </xsl:text>
  39.     </xsl:template>
  40.  
  41.     <xsl:template match="@fo:border | @fo:border-top | @fo:border-bottom | @fo:border-left | @fo:border-right">
  42.         <xsl:variable name="borderType" select="substring-after(name(), ':')"/>
  43.         <xsl:choose>
  44.             <xsl:when test=". = 'none'">
  45.                 <xsl:value-of select="$borderType"/>
  46.                 <xsl:text>-style:none; </xsl:text>
  47.             </xsl:when>
  48.             <xsl:otherwise>
  49.                 <xsl:variable name="borderWidth" select="substring-before(., ' ')"/>
  50.                 <xsl:variable name="borderStyle" select="substring-before(substring-after(., ' '), ' ')"/>
  51.                 <xsl:variable name="borderColor" select="substring-after(substring-after(., ' '), ' ')"/>
  52.  
  53.                <!-- More information at template 'round-up-border-width' -->
  54.                 <xsl:variable name="borderWidthFixed">
  55.                     <xsl:call-template name="round-up-border-width">
  56.                         <xsl:with-param name="borderWidth" select="$borderWidth"/>
  57.                         <xsl:with-param name="multiplier">
  58.                             <xsl:choose>
  59.                                 <xsl:when test="$borderStyle = 'double'">3</xsl:when>
  60.                                 <xsl:otherwise>1</xsl:otherwise>
  61.                             </xsl:choose>
  62.                         </xsl:with-param>
  63.                     </xsl:call-template>
  64.                 </xsl:variable>
  65.  
  66.                 <xsl:value-of select="$borderType"/>
  67.                 <xsl:text>-width:</xsl:text>
  68.                 <xsl:value-of select="$borderWidthFixed"/>
  69.                 <xsl:text>; </xsl:text>
  70.                 <xsl:value-of select="$borderType"/>
  71.                 <xsl:text>-style:</xsl:text>
  72.                 <xsl:value-of select="$borderStyle"/>
  73.                 <xsl:text>; </xsl:text>
  74.                 <xsl:value-of select="$borderType"/>
  75.                 <xsl:text>-color:</xsl:text>
  76.                 <xsl:value-of select="$borderColor"/>
  77.                 <xsl:text>; </xsl:text>
  78.             </xsl:otherwise>
  79.         </xsl:choose>
  80.     </xsl:template>
  81.  
  82.     <!-- NOTE: Still there have to be placed a <br clear='all' /> to disable the flow!!!!-->
  83.     <xsl:template match="@fo:clear">
  84.         <xsl:text>clear:both; </xsl:text>
  85.     </xsl:template>
  86.  
  87.     <!-- text-shadow is a CSS2 feature and yet not common used in user-agents -->
  88.     <xsl:template match="@fo:color |@svg:font-family |@fo:font-size |@fo:font-style |@fo:font-weight |@fo:text-indent |@fo:text-shadow">
  89.         <xsl:value-of select="substring-after(name(), ':')"/>
  90.         <xsl:text>:</xsl:text>
  91.         <xsl:value-of select="."/>
  92.         <xsl:text>; </xsl:text>
  93.     </xsl:template>
  94.  
  95.     <!-- Maps fo:margin as well fo:margin-top, fo:margin-bottom, fo:padding-left, fo:margin-right -->
  96.     <!-- Maps fo:padding as well fo:padding-top, fo:padding-bottom, fo:padding-left, fo:padding-right -->
  97.     <xsl:template match="@fo:letter-spacing | @fo:line-height | @fo:width |@fo:margin | @fo:margin-top | @fo:margin-bottom | @fo:margin-left | @fo:margin-right | @fo:padding | @fo:padding-top | @fo:padding-bottom | @fo:padding-left | @fo:padding-right">
  98.         <xsl:value-of select="substring-after(name(), ':')"/>
  99.         <xsl:text>:</xsl:text>
  100.         <!-- Map once erroneusly used inch shortage 'inch' to CSS shortage 'in' -->
  101.         <xsl:choose>
  102.             <xsl:when test="contains(., 'inch')">
  103.                 <xsl:value-of select="substring-before(.,'ch')"/>
  104.             </xsl:when>
  105.             <xsl:otherwise>
  106.                 <xsl:value-of select="."/>
  107.             </xsl:otherwise>
  108.         </xsl:choose>
  109.         <xsl:text>; </xsl:text>
  110.     </xsl:template>
  111.  
  112.     <xsl:template match="@fo:text-align">
  113.         <!-- 'important' is necessary as table cell value alignment is decided by runtime over the valuetype
  114.             Otherwise a table cell style-class would always be outnumbered by the run-time alignment value -->
  115.         <xsl:choose>
  116.             <xsl:when test="contains(., 'start')">
  117.                 <xsl:choose>
  118.                     <xsl:when test="parent::*/@style:writing-mode and contains(parent::*/@style:writing-mode, 'rl')">
  119.                         <xsl:text>text-align:right ! important; </xsl:text>
  120.                     </xsl:when>
  121.                     <xsl:otherwise>
  122.                         <xsl:text>text-align:left ! important; </xsl:text>
  123.                     </xsl:otherwise>
  124.                 </xsl:choose>
  125.             </xsl:when>
  126.             <xsl:when test="contains(., 'end')">
  127.                 <xsl:choose>
  128.                     <xsl:when test="parent::*/@style:writing-mode and contains(parent::*/@style:writing-mode, 'rl')">
  129.                         <xsl:text>text-align:left ! important;</xsl:text> 
  130.                     </xsl:when>
  131.                     <xsl:otherwise>
  132.                         <xsl:text>text-align:right ! important; </xsl:text>
  133.                     </xsl:otherwise>
  134.                 </xsl:choose>
  135.             </xsl:when>
  136.             <xsl:otherwise>
  137.                 <xsl:text>text-align:</xsl:text>
  138.                 <xsl:value-of select="."/>
  139.                 <xsl:text> ! important; </xsl:text>
  140.             </xsl:otherwise>
  141.         </xsl:choose>
  142.     </xsl:template>
  143.  
  144.     <xsl:template match="@style:vertical-align">
  145.         <xsl:choose>
  146.             <xsl:when test="contains(., 'bottom')">
  147.                 <xsl:text>vertical-align:bottom; </xsl:text>
  148.             </xsl:when>
  149.             <xsl:when test="contains(., 'middle')">
  150.                 <xsl:text>vertical-align:middle; </xsl:text>
  151.             </xsl:when>
  152.             <xsl:otherwise>
  153.                 <xsl:text>vertical-align:top; </xsl:text>
  154.             </xsl:otherwise>
  155.         </xsl:choose>
  156.     </xsl:template>
  157.  
  158. <!-- *** Properties with a 'style:' prefix *** -->
  159.     <!-- NOTE: Can 'inside' | 'from-inside' better be handled:
  160.     <!ATTLIST * style:horizontal-pos (from-left|left|center|right|from-inside|inside|outside)#IMPLIED>-->
  161.     <xsl:template match="@style:horizontal-pos">
  162.         <xsl:choose>
  163.             <xsl:when test=".='left'">
  164.                 <xsl:text>text-align:left; </xsl:text>
  165.             </xsl:when>
  166.             <xsl:when test=". = 'right'">
  167.                 <xsl:text>text-align:right; </xsl:text>
  168.             </xsl:when>
  169.             <xsl:when test=".='center'">
  170.                 <xsl:text>text-align:center; </xsl:text>
  171.             </xsl:when>
  172.             <!-- NOTE: currently other values are not used.
  173.                 If the property value is from-left or from-inside,
  174.                 the svg:x attribute associated with the frame element specifies
  175.                 the horizontal position of the frame.
  176.                 Otherwise the svg:x attribute is ignored for text documents.
  177.             -->
  178.         </xsl:choose>
  179.     </xsl:template>
  180.  
  181.     <xsl:template match="@style:column-width">
  182.         <xsl:text>width:</xsl:text>
  183.         <xsl:choose>
  184.             <!-- changing the distance measure: inch to in -->
  185.             <xsl:when test="contains(., 'inch')">
  186.                 <xsl:value-of select="substring-before(.,'ch')"/>
  187.             </xsl:when>
  188.             <xsl:otherwise>
  189.                 <xsl:value-of select="."/>
  190.             </xsl:otherwise>
  191.         </xsl:choose>
  192.         <xsl:text>; </xsl:text>
  193.     </xsl:template>
  194.  
  195.     <xsl:template match="@style:text-underline-style">
  196.         <xsl:text>text-decoration:</xsl:text>
  197.         <xsl:choose>
  198.             <!-- changing the distance measure: inch to in -->
  199.             <xsl:when test=".='none'">
  200.                 <xsl:text>none ! important</xsl:text>
  201.             </xsl:when>
  202.             <xsl:otherwise>
  203.                 <xsl:text>underline</xsl:text>
  204.             </xsl:otherwise>
  205.         </xsl:choose>
  206.         <xsl:text>; </xsl:text>
  207.     </xsl:template>
  208.  
  209.     <xsl:template match="@style:font-name">
  210.         <xsl:param name="globalData" />
  211.  
  212.         <xsl:text>font-family:</xsl:text>
  213.         <xsl:variable name="content" select="."/>
  214.         <xsl:variable name="quote">'</xsl:variable>
  215.         <xsl:variable name="fontName" select="$globalData/office:font-face-decls/style:font-face[@style:name=$content]/@svg:font-family" />
  216.         <xsl:value-of select="translate($fontName, $quote, '')"/>
  217.         <xsl:text>; </xsl:text>
  218.     </xsl:template>
  219.  
  220.     <xsl:template match="@style:row-height">
  221.         <xsl:text>height:</xsl:text>
  222.         <xsl:choose>
  223.             <!-- changing the distance measure: inch to in -->
  224.             <xsl:when test="contains(., 'inch')">
  225.                 <xsl:value-of select="substring-before(.,'ch')"/>
  226.             </xsl:when>
  227.             <xsl:otherwise>
  228.                 <xsl:value-of select="."/>
  229.             </xsl:otherwise>
  230.         </xsl:choose>
  231.         <xsl:text>; </xsl:text>
  232.     </xsl:template>
  233.  
  234.     <xsl:template match="@svg:strikethrough-position">
  235.         <xsl:if test="not(.='none')">
  236.             <xsl:text>text-decoration:line-through; </xsl:text>
  237.         </xsl:if>
  238.     </xsl:template>
  239.     <xsl:template match="@style:text-position">
  240.         <xsl:if test="contains(., 'sub')">
  241.             <xsl:text>vertical-align:sub; </xsl:text>
  242.             <xsl:if test="contains(., '%')">
  243.                 <xsl:text>font-size:</xsl:text>
  244.                 <xsl:value-of select="substring-after(., 'sub ')"/>
  245.                 <xsl:text>;</xsl:text>
  246.             </xsl:if>
  247.         </xsl:if>
  248.         <xsl:if test="contains(., 'super')">
  249.             <xsl:text>vertical-align:super; </xsl:text>
  250.             <xsl:if test="contains(., '%')">
  251.                 <xsl:text>font-size:</xsl:text>
  252.                 <xsl:value-of select="substring-after(., 'super ')"/>
  253.                 <xsl:text>;</xsl:text>
  254.             </xsl:if>
  255.         </xsl:if>
  256.     </xsl:template>
  257.  
  258.     <xsl:template match="@style:vertical-pos">
  259.         <xsl:choose>
  260.             <xsl:when test=".='from-top'">
  261.                 <xsl:text>vertical-align:top; </xsl:text>
  262.             </xsl:when>
  263.             <xsl:otherwise>
  264.                 <xsl:text>vertical-align:</xsl:text>
  265.                 <xsl:value-of select="."/>
  266.                 <xsl:text>; </xsl:text>
  267.             </xsl:otherwise>
  268.         </xsl:choose>
  269.     </xsl:template>
  270.  
  271.     <xsl:template match="@style:width">
  272.         <xsl:text>width:</xsl:text>
  273.         <xsl:choose>
  274.             <!-- changing the distance measure: inch to in -->
  275.             <xsl:when test="contains(., 'inch')">
  276.                 <xsl:value-of select="substring-before(.,'ch')"/>
  277.             </xsl:when>
  278.             <xsl:otherwise>
  279.                 <xsl:value-of select="."/>
  280.             </xsl:otherwise>
  281.         </xsl:choose>
  282.         <xsl:text>; </xsl:text>
  283.     </xsl:template>
  284.     <xsl:template match="@style:wrap">
  285.         <xsl:choose>
  286.             <xsl:when test=".='left'">
  287.                 <xsl:text>float:right; </xsl:text>
  288.             </xsl:when>
  289.             <xsl:when test=".='right'">
  290.                 <xsl:text>float:left; </xsl:text>
  291.             </xsl:when>
  292.         </xsl:choose>
  293.     </xsl:template>
  294.     <xsl:template match="@style:writing-mode">
  295.         <xsl:text>writing-mode:</xsl:text>
  296.         <xsl:value-of select="."/>
  297.         <xsl:text>; </xsl:text>
  298.     </xsl:template>    
  299.     <!-- *** Properties with a no 'fo:' or 'style:' prefix *** -->
  300.     <xsl:template match="@table:align">
  301.         <xsl:choose>
  302.             <xsl:when test=".='left'">
  303.             <!-- Note: problems with meeting minutes example
  304.                 <xsl:text>float:right; </xsl:text> --></xsl:when>
  305.             <xsl:when test=".='right'">
  306.             <!-- Note: problems with meeting minutes example
  307.                 <xsl:text>float:left; </xsl:text> --></xsl:when>
  308.             <xsl:otherwise>
  309.                 <xsl:text>float:none; </xsl:text>
  310.             </xsl:otherwise>
  311.         </xsl:choose>
  312.     </xsl:template>
  313.  
  314.     <xsl:template match="style:background-image">
  315.         <xsl:text>background-image:url(</xsl:text>
  316.         <xsl:value-of select="@xlink:href"/>
  317.         <xsl:text>); </xsl:text>
  318.         <xsl:choose>
  319.             <xsl:when test="@style:repeat = 'repeat'">
  320.                 <xsl:text>background-repeat:repeat; </xsl:text>
  321.             </xsl:when>
  322.             <xsl:otherwise>
  323.                 <xsl:text>background-repeat:no-repeat; </xsl:text>
  324.             </xsl:otherwise>
  325.         </xsl:choose>
  326.     </xsl:template>
  327.  
  328.     <!-- Changing border width measure to cm and enlarging border-width to the Mozilla browser(1.7)
  329.          visible minimum width
  330.             - 0.0133cm for solid style
  331.             - 0.0399cm for double style
  332.          as there are three border lines painted -->
  333.     <xsl:template name="round-up-border-width">
  334.         <xsl:param name="borderWidth"/>
  335.         <xsl:param name="multiplier"/>
  336.  
  337.         <xsl:variable name="borderWidthByCentimeter">
  338.             <xsl:call-template name="convert2cm">
  339.                 <xsl:with-param name="value" select="$borderWidth"/>
  340.             </xsl:call-template>
  341.         </xsl:variable>
  342.         <xsl:variable name="minimalBorderWidth" select="0.0133 * $multiplier"/>
  343.         <xsl:choose>
  344.             <xsl:when test="number($borderWidthByCentimeter) < $minimalBorderWidth">
  345.                 <xsl:value-of select="$minimalBorderWidth"/>
  346.                 <xsl:text>cm</xsl:text>
  347.             </xsl:when>
  348.             <xsl:otherwise>
  349.                 <xsl:value-of select="$borderWidthByCentimeter"/>
  350.                 <xsl:text>cm</xsl:text>
  351.             </xsl:otherwise>
  352.         </xsl:choose>
  353.     </xsl:template>
  354. </xsl:stylesheet>
  355.  
  356.