home *** CD-ROM | disk | FTP | other *** search
/ PC World 2004 October / PCWorld_2004-10_cd.bin / akce / openoffice / f_0394 / table.xsl
Text File  |  2003-04-04  |  18KB  |  329 lines

  1. <!--
  2.  
  3.    The Contents of this file are made available subject to the terms of
  4.    either of the following licenses
  5.  
  6.           - GNU Lesser General Public License Version 2.1
  7.           - Sun Industry Standards Source License Version 1.1
  8.  
  9.    Sun Microsystems Inc., October, 2000
  10.  
  11.    GNU Lesser General Public License Version 2.1
  12.    =============================================
  13.    Copyright 2000 by Sun Microsystems, Inc.
  14.    901 San Antonio Road, Palo Alto, CA 94303, USA
  15.  
  16.    This library is free software; you can redistribute it and/or
  17.    modify it under the terms of the GNU Lesser General Public
  18.    License version 2.1, as published by the Free Software Foundation.
  19.  
  20.    This library is distributed in the hope that it will be useful,
  21.    but WITHOUT ANY WARRANTY; without even the implied warranty of
  22.    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
  23.    Lesser General Public License for more details.
  24.  
  25.    You should have received a copy of the GNU Lesser General Public
  26.    License along with this library; if not, write to the Free Software
  27.    Foundation, Inc., 59 Temple Place, Suite 330, Boston,
  28.    MA  02111-1307  USA
  29.  
  30.  
  31.    Sun Industry Standards Source License Version 1.1
  32.    =================================================
  33.    The contents of this file are subject to the Sun Industry Standards
  34.    Source License Version 1.1 (the "License"); You may not use this file
  35.    except in compliance with the License. You may obtain a copy of the
  36.    License at http://www.openoffice.org/license.html.
  37.  
  38.    Software provided under this License is provided on an "AS IS" basis,
  39.    WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESS OR IMPLIED, INCLUDING,
  40.    WITHOUT LIMITATION, WARRANTIES THAT THE SOFTWARE IS FREE OF DEFECTS,
  41.    MERCHANTABLE, FIT FOR A PARTICULAR PURPOSE, OR NON-INFRINGING.
  42.    See the License for the specific provisions governing your rights and
  43.    obligations concerning the Software.
  44.  
  45.    The Initial Developer of the Original Code is: Sun Microsystems, Inc.
  46.  
  47.    Copyright ┬⌐ 2002 by Sun Microsystems, Inc.
  48.  
  49.    All Rights Reserved.
  50.  
  51.    Contributor(s): _______________________________________
  52.  
  53. -->
  54. <xsl:stylesheet version="1.0"
  55.                 xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
  56.                 xmlns:office="http://openoffice.org/2000/office"
  57.                 xmlns:style="http://openoffice.org/2000/style"
  58.                 xmlns:text="http://openoffice.org/2000/text"
  59.                 xmlns:table="http://openoffice.org/2000/table"
  60.                 xmlns:draw="http://openoffice.org/2000/drawing"
  61.                 xmlns:fo="http://www.w3.org/1999/XSL/Format"
  62.                 xmlns:xlink="http://www.w3.org/1999/xlink"
  63.                 xmlns:number="http://openoffice.org/2000/datastyle"
  64.                 xmlns:svg="http://www.w3.org/2000/svg"
  65.                 xmlns:chart="http://openoffice.org/2000/chart"
  66.                 xmlns:dr3d="http://openoffice.org/2000/dr3d"
  67.                 xmlns:math="http://www.w3.org/1998/Math/MathML"
  68.                 xmlns:form="http://openoffice.org/2000/form"
  69.                 xmlns:script="http://openoffice.org/2000/script"
  70.                 office:class="text"
  71.                 office:version="1.0"
  72.                 xmlns:dc="http://purl.org/dc/elements/1.1/"
  73.                 xmlns:meta="http://openoffice.org/2000/meta"
  74.                 xmlns:config="http://openoffice.org/2001/config"
  75.                 xmlns:help="http://openoffice.org/2000/help"
  76.                 xmlns:xt="http://www.jclark.com/xt"
  77.                 xmlns:system="http://www.jclark.com/xt/java/java.lang.System"
  78.                 xmlns:xalan="http://xml.apache.org/xalan"
  79.                 xmlns:java="http://xml.apache.org/xslt/java"
  80.                 exclude-result-prefixes="java">
  81.  
  82.  
  83.     <!-- table row handling -->
  84.     <xsl:include href="table_rows.xsl"/>
  85.     <!-- table column handling -->
  86.     <xsl:include href="table_columns.xsl"/>
  87.     <!-- table cell handling -->
  88.     <xsl:include href="table_cells.xsl"/>
  89.  
  90.  
  91.  
  92.     <!-- ******************* -->
  93.     <!-- *** main table  *** -->
  94.     <!-- ******************* -->
  95.  
  96.     <xsl:template match="table:table | table:sub-table">
  97.         <xsl:param name="collectedGlobalData"/>
  98.  
  99.         <!-- a table will only be created if the "scenario" is active -->
  100.         <xsl:if test="string-length(table:scenario/@table:is-active) = 0">
  101.             <!-- collecting all visible "table:table-row" elements of the table -->
  102.             <xsl:variable name="allVisibleTableRows" select="table:table-row[not(@table:visibility = 'collapse' or @table:visibility = 'filter')]
  103.                     |    table:table-header-rows/descendant::table:table-row[not(@table:visibility = 'collapse' or @table:visibility = 'filter')]
  104.                     |    table:table-row-group/descendant::table:table-row[not(@table:visibility = 'collapse' or @table:visibility = 'filter')]"/>
  105.             <xsl:choose>
  106.                 <!-- for all but WAP/WML devices a table border check is done (cp. "check-for-table-border") -->
  107.                 <xsl:when test="not($outputType = 'WML')">
  108.  
  109.                     <!-- As the alignment of a table is by 'align' attribut is deprecated and as the CSS 'float' attribute not well displayed,
  110.                          we do a little trick by encapsulating the table with a aligned 'div' element-->
  111.                     <xsl:variable name="table-alignment" select="$office:automatic-styles/style:style[@style:name = current()/@table:style-name]/style:properties/@table:align"/>
  112.  
  113.                     <xsl:choose>
  114.                         <xsl:when test="string-length($table-alignment) != 0">
  115.                             <xsl:element name="div">
  116.                                 <xsl:attribute name="align">
  117.                                     <xsl:choose>
  118.                                         <xsl:when test='$table-alignment="left" or $table-alignment="margins"'>
  119.                                                 <xsl:text>left</xsl:text>
  120.                                         </xsl:when>
  121.                                         <xsl:when test='$table-alignment="right"'>
  122.                                             <xsl:text>right</xsl:text>
  123.                                         </xsl:when>
  124.                                         <xsl:when test='$table-alignment="center"'>
  125.                                             <xsl:text>center</xsl:text>
  126.                                         </xsl:when>
  127.                                     </xsl:choose>
  128.                                 </xsl:attribute>
  129.                                 <xsl:element name="table">
  130.  
  131.                                     <xsl:apply-templates select="@table:style-name">
  132.                                         <xsl:with-param name="collectedGlobalData" select="$collectedGlobalData"/>
  133.                                     </xsl:apply-templates>
  134.  
  135.                                     <!-- workaround, set table border attribut if any cell-border exists
  136.                                     <xsl:call-template name="check-for-table-border">
  137.                                         <xsl:with-param name="allVisibleTableRows" select="$allVisibleTableRows"/>
  138.                                     </xsl:call-template> -->
  139.                                     <xsl:call-template name="create-column-style-variable">
  140.                                         <xsl:with-param name="allVisibleTableRows" select="$allVisibleTableRows"/>
  141.                                         <xsl:with-param name="collectedGlobalData" select="$collectedGlobalData"/>
  142.                                     </xsl:call-template>
  143.                                 </xsl:element>
  144.                             </xsl:element>
  145.                         </xsl:when>
  146.                         <xsl:otherwise>
  147.                             <xsl:element name="table">
  148.                                 <xsl:apply-templates select="@table:style-name">
  149.                                     <xsl:with-param name="collectedGlobalData" select="$collectedGlobalData"/>
  150.                                 </xsl:apply-templates>
  151.  
  152.                                 <!-- workaround, set table border attribut if any cell-border exists
  153.                                 <xsl:call-template name="check-for-table-border">
  154.                                     <xsl:with-param name="allVisibleTableRows" select="$allVisibleTableRows"/>
  155.                                 </xsl:call-template>  -->
  156.                                 <xsl:call-template name="create-column-style-variable">
  157.                                     <xsl:with-param name="allVisibleTableRows" select="$allVisibleTableRows"/>
  158.                                      <xsl:with-param name="collectedGlobalData" select="$collectedGlobalData"/>
  159.                                 </xsl:call-template>
  160.                             </xsl:element>
  161.                         </xsl:otherwise>
  162.                     </xsl:choose>
  163.  
  164.                 </xsl:when>
  165.                 <xsl:otherwise>
  166.                 <!-- for WML devices only ASCII table are written as tables are not implemented widley.
  167.                      Beginning from 'repeat-write-row' the templates are handled by the table_wml.xsl stylesheet -->
  168.                     <xsl:call-template name="create-column-style-variable">
  169.                         <xsl:with-param name="collectedGlobalData"   select="$collectedGlobalData"/>
  170.                         <xsl:with-param name="allVisibleTableRows"  select="$allVisibleTableRows"/>
  171.                     </xsl:call-template>
  172.                 </xsl:otherwise>
  173.             </xsl:choose>
  174.         </xsl:if>
  175.     </xsl:template>
  176.  
  177.  
  178.  
  179.     <xsl:template name="create-column-style-variable">
  180.         <xsl:param name="collectedGlobalData"/>
  181.         <xsl:param name="allVisibleTableRows"/>
  182.  
  183.         <!-- all columns of the table -->
  184.         <xsl:variable name="allTableColumns" select="table:table-column |
  185.                                                      table:table-column-group/descendant::table:table-column |
  186.                                                      table:table-header-columns/descendant::table:table-column"/>
  187.         <!-- allColumnStyleEntries: Containing all columns of the table, hidden and viewed.
  188.             - if a column is hidden, it contains the hidden attribute, otherwise the style-properties will be stored
  189.             - if a column is being repeated, each repeated column is explicitly written as entry in this variable.
  190.               Later (during template "write-cell") the style of the column will be mixed with the cell-style by using
  191.               the position() of the column entry and comparing it with the iterating cell number. -->
  192.         <xsl:variable name="allColumnStyleEntries-RTF">
  193.             <xsl:call-template name="adding-column-styles-entries">
  194.                 <xsl:with-param name="collectedGlobalData"   select="$collectedGlobalData"/>
  195.                 <xsl:with-param name="allTableColumns"      select="$allTableColumns"/>
  196.             </xsl:call-template>
  197.         </xsl:variable>
  198.  
  199.         <xsl:choose>
  200.             <xsl:when test="function-available('xt:node-set')">
  201.                 <xsl:call-template name="create-table">
  202.                     <xsl:with-param name="collectedGlobalData"       select="$collectedGlobalData"/>
  203.                     <xsl:with-param name="allVisibleTableRows"      select="$allVisibleTableRows"/>
  204.                     <xsl:with-param name="allColumnStyleEntries"    select="xt:node-set($allColumnStyleEntries-RTF)"/>
  205.                 </xsl:call-template>
  206.             </xsl:when>
  207.             <xsl:when test="function-available('xalan:nodeset')">
  208.                 <xsl:call-template name="create-table">
  209.                     <xsl:with-param name="collectedGlobalData"       select="$collectedGlobalData"/>
  210.                     <xsl:with-param name="allVisibleTableRows"      select="$allVisibleTableRows"/>
  211.                     <xsl:with-param name="allColumnStyleEntries"    select="xalan:nodeset($allColumnStyleEntries-RTF)"/>
  212.                 </xsl:call-template>
  213.             </xsl:when>
  214.         </xsl:choose>
  215.  
  216.     </xsl:template>
  217.  
  218.  
  219.  
  220.     <xsl:template name="create-table">
  221.         <xsl:param name="collectedGlobalData"/>
  222.         <xsl:param name="allVisibleTableRows"/>
  223.         <xsl:param name="allColumnStyleEntries"/>
  224.  
  225.  
  226.         <!-- Some Office Calc documents simulate a background by repeating the last cell until end of space
  227.              (The value of "table:number-columns-repeated" is enourmous). Writing out all these cells would be fatal.
  228.              Therefore, this global variable shows us the longest row with content.
  229.  
  230.         Earlier only the viewable columns were listed, but it is easier to handle with all columns:
  231.         <xsl:variable name="maxRowLength" select="count($allColumnStyleEntries/column-style-entry[not(@column-hidden-flag)])"/> -->
  232.         <xsl:variable name="maxRowLength" select="count($allColumnStyleEntries/column-style-entry)"/>
  233.  
  234.  
  235.         <!--isDebugMode-START-->
  236.         <xsl:if test="$isDebugMode">
  237.             <xsl:message>maxRowLength: <xsl:value-of select="$maxRowLength"/></xsl:message>
  238.             <xsl:variable name="numberOfHiddenColumns" select="count($allColumnStyleEntries/column-style-entry[@column-hidden-flag])"/>
  239.             <xsl:message>numberOfHiddenColumns: <xsl:value-of select="$numberOfHiddenColumns"/></xsl:message>
  240.             <xsl:call-template name="table-debug-allColumnStyleEntries">
  241.                 <xsl:with-param name="allColumnStyleEntries" select="$allColumnStyleEntries"/>
  242.             </xsl:call-template>
  243.         </xsl:if>
  244.         <!--isDebugMode-END-->
  245.         <xsl:choose>
  246.             <xsl:when test="$outputType = 'WML'">
  247.                 <!-- matching all rows - we can not use xsl:apply-template with a node-set parameter as by a bug in XT (James Clark)
  248.                      (here: allColumnStyleEntries) will be interpreted as a result tree fragment, where no search expression (XPath) can be used
  249.                      2DO:CHECK WITH XALAN-->
  250.                 <xsl:for-each select="$allVisibleTableRows">
  251.                     <xsl:call-template name="wml-repeat-write-row">
  252.                         <xsl:with-param name="collectedGlobalData"       select="$collectedGlobalData"/>
  253.                         <xsl:with-param name="allColumnStyleEntries"    select="$allColumnStyleEntries"/>
  254.                         <xsl:with-param name="number-rows-repeated"     select="@table:number-rows-repeated"/>
  255.                         <xsl:with-param name="maxRowLength"             select="$maxRowLength"/>
  256.                     </xsl:call-template>
  257.                 </xsl:for-each>
  258.             </xsl:when>
  259.             <xsl:otherwise>
  260.                 <!-- matching all rows - we can not use xsl:apply-template with a node-set parameter as by a bug in XT (James Clark)
  261.                      (here: allColumnStyleEntries) will be interpreted as a result tree fragment, where no search expression (XPath) can be used
  262.                      2DO:CHECK WITH XALAN -->
  263.                 <xsl:for-each select="$allVisibleTableRows">
  264.                     <xsl:call-template name="repeat-write-row">
  265.                         <xsl:with-param name="collectedGlobalData"       select="$collectedGlobalData"/>
  266.                         <xsl:with-param name="allColumnStyleEntries"    select="$allColumnStyleEntries"/>
  267.                         <xsl:with-param name="number-rows-repeated"     select="@table:number-rows-repeated"/>
  268.                         <xsl:with-param name="maxRowLength"             select="$maxRowLength"/>
  269.                     </xsl:call-template>
  270.                 </xsl:for-each>
  271.             </xsl:otherwise>
  272.         </xsl:choose>
  273.     </xsl:template>
  274.  
  275.  
  276.  
  277.  
  278.  
  279.     <!-- **************************** -->
  280.     <!-- *** HELPER: table border *** -->
  281.     <!-- **************************** -->
  282.  
  283.     <!-- only one table border for HTML4 or CSS devices which contain one or more 'fo:border-top' attributes (pars pro toto, if one exist the other usually exist, too) -->
  284.     <!-- this was a work-around for the netscape 4.xx but not longer necessary for Mozilla -->
  285.     <xsl:template name="check-for-table-border">
  286.         <xsl:param name="allVisibleTableRows"/>
  287.  
  288.         <xsl:variable name="startTime">
  289.             <xsl:if test="$isDebugMode and not($isJavaDisabled)">
  290.                 <xsl:choose>
  291.                     <xsl:when test="function-available('system:current-time-millis')">
  292.                         <xsl:value-of select="system:current-time-millis()"/>
  293.                     </xsl:when>
  294.                     <xsl:when test="function-available('java:java.lang.System.currentTimeMillis')">
  295.                         <xsl:value-of select="java:java.lang.System.currentTimeMillis()"/>
  296.                     </xsl:when>
  297.                 </xsl:choose>
  298.             </xsl:if>
  299.         </xsl:variable>
  300.  
  301.         <!-- checks if one cell (table:table-cell) of the rows of this table (allVisibleTableRows) contains a border style (i.e. fo:border-top)
  302.              If only one single border element exist, the whole table will gets pre-defined borders (simple heuristic for better browser display) -->
  303.         <xsl:if test="$allVisibleTableRows/table:table-cell[@table:style-name=/*/*/style:style[style:properties/@fo:border-top]/@style:name]">
  304.             <xsl:attribute name="border">1</xsl:attribute>
  305.             <xsl:attribute name="bordercolor">#000000</xsl:attribute>
  306.             <xsl:attribute name="cellpadding">2</xsl:attribute>
  307.             <xsl:attribute name="cellspacing">0</xsl:attribute>
  308.             <xsl:attribute name="page-break-inside">page-break-inside:avoid</xsl:attribute>
  309.         </xsl:if>
  310.  
  311.  
  312.         <!-- check the time for borderchecking (debug)-->
  313.         <xsl:if test="$isDebugMode and not($isJavaDisabled)">
  314.             <xsl:variable name="endTime">
  315.                 <xsl:choose>
  316.                     <xsl:when test="function-available('system:current-time-millis')">
  317.                         <xsl:value-of select="system:current-time-millis()"/>
  318.                     </xsl:when>
  319.                     <xsl:when test="function-available('java:java.lang.System.currentTimeMillis')">
  320.                         <xsl:value-of select="java:java.lang.System.currentTimeMillis()"/>
  321.                     </xsl:when>
  322.                 </xsl:choose>
  323.             </xsl:variable>
  324.             <xsl:message>Time for checking BorderStyle: <xsl:value-of select="($endTime - $startTime)"/> ms</xsl:message>
  325.         </xsl:if>
  326.     </xsl:template>
  327.  
  328. </xsl:stylesheet>
  329.