1<?xml version="1.0" encoding="UTF-8"?>
2<!--***********************************************************
3 *
4 * Licensed to the Apache Software Foundation (ASF) under one
5 * or more contributor license agreements.  See the NOTICE file
6 * distributed with this work for additional information
7 * regarding copyright ownership.  The ASF licenses this file
8 * to you under the Apache License, Version 2.0 (the
9 * "License"); you may not use this file except in compliance
10 * with the License.  You may obtain a copy of the License at
11 *
12 *   http://www.apache.org/licenses/LICENSE-2.0
13 *
14 * Unless required by applicable law or agreed to in writing,
15 * software distributed under the License is distributed on an
16 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
17 * KIND, either express or implied.  See the License for the
18 * specific language governing permissions and limitations
19 * under the License.
20 *
21 ***********************************************************-->
22
23
24<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:fo="urn:oasis:names:tc:opendocument:xmlns:xsl-fo-compatible:1.0" xmlns:xlink="http://www.w3.org/1999/xlink" xmlns:w="http://schemas.microsoft.com/office/word/2003/wordml" xmlns:wx="http://schemas.microsoft.com/office/word/2003/auxHint" xmlns:o="urn:schemas-microsoft-com:office:office" xmlns:aml="http://schemas.microsoft.com/aml/2001/core" xmlns:dt="uuid:C2F41010-65B3-11d1-A29F-00AA00C14882" xmlns:v="urn:schemas-microsoft-com:vml" xmlns:office="urn:oasis:names:tc:opendocument:xmlns:office:1.0" xmlns:style="urn:oasis:names:tc:opendocument:xmlns:style:1.0" xmlns:text="urn:oasis:names:tc:opendocument:xmlns:text:1.0" xmlns:table="urn:oasis:names:tc:opendocument:xmlns:table:1.0" xmlns:w10="urn:schemas-microsoft-com:office:word" xmlns:draw="urn:oasis:names:tc:opendocument:xmlns:drawing:1.0" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:meta="urn:oasis:names:tc:opendocument:xmlns:meta:1.0" xmlns:number="urn:oasis:names:tc:opendocument:xmlns:datastyle:1.0" xmlns:svg="urn:oasis:names:tc:opendocument:xmlns:svg-compatible:1.0" xmlns:chart="urn:oasis:names:tc:opendocument:xmlns:chart:1.0" xmlns:dr3d="urn:oasis:names:tc:opendocument:xmlns:dr3d:1.0" xmlns:math="http://www.w3.org/1998/Math/MathML" xmlns:form="urn:oasis:names:tc:opendocument:xmlns:form:1.0" xmlns:script="urn:oasis:names:tc:opendocument:xmlns:script:1.0" xmlns:config="urn:oasis:names:tc:opendocument:xmlns:config:1.0" xmlns:ooo="http://openoffice.org/2004/office" xmlns:ooow="http://openoffice.org/2004/writer" xmlns:oooc="http://openoffice.org/2004/calc" xmlns:dom="http://www.w3.org/2001/xml-events" exclude-result-prefixes="office table style text draw svg   dc config xlink meta oooc dom ooo chart math dr3d form script ooow draw">
25    <!-- multiple usage: get size, type, color of table-cell, paragraph, and page borders. -->
26    <xsl:template name="get-border-size">
27        <xsl:param name="border"/>
28        <xsl:param name="border-line-width"/>
29        <xsl:choose>
30            <xsl:when test="$border = 'none' or $border = 'hidden'">
31                <xsl:text>none;0</xsl:text>
32            </xsl:when>
33            <xsl:otherwise>
34                <xsl:variable name="border-value">
35                    <xsl:call-template name="convert2cm">
36                        <xsl:with-param name="value" select="$border"/>
37                    </xsl:call-template>
38                </xsl:variable>
39                <xsl:variable name="border-style">
40                    <xsl:choose>
41                        <xsl:when test="contains($border,'solid')">solid</xsl:when>
42                        <xsl:when test="contains($border,'double')">double</xsl:when>
43                        <xsl:otherwise>none</xsl:otherwise>
44                    </xsl:choose>
45                </xsl:variable>
46                <!-- MS word and SO wirter borders Mapping
47				MS word Borders                         SO borders
48				w:val="single" w:sz="0"             		0.05pt(0.002cm);solid
49				w:val="single" w:sz="12"             		1.00pt(0.035cm);solid
50				w:val="single" w:sz="18"  					2.50pt(0.088cm);solid
51				w:val="single" w:sz="36" 						4.00pt(0.141cm);solid
52				w:val="single" w:sz="48"  						5.00pt(0.176cm);solid
53				w:val="double" w:sz="2"  						1.10pt(0.039cm);double
54				w:val="double" w:sz="6"  						2.60pt(0.092cm);double
55				w:val="thin-thick-small-gap" w:sz="12"        		  3.00pt(0.105cm);double
56				w:val="thin-thick-large-gap" w:sz="18"   			 3.55pt(0.125cm);double
57				w:val="thick-thin-medium-gap" w:sz="24" 		4.50pt(0.158cm);double
58				w:val="thin-thick-medium-gap" w:sz="24"		 5.05pt(0.178cm);double
59				w:val="thin-thick-small-gap" w:sz="24"			6.00pt(0.211cm);double
60				w:val="thin-thick-medium-gap" w:sz="36			" 6.55pt(0.231cm);double
61				w:val="double" w:sz="18" 						7.50pt(0.264cm);double
62				w:val="thin-thick-medium-gap" w:sz="48" 		9.00pt(0.317cm);double;style:border-line-width="0.088cm 0.088cm 0.141cm"
63				w:val="double" w:sz="24"						9.00pt(0.317cm);double;style:border-line-width="0.141cm 0.088cm 0.088cm"
64				we adjust the criteria by adding about 1/2 range of this current criteria and next criteria.  Gary. Yang -->
65                <xsl:variable name="microsoft-border-style-size">
66                    <xsl:choose>
67                        <xsl:when test=" $border-style = 'solid'">
68                            <xsl:choose>
69                                <xsl:when test="$border-value &lt;= 0.018">single;0</xsl:when>
70                                <xsl:when test="$border-value &lt;= 0.055">single;12</xsl:when>
71                                <xsl:when test="$border-value &lt;= 0.110">single;18</xsl:when>
72                                <xsl:when test="$border-value &lt;= 0.155">single;36</xsl:when>
73                                <xsl:when test="$border-value &lt;= 0.198">single;48</xsl:when>
74                                <xsl:otherwise>single;48</xsl:otherwise>
75                            </xsl:choose>
76                        </xsl:when>
77                        <xsl:when test="$border-style = 'double'">
78                            <xsl:choose>
79                                <xsl:when test="$border-value &lt; 0.064">double;2</xsl:when>
80                                <xsl:when test="$border-value &lt; 0.098">double;6</xsl:when>
81                                <xsl:when test="$border-value &lt; 0.115">thin-thick-small-gap;12</xsl:when>
82                                <xsl:when test="$border-value &lt; 0.135">thin-thick-large-gap;18</xsl:when>
83                                <xsl:when test="$border-value &lt; 0.168">thick-thin-medium-gap;24</xsl:when>
84                                <xsl:when test="$border-value &lt; 0.190">thin-thick-medium-gap;24</xsl:when>
85                                <xsl:when test="$border-value &lt; 0.221">thin-thick-small-gap;24</xsl:when>
86                                <xsl:when test="$border-value &lt; 0.241">thin-thick-medium-gap;36</xsl:when>
87                                <xsl:when test="$border-value &lt; 0.300">double;18</xsl:when>
88                                <xsl:when test="$border-value &lt; 0.430">
89                                    <xsl:variable name="border-inner-line-value">
90                                        <xsl:call-template name="convert2cm">
91                                            <xsl:with-param name="value" select="$border-line-width"/>
92                                        </xsl:call-template>
93                                    </xsl:variable>
94                                    <xsl:if test="$border-inner-line-value &lt; 0.10">thin-thick-medium-gap;48</xsl:if>
95                                    <xsl:if test="$border-inner-line-value &gt; 0.10">double;24</xsl:if>
96                                </xsl:when>
97                                <xsl:otherwise>double;24</xsl:otherwise>
98                            </xsl:choose>
99                        </xsl:when>
100                        <xsl:otherwise>none;0</xsl:otherwise>
101                    </xsl:choose>
102                </xsl:variable>
103                <xsl:value-of select="$microsoft-border-style-size"/>
104            </xsl:otherwise>
105        </xsl:choose>
106    </xsl:template>
107    <!-- get bottom and right border style, size, color  -->
108    <xsl:template name="get-border">
109        <xsl:param name="so-border"/>
110        <xsl:param name="so-border-line-width"/>
111        <xsl:param name="so-border-position"/>
112        <xsl:variable name="ms-style-width">
113            <xsl:call-template name="get-border-size">
114                <xsl:with-param name="border" select="$so-border"/>
115                <xsl:with-param name="border-line-width" select="$so-border-line-width"/>
116            </xsl:call-template>
117        </xsl:variable>
118        <xsl:choose>
119            <xsl:when test="$so-border-position = 'bottom' or $so-border-position = 'right'">
120                <!-- if border style is bottom or right border we need to change the thin-thick to thick-thin; Vice Versa -->
121                <xsl:choose>
122                    <xsl:when test="substring-before($ms-style-width, '-')='thin'">
123                        <xsl:attribute name="w:val"><xsl:value-of select="concat( 'thick-thin', substring-after(substring-before($ms-style-width, ';'), 'k' ))"/></xsl:attribute>
124                    </xsl:when>
125                    <xsl:when test="substring-before($ms-style-width, '-')='thick'">
126                        <xsl:attribute name="w:val"><xsl:value-of select="concat( 'thin-thick', substring-after(substring-before($ms-style-width, ';'), 'n' ))"/></xsl:attribute>
127                    </xsl:when>
128                    <xsl:otherwise>
129                        <xsl:attribute name="w:val"><xsl:value-of select="substring-before($ms-style-width, ';')"/></xsl:attribute>
130                    </xsl:otherwise>
131                </xsl:choose>
132                <xsl:attribute name="w:sz"><xsl:value-of select="substring-after($ms-style-width,';')"/></xsl:attribute>
133            </xsl:when>
134            <xsl:when test="$so-border-position = 'top' or $so-border-position = 'left'">
135                <xsl:attribute name="w:val"><xsl:value-of select="substring-before($ms-style-width,';')"/></xsl:attribute>
136                <xsl:attribute name="w:sz"><xsl:value-of select="substring-after($ms-style-width,';')"/></xsl:attribute>
137            </xsl:when>
138        </xsl:choose>
139        <!--get border color -->
140        <xsl:choose>
141            <xsl:when test="contains($so-border,'#')">
142                <xsl:attribute name="w:color"><xsl:value-of select="substring-after($so-border, '#')"/></xsl:attribute>
143            </xsl:when>
144            <xsl:otherwise>
145                <xsl:attribute name="w:color">auto</xsl:attribute>
146            </xsl:otherwise>
147        </xsl:choose>
148    </xsl:template>
149</xsl:stylesheet>
150