| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933 |
- <?xml version="1.0" encoding="UTF-8"?>
- <!--***********************************************************
- *
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied. See the License for the
- * specific language governing permissions and limitations
- * under the License.
- *
- ***********************************************************-->
- <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:xlink="http://www.w3.org/1999/xlink"
- xmlns:xt="http://www.jclark.com/xt"
- xmlns:common="http://exslt.org/common"
- xmlns:xalan="http://xml.apache.org/xalan"
- xmlns="urn:schemas-microsoft-com:office:spreadsheet" xmlns:c="urn:schemas-microsoft-com:office:component:spreadsheet" xmlns:html="http://www.w3.org/TR/REC-html40" xmlns:o="urn:schemas-microsoft-com:office:office" xmlns:ss="urn:schemas-microsoft-com:office:spreadsheet" xmlns:x2="http://schemas.microsoft.com/office/excel/2003/xml" xmlns:x="urn:schemas-microsoft-com:office:excel" 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 xlink xt common xalan">
- <!-- ************** -->
- <!-- *** Table *** -->
- <!-- ************** -->
- <!-- check existence of default cell style -->
- <xsl:variable name="firstDefaultCellStyle" select="descendant::table:table-column/@table:default-cell-style-name" />
- <xsl:template match="table:table" name="table:table">
- <xsl:element name="Table">
- <xsl:apply-templates select="@table:style-name" />
- <!-- find all columns in the table -->
- <xsl:variable name="columnNodes" select="descendant::table:table-column" />
- <!-- calculate the overall column amount -->
- <xsl:variable name="maxColumnNo">
- <xsl:choose>
- <xsl:when test="$columnNodes/@table:number-columns-repeated">
- <xsl:value-of select="count($columnNodes)
- + number(sum($columnNodes/@table:number-columns-repeated))
- - count($columnNodes/@table:number-columns-repeated)" />
- </xsl:when>
- <xsl:otherwise>
- <xsl:value-of select="count($columnNodes)"/>
- </xsl:otherwise>
- </xsl:choose>
- </xsl:variable>
- <!-- create columns -->
- <xsl:apply-templates select="$columnNodes[1]">
- <xsl:with-param name="columnNodes" select="$columnNodes" />
- <xsl:with-param name="maxColumnNo" select="$maxColumnNo" />
- </xsl:apply-templates>
- <!-- create rows -->
- <xsl:choose>
- <xsl:when test="not($columnNodes/@table:number-columns-repeated)">
- <xsl:call-template name="optimized-row-handling">
- <xsl:with-param name="rowNodes" select="descendant::table:table-row" />
- <xsl:with-param name="columnNodes" select="$columnNodes" />
- </xsl:call-template>
- </xsl:when>
- <xsl:otherwise>
- <!-- To be able to match from a cell to the corresponding column to match @table:default-cell-style-name,
- the repeated columns are being resolved by copying them in a helper variable -->
- <xsl:variable name="columnNodes-RTF">
- <xsl:for-each select="$columnNodes">
- <xsl:call-template name="adding-column-styles-entries" />
- </xsl:for-each>
- </xsl:variable>
- <xsl:choose>
- <xsl:when test="function-available('xalan:nodeset')">
- <xsl:call-template name="optimized-row-handling">
- <xsl:with-param name="rowNodes" select="descendant::table:table-row" />
- <xsl:with-param name="columnNodes" select="xalan:nodeset($columnNodes-RTF)" />
- </xsl:call-template>
- </xsl:when>
- <xsl:when test="function-available('common:node-set')">
- <xsl:call-template name="optimized-row-handling">
- <xsl:with-param name="rowNodes" select="descendant::table:table-row" />
- <xsl:with-param name="columnNodes" select="common:node-set($columnNodes-RTF)" />
- </xsl:call-template>
- </xsl:when>
- <xsl:when test="function-available('xt:node-set')">
- <xsl:call-template name="optimized-row-handling">
- <xsl:with-param name="rowNodes" select="descendant::table:table-row" />
- <xsl:with-param name="columnNodes" select="xt:node-set($columnNodes-RTF)" />
- </xsl:call-template>
- </xsl:when>
- </xsl:choose>
- </xsl:otherwise>
- </xsl:choose>
- </xsl:element>
- </xsl:template>
- <!-- **************** -->
- <!-- *** Columns *** -->
- <!-- **************** -->
- <xsl:template match="table:table-column">
- <xsl:param name="columnNodes" />
- <xsl:param name="currentColumnNumber" select="1" />
- <xsl:param name="setIndex" select="false()" />
- <xsl:param name="maxColumnNo" />
- <xsl:element name="Column">
- <xsl:if test="@table:visibility = 'collapse' or @table:visibility = 'filter'">
- <xsl:attribute name="ss:Hidden">1</xsl:attribute>
- </xsl:if>
- <xsl:if test="@table:number-columns-repeated">
- <xsl:attribute name="ss:Span">
- <xsl:value-of select="@table:number-columns-repeated - 1" />
- </xsl:attribute>
- </xsl:if>
- <xsl:if test="$setIndex">
- <xsl:attribute name="ss:Index">
- <xsl:value-of select="$currentColumnNumber" />
- </xsl:attribute>
- </xsl:if>
- <xsl:choose>
- <xsl:when test="@style:use-optimal-column-width = 'true'">
- <xsl:attribute name="ss:AutoFitWidth">1</xsl:attribute>
- </xsl:when>
- <xsl:otherwise>
- <xsl:variable name="width" select="key('styles', @table:style-name)/style:table-column-properties/@style:column-width" />
- <xsl:if test="$width">
- <xsl:attribute name="ss:Width">
- <!-- using the absolute width in point -->
- <xsl:call-template name="convert2pt">
- <xsl:with-param name="value" select="$width" />
- </xsl:call-template>
- </xsl:attribute>
- </xsl:if>
- </xsl:otherwise>
- </xsl:choose>
- <xsl:if test="@table:number-columns-repeated">
- <xsl:attribute name="ss:Span">
- <xsl:value-of select="@table:number-columns-repeated - 1" />
- </xsl:attribute>
- </xsl:if>
- </xsl:element>
- <xsl:variable name="columnNumber">
- <xsl:choose>
- <xsl:when test="@table:number-columns-repeated">
- <xsl:value-of select="$currentColumnNumber + @table:number-columns-repeated"/>
- </xsl:when>
- <xsl:otherwise>
- <xsl:value-of select="$currentColumnNumber"/>
- </xsl:otherwise>
- </xsl:choose>
- </xsl:variable>
- <xsl:if test="$columnNumber < $maxColumnNo">
- <xsl:variable name="nextColumnNodes" select="$columnNodes[position() != 1]" />
- <xsl:choose>
- <xsl:when test="@table:number-columns-repeated">
- <xsl:apply-templates select="$nextColumnNodes[1]">
- <xsl:with-param name="columnNodes" select="$nextColumnNodes" />
- <xsl:with-param name="currentColumnNumber" select="$columnNumber" />
- <xsl:with-param name="maxColumnNo" select="$maxColumnNo" />
- <xsl:with-param name="setIndex" select="true()" />
- </xsl:apply-templates>
- </xsl:when>
- <xsl:otherwise>
- <xsl:apply-templates select="$nextColumnNodes[1]">
- <xsl:with-param name="columnNodes" select="$nextColumnNodes" />
- <xsl:with-param name="currentColumnNumber" select="$columnNumber + 1" />
- <xsl:with-param name="maxColumnNo" select="$maxColumnNo" />
- </xsl:apply-templates>
- </xsl:otherwise>
- </xsl:choose>
- </xsl:if>
- </xsl:template>
- <!-- current node is a table:table-column -->
- <xsl:template name="adding-column-styles-entries">
- <xsl:choose>
- <xsl:when test="not(@table:number-columns-repeated and @table:number-columns-repeated > 1)">
- <!-- writes an entry of a column in the columns-variable -->
- <xsl:copy-of select="." />
- </xsl:when>
- <xsl:otherwise>
- <!-- repeated colums will be written explicit several times in the variable-->
- <xsl:call-template name="repeat-adding-table-column">
- <xsl:with-param name="numberColumnsRepeated" select="@table:number-columns-repeated" />
- </xsl:call-template>
- </xsl:otherwise>
- </xsl:choose>
- </xsl:template>
- <!-- current node is a table:table-column -->
- <!-- dublicates column elements in case of column-repeated attribute -->
- <xsl:template name="repeat-adding-table-column">
- <xsl:param name="table:table-column" />
- <xsl:param name="numberColumnsRepeated" />
- <xsl:choose>
- <xsl:when test="$numberColumnsRepeated > 1">
- <!-- writes an entry of a column in the columns-variable -->
- <xsl:copy-of select="." />
- <!-- repeat calling this method until all elements written out -->
- <xsl:call-template name="repeat-adding-table-column">
- <xsl:with-param name="numberColumnsRepeated" select="$numberColumnsRepeated - 1" />
- </xsl:call-template>
- </xsl:when>
- <xsl:otherwise>
- <!-- writes an entry of a column in the columns-variable -->
- <xsl:copy-of select="." />
- </xsl:otherwise>
- </xsl:choose>
- </xsl:template>
- <!-- ************* -->
- <!-- *** Rows *** -->
- <!-- ************* -->
- <!-- Recursions are much faster when the stack size is small -->
- <xsl:template name="optimized-row-handling">
- <xsl:param name="rowNodes" />
- <xsl:param name="columnNodes" />
- <xsl:param name="offset" select="0"/>
- <xsl:param name="threshold" select="10"/>
- <xsl:variable name="rowCount" select="count($rowNodes)"/>
- <xsl:choose>
- <xsl:when test="$rowCount <= $threshold">
- <xsl:apply-templates select="$rowNodes[1]">
- <xsl:with-param name="rowNodes" select="$rowNodes" />
- <xsl:with-param name="offset" select="$offset" />
- <xsl:with-param name="columnNodes" select="$columnNodes" />
- </xsl:apply-templates>
- </xsl:when>
- <xsl:otherwise>
- <xsl:variable name="rowCountHalf" select="floor($rowCount div 2)"/>
- <xsl:variable name="rowNodesSetA" select="$rowNodes[position() <= $rowCountHalf]"/>
- <xsl:variable name="rowNodesSetB" select="$rowNodes[position() > $rowCountHalf]"/>
- <!-- to keep track of the rownumber, the repeteated rows have to kept into accounts -->
- <xsl:variable name="rowsCreatedByRepetition">
- <xsl:choose>
- <xsl:when test="$rowNodesSetA/@table:number-rows-repeated">
- <xsl:value-of select="number(sum($rowNodesSetA/@table:number-rows-repeated))
- - count($rowNodesSetA/@table:number-rows-repeated)" />
- </xsl:when>
- <xsl:otherwise>0</xsl:otherwise>
- </xsl:choose>
- </xsl:variable>
- <xsl:choose>
- <xsl:when test="$rowCountHalf > $threshold">
- <xsl:call-template name="optimized-row-handling">
- <xsl:with-param name="rowNodes" select="$rowNodesSetA"/>
- <xsl:with-param name="offset" select="$offset" />
- <xsl:with-param name="columnNodes" select="$columnNodes" />
- </xsl:call-template>
- <xsl:call-template name="optimized-row-handling">
- <xsl:with-param name="rowNodes" select="$rowNodesSetB"/>
- <xsl:with-param name="offset" select="$offset + $rowCountHalf + $rowsCreatedByRepetition" />
- <xsl:with-param name="columnNodes" select="$columnNodes" />
- </xsl:call-template>
- </xsl:when>
- <xsl:otherwise>
- <xsl:apply-templates select="$rowNodesSetA[1]">
- <xsl:with-param name="rowNodes" select="$rowNodesSetA"/>
- <xsl:with-param name="offset" select="$offset" />
- <xsl:with-param name="columnNodes" select="$columnNodes" />
- </xsl:apply-templates>
- <xsl:apply-templates select="$rowNodesSetB[1]">
- <xsl:with-param name="rowNodes" select="$rowNodesSetB" />
- <xsl:with-param name="offset" select="$offset + $rowCountHalf + $rowsCreatedByRepetition" />
- <xsl:with-param name="columnNodes" select="$columnNodes" />
- </xsl:apply-templates>
- </xsl:otherwise>
- </xsl:choose>
- </xsl:otherwise>
- </xsl:choose>
- </xsl:template>
- <!--
- Rows as "table:table-row" might be grouped in
- "table:table-header-rows" or "table:table-row-group"
- This row-tree will be traversed providing each Row with it's
- calculatedRowPosition and earlierRowNumber.
- By this repeated empty rows might be neglected in the spreadsheetml output,
- as the following row will notice the 'gap' and provide @ss:Index,
- which results in filling up the gap by a row without style and content.
- In Excel created rows by ss:Index are 'default' rows.
- -->
- <xsl:template match="table:table-row">
- <xsl:param name="earlierRowNumber" select="0" />
- <xsl:param name="offset" />
- <xsl:param name="calculatedRowPosition" select="$offset + 1" />
- <xsl:param name="rowNodes" />
- <xsl:param name="columnNodes" />
- <xsl:choose>
- <xsl:when test="@table:number-rows-repeated > 1">
- <xsl:call-template name="write-table-row">
- <xsl:with-param name="earlierRowNumber" select="$earlierRowNumber" />
- <xsl:with-param name="calculatedRowPosition" select="$calculatedRowPosition" />
- <xsl:with-param name="columnNodes" select="$columnNodes" />
- </xsl:call-template>
- <xsl:if test="@table:number-rows-repeated > 2 and (table:table-cell/@office:value-type or $firstDefaultCellStyle != '')">
- <!-- In case a cell is being repeated, the cell will be created
- in a variabel, which is as many times given out, as being repeated -->
- <xsl:variable name="tableRow">
- <xsl:call-template name="write-table-row">
- <xsl:with-param name="columnNodes" select="$columnNodes" />
- </xsl:call-template>
- </xsl:variable>
- <xsl:call-template name="optimized-row-repeating">
- <xsl:with-param name="tableRow" select="$tableRow" />
- <xsl:with-param name="repetition" select="@table:number-rows-repeated - 1" />
- <xsl:with-param name="columnNodes" select="$columnNodes" />
- </xsl:call-template>
- </xsl:if>
- </xsl:when>
- <xsl:otherwise>
- <xsl:call-template name="write-table-row">
- <xsl:with-param name="earlierRowNumber" select="$earlierRowNumber" />
- <xsl:with-param name="calculatedRowPosition" select="$calculatedRowPosition" />
- <xsl:with-param name="columnNodes" select="$columnNodes" />
- </xsl:call-template>
- </xsl:otherwise>
- </xsl:choose>
- <xsl:variable name="nextRowNodes" select="$rowNodes[position()!=1]" />
- <xsl:choose>
- <xsl:when test="@table:number-rows-repeated > 1">
- <xsl:apply-templates select="$nextRowNodes[1]">
- <xsl:with-param name="earlierRowNumber" select="$calculatedRowPosition" />
- <xsl:with-param name="calculatedRowPosition" select="$calculatedRowPosition + @table:number-rows-repeated" />
- <xsl:with-param name="rowNodes" select="$nextRowNodes" />
- <xsl:with-param name="columnNodes" select="$columnNodes" />
- </xsl:apply-templates>
- </xsl:when>
- <xsl:otherwise>
- <xsl:apply-templates select="$nextRowNodes[1]">
- <xsl:with-param name="earlierRowNumber" select="$calculatedRowPosition" />
- <xsl:with-param name="calculatedRowPosition" select="$calculatedRowPosition + 1" />
- <xsl:with-param name="rowNodes" select="$nextRowNodes" />
- <xsl:with-param name="columnNodes" select="$columnNodes" />
- </xsl:apply-templates>
- </xsl:otherwise>
- </xsl:choose>
- </xsl:template>
- <xsl:template name="write-table-row">
- <xsl:param name="earlierRowNumber" select="0" />
- <xsl:param name="calculatedRowPosition" select="1" />
- <xsl:param name="columnNodes" />
- <xsl:element name="Row">
- <xsl:if test="@table:visibility = 'collapse' or @table:visibility = 'filter'">
- <xsl:attribute name="ss:Hidden">1</xsl:attribute>
- </xsl:if>
- <xsl:if test="not($earlierRowNumber + 1 = $calculatedRowPosition)">
- <xsl:attribute name="ss:Index"><xsl:value-of select="$calculatedRowPosition" /></xsl:attribute>
- </xsl:if>
- <!-- writing the style of the row -->
- <xsl:apply-templates select="@table:style-name" mode="table-row" />
- <xsl:variable name="rowProperties" select="key('styles', @table:style-name)/*" />
- <xsl:if test="$rowProperties/@style:use-optimal-row-height = 'false'">
- <!-- default is '1', therefore write only '0' -->
- <xsl:attribute name="ss:AutoFitHeight">0</xsl:attribute>
- </xsl:if>
- <xsl:variable name="height" select="$rowProperties/@style:row-height" />
- <xsl:if test="$height">
- <xsl:attribute name="ss:Height">
- <!-- using the absolute height in point -->
- <xsl:call-template name="convert2pt">
- <xsl:with-param name="value" select="$height" />
- </xsl:call-template>
- </xsl:attribute>
- </xsl:if>
- <xsl:apply-templates select="table:table-cell[1]">
- <xsl:with-param name="calculatedRowPosition" select="$calculatedRowPosition" />
- <xsl:with-param name="cellNodes" select="table:table-cell" />
- <xsl:with-param name="columnNodes" select="$columnNodes" />
- </xsl:apply-templates>
- </xsl:element>
- </xsl:template>
- <!-- Recursions are much faster when the stack size is small -->
- <xsl:template name="optimized-row-repeating">
- <xsl:param name="tableRow" />
- <xsl:param name="repetition" />
- <!-- resource optimation: instead of '1' it will be '1000' and the column is not full -->
- <xsl:param name="thresholdmax" select="512"/>
- <xsl:param name="thresholdmin" select="256"/>
- <xsl:choose>
- <xsl:when test="$repetition <= $thresholdmax">
- <xsl:copy-of select="$tableRow" />
- <xsl:if test="$repetition <= $thresholdmin">
- <xsl:call-template name="optimized-row-repeating">
- <xsl:with-param name="repetition" select="$repetition - 1"/>
- <xsl:with-param name="tableRow" select="$tableRow" />
- </xsl:call-template>
- </xsl:if>
- </xsl:when>
- <xsl:otherwise>
- <xsl:if test="$repetition mod 2 = 1">
- <xsl:copy-of select="$tableRow" />
- </xsl:if>
- <xsl:variable name="repetitionHalf" select="floor($repetition div 2)"/>
- <xsl:call-template name="optimized-row-repeating">
- <xsl:with-param name="repetition" select="$repetitionHalf"/>
- <xsl:with-param name="tableRow" select="$tableRow" />
- </xsl:call-template>
- <xsl:call-template name="optimized-row-repeating">
- <xsl:with-param name="repetition" select="$repetitionHalf"/>
- <xsl:with-param name="tableRow" select="$tableRow" />
- </xsl:call-template>
- </xsl:otherwise>
- </xsl:choose>
- </xsl:template>
- <!-- ************** -->
- <!-- *** Cells *** -->
- <!-- ************** -->
- <!-- Table cells are able to be repeated by attribute in StarOffice,
- but not in Excel. If more cells are repeated -->
- <xsl:template name="table:table-cell" match="table:table-cell">
- <xsl:param name="calculatedCellPosition" select="1" /><!-- the later table position of the current cell -->
- <xsl:param name="calculatedRowPosition" /><!-- the later table position of the current row -->
- <xsl:param name="setIndex" select="false()" /> <!-- if not '0' @ss:Index used for neglecting repeteated empty cells -->
- <xsl:param name="repetition" select="@table:number-columns-repeated" /> <!-- used for explicit writen out cells -->
- <xsl:param name="repetitionCellPosition" select="$calculatedCellPosition" /><!-- during repetition formula needs exact cell positioning -->
- <xsl:param name="nextMatchedCellPosition"><!-- the later table position of the next cell -->
- <xsl:choose>
- <xsl:when test="not(@table:number-columns-repeated) and not(@table:number-columns-spanned)">
- <xsl:value-of select="$calculatedCellPosition + 1" />
- </xsl:when>
- <xsl:when test="not(@table:number-columns-spanned)">
- <xsl:value-of select="$calculatedCellPosition + @table:number-columns-repeated" />
- </xsl:when>
- <xsl:when test="not(@table:number-columns-repeated)">
- <xsl:value-of select="$calculatedCellPosition + @table:number-columns-spanned" />
- </xsl:when>
- <xsl:otherwise>
- <xsl:value-of select="$calculatedCellPosition + @table:number-columns-spanned * @table:number-columns-repeated" />
- </xsl:otherwise>
- </xsl:choose>
- </xsl:param>
- <xsl:param name="cellNodes" /><!-- cells to be handled -->
- <xsl:param name="columnNodes" />
- <xsl:choose>
- <!-- in case a repetition took place -->
- <xsl:when test="$repetition > 0">
- <xsl:choose>
- <!-- In case of no cell content (text, subelements, attribute, except repeated style) the ss:Index could be used -->
- <xsl:when test="not(text()) and not(*) and not(@*[name() != 'table:number-columns-repeated'])">
- <xsl:choose>
- <xsl:when test="count($cellNodes) = 1">
- <xsl:call-template name="create-table-cell">
- <xsl:with-param name="setIndex" select="true()" />
- <xsl:with-param name="calculatedCellPosition" select="$nextMatchedCellPosition - 1" />
- <xsl:with-param name="calculatedRowPosition" select="$calculatedRowPosition" />
- <xsl:with-param name="columnNodes" select="$columnNodes" />
- </xsl:call-template>
- </xsl:when>
- <xsl:otherwise>
- <xsl:apply-templates select="$cellNodes[2]">
- <xsl:with-param name="calculatedCellPosition" select="$nextMatchedCellPosition" />
- <xsl:with-param name="calculatedRowPosition" select="$calculatedRowPosition" />
- <xsl:with-param name="setIndex" select="true()" />
- <xsl:with-param name="cellNodes" select="$cellNodes[position() != 1]" />
- <xsl:with-param name="columnNodes" select="$columnNodes" />
- </xsl:apply-templates>
- </xsl:otherwise>
- </xsl:choose>
- </xsl:when>
- <!-- Fastest cell repetition by creating cell once and copying, works not for
- a) cells with formula (need of actual cell postition)
- b) cells, which start with ss:Index (as ss:Index is not allowed to be repeated) -->
- <xsl:when test="not(@table:formula) and not($setIndex)">
- <!-- In case a non-empty cell is being repeated, the cell will be created
- in a variabel, which is as many times given out, as being repeated -->
- <xsl:variable name="tableCell">
- <xsl:call-template name="create-table-cell">
- <xsl:with-param name="setIndex" select="false()" /><!-- copied cells may not have indices -->
- <xsl:with-param name="columnNodes" select="$columnNodes" />
- </xsl:call-template>
- </xsl:variable>
- <xsl:call-template name="repeat-copy-table-cell">
- <xsl:with-param name="tableCell" select="$tableCell" />
- <xsl:with-param name="repetition" select="$repetition" />
- <xsl:with-param name="columnNodes" select="$columnNodes" />
- </xsl:call-template>
- <xsl:apply-templates select="$cellNodes[2]">
- <xsl:with-param name="calculatedCellPosition" select="$nextMatchedCellPosition" />
- <xsl:with-param name="calculatedRowPosition" select="$calculatedRowPosition" />
- <xsl:with-param name="cellNodes" select="$cellNodes[position() != 1]" />
- <xsl:with-param name="columnNodes" select="$columnNodes" />
- </xsl:apply-templates>
- </xsl:when>
- <!-- explicit writing (instead of copying) of cell for the cases mentioned above -->
- <xsl:otherwise>
- <xsl:call-template name="create-table-cell">
- <xsl:with-param name="setIndex" select="$setIndex" /><!-- a possible Index will be created -->
- <xsl:with-param name="calculatedCellPosition" select="$repetitionCellPosition" />
- <xsl:with-param name="calculatedRowPosition" select="$calculatedRowPosition" />
- <xsl:with-param name="columnNodes" select="$columnNodes" />
- </xsl:call-template>
- <xsl:choose>
- <!-- as long there is a repetition (higher '1') stay on the same cell node -->
- <xsl:when test="$repetition > 1">
- <xsl:call-template name="table:table-cell">
- <xsl:with-param name="calculatedCellPosition" select="$nextMatchedCellPosition" />
- <xsl:with-param name="calculatedRowPosition" select="$calculatedRowPosition" />
- <xsl:with-param name="repetitionCellPosition">
- <xsl:choose>
- <xsl:when test="@table:number-columns-spanned">
- <xsl:value-of select="$repetitionCellPosition + @table:number-columns-spanned" />
- </xsl:when>
- <xsl:otherwise>
- <xsl:value-of select="$repetitionCellPosition + 1"/>
- </xsl:otherwise>
- </xsl:choose>
- </xsl:with-param>
- <xsl:with-param name="nextMatchedCellPosition" select="$nextMatchedCellPosition" />
- <xsl:with-param name="repetition" select="$repetition - 1" />
- <xsl:with-param name="cellNodes" select="$cellNodes" />
- <xsl:with-param name="columnNodes" select="$columnNodes" />
- </xsl:call-template>
- </xsl:when>
- <xsl:otherwise>
- <xsl:apply-templates select="$cellNodes[2]">
- <xsl:with-param name="calculatedCellPosition" select="$nextMatchedCellPosition" />
- <xsl:with-param name="calculatedRowPosition" select="$calculatedRowPosition" />
- <xsl:with-param name="cellNodes" select="$cellNodes[position() != 1]" />
- <xsl:with-param name="columnNodes" select="$columnNodes" />
- </xsl:apply-templates>
- </xsl:otherwise>
- </xsl:choose>
- </xsl:otherwise>
- </xsl:choose>
- </xsl:when>
- <xsl:otherwise>
- <!-- in case no repetition took place -->
- <xsl:choose>
- <!-- neglect en empty cells by using ss:Index Attribut -->
- <xsl:when test="not(text()) and not(*) and not(@*)">
- <xsl:choose>
- <!-- if it is the last cell, write this cell -->
- <xsl:when test="count($cellNodes) = 1">
- <xsl:call-template name="create-table-cell">
- <xsl:with-param name="setIndex" select="true()" />
- <xsl:with-param name="calculatedCellPosition" select="$nextMatchedCellPosition - 1" />
- <xsl:with-param name="calculatedRowPosition" select="$calculatedRowPosition" />
- <xsl:with-param name="columnNodes" select="$columnNodes" />
- </xsl:call-template>
- </xsl:when>
- <xsl:otherwise>
- <xsl:apply-templates select="$cellNodes[2]">
- <xsl:with-param name="setIndex" select="true()" />
- <xsl:with-param name="calculatedCellPosition" select="$nextMatchedCellPosition" />
- <xsl:with-param name="calculatedRowPosition" select="$calculatedRowPosition" />
- <xsl:with-param name="cellNodes" select="$cellNodes[position() != 1]" />
- <xsl:with-param name="columnNodes" select="$columnNodes" />
- </xsl:apply-templates>
- </xsl:otherwise>
- </xsl:choose>
- </xsl:when>
- <xsl:otherwise>
- <!-- create cell and use/unset the ss:Index -->
- <xsl:call-template name="create-table-cell">
- <xsl:with-param name="setIndex" select="$setIndex" />
- <xsl:with-param name="calculatedCellPosition" select="$calculatedCellPosition" />
- <xsl:with-param name="calculatedRowPosition" select="$calculatedRowPosition" />
- <xsl:with-param name="columnNodes" select="$columnNodes" />
- </xsl:call-template>
- <xsl:apply-templates select="$cellNodes[2]">
- <xsl:with-param name="calculatedCellPosition" select="$nextMatchedCellPosition" />
- <xsl:with-param name="calculatedRowPosition" select="$calculatedRowPosition" />
- <xsl:with-param name="cellNodes" select="$cellNodes[position() != 1]" />
- <xsl:with-param name="columnNodes" select="$columnNodes" />
- </xsl:apply-templates>
- </xsl:otherwise>
- </xsl:choose>
- </xsl:otherwise>
- </xsl:choose>
- </xsl:template>
- <!-- Copies the variable 'tableCell' to the output as often as 'repetition' -->
- <xsl:template name="repeat-copy-table-cell">
- <xsl:param name="tableCell" />
- <xsl:param name="repetition" />
- <xsl:if test="$repetition > 0">
- <xsl:copy-of select="$tableCell"/>
- <xsl:call-template name="repeat-copy-table-cell">
- <xsl:with-param name="tableCell" select="$tableCell" />
- <xsl:with-param name="repetition" select="$repetition - 1" />
- </xsl:call-template>
- </xsl:if>
- </xsl:template>
- <xsl:template name="create-table-cell">
- <xsl:param name="setIndex" select="false()" />
- <xsl:param name="calculatedCellPosition" />
- <xsl:param name="calculatedRowPosition" />
- <xsl:param name="columnNodes" />
- <xsl:element name="Cell" namespace="urn:schemas-microsoft-com:office:spreadsheet">
- <xsl:if test="$setIndex">
- <xsl:attribute name="ss:Index">
- <xsl:value-of select="$calculatedCellPosition"/>
- </xsl:attribute>
- </xsl:if>
- <xsl:if test="@table:number-columns-spanned > 1">
- <xsl:attribute name="ss:MergeAcross">
- <xsl:value-of select="@table:number-columns-spanned - 1" />
- </xsl:attribute>
- </xsl:if>
- <xsl:if test="@table:number-rows-spanned > 1">
- <xsl:attribute name="ss:MergeDown">
- <xsl:value-of select="@table:number-rows-spanned - 1" />
- </xsl:attribute>
- </xsl:if>
- <xsl:variable name="link" select="descendant::text:a/@xlink:href" />
- <xsl:if test="$link">
- <xsl:attribute name="ss:HRef">
- <xsl:value-of select="$link" />
- </xsl:attribute>
- </xsl:if>
- <xsl:choose>
- <xsl:when test="@table:style-name">
- <xsl:apply-templates select="@table:style-name" />
- </xsl:when>
- <xsl:otherwise>
- <xsl:if test="$firstDefaultCellStyle != ''">
- <xsl:variable name="defaultCellStyle" select="$columnNodes/table:table-column[position() = $calculatedCellPosition]/@table:default-cell-style-name" />
- <xsl:if test="$defaultCellStyle">
- <xsl:if test="not($defaultCellStyle = 'Default')">
- <xsl:attribute name="ss:StyleID"><xsl:value-of select="$defaultCellStyle"/></xsl:attribute>
- </xsl:if>
- </xsl:if>
- </xsl:if>
- </xsl:otherwise>
- </xsl:choose>
- <xsl:apply-templates select="@table:formula">
- <xsl:with-param name="calculatedCellPosition" select="$calculatedCellPosition" />
- <xsl:with-param name="calculatedRowPosition" select="$calculatedRowPosition" />
- </xsl:apply-templates>
- <xsl:choose>
- <xsl:when test="*">
- <!-- in case it is not an empty cell
- As the sequence of comment and data is opposite in Excel and Calc no match work here, in both comments exist only once
- Possible Table Content of interest: text:h|text:p|text:list -->
- <xsl:if test="text:h | text:p | text:list">
- <xsl:variable name="valueType">
- <xsl:choose>
- <xsl:when test="@office:value-type">
- <xsl:value-of select="@office:value-type" />
- </xsl:when>
- <xsl:otherwise>string</xsl:otherwise>
- </xsl:choose>
- </xsl:variable>
- <xsl:call-template name="ss:Data">
- <xsl:with-param name="valueType" select="$valueType" />
- <xsl:with-param name="cellStyleName" select="@table:style-name" />
- </xsl:call-template>
- </xsl:if>
- <xsl:if test="office:annotation">
- <xsl:element name="Comment">
- <xsl:if test="office:annotation/@office:author">
- <xsl:attribute name="ss:Author"><xsl:value-of select="office:annotation/@office:author" /></xsl:attribute>
- </xsl:if>
- <xsl:if test="office:annotation/@office:display = 'true'">
- <xsl:attribute name="ss:ShowAlways">1</xsl:attribute>
- </xsl:if>
- <!-- ss:Data is oblicatory, but not the same as the ss:Cell ss:Data child, as it has no attributes -->
- <ss:Data xmlns="http://www.w3.org/TR/REC-html40">
- <xsl:for-each select="office:annotation/text:p">
- <xsl:choose>
- <xsl:when test="*">
- <!-- paragraph style have to be neglected due to Excel error,
- which does not allow shadowing their HTML attributes -->
- <xsl:for-each select="*">
- <xsl:call-template name="style-and-contents" />
- </xsl:for-each>
- </xsl:when>
- <xsl:when test="@text:style-name">
- <xsl:call-template name="style-and-contents" />
- </xsl:when>
- <xsl:otherwise>
- <!-- if no style is set, BOLD is set as default -->
- <B>
- <xsl:call-template name="style-and-contents" />
- </B>
- </xsl:otherwise>
- </xsl:choose>
- </xsl:for-each>
- </ss:Data>
- </xsl:element>
- </xsl:if>
- </xsl:when>
- </xsl:choose>
- </xsl:element>
- </xsl:template>
- <!-- comments are handled separately in the cell -->
- <xsl:template match="office:annotation" />
- <xsl:template match="dc:date" />
- <xsl:template name="ss:Data">
- <!-- the default value is 'String' in the office -->
- <xsl:param name="valueType" select="'string'" />
- <xsl:param name="cellStyleName" />
- <xsl:choose>
- <xsl:when test="descendant::*/@text:style-name">
- <xsl:choose>
- <xsl:when test="$valueType = 'string'">
- <ss:Data ss:Type="String" xmlns="http://www.w3.org/TR/REC-html40">
- <xsl:apply-templates>
- <xsl:with-param name="cellStyleName" select="$cellStyleName" />
- </xsl:apply-templates>
- </ss:Data>
- </xsl:when>
- <xsl:when test="$valueType = 'boolean'">
- <ss:Data ss:Type="Boolean" xmlns="http://www.w3.org/TR/REC-html40">
- <xsl:apply-templates>
- <xsl:with-param name="cellStyleName" select="$cellStyleName" />
- </xsl:apply-templates>
- </ss:Data>
- </xsl:when>
- <xsl:when test="$valueType = 'date'">
- <ss:Data ss:Type="DateTime" xmlns="http://www.w3.org/TR/REC-html40">
- <xsl:apply-templates>
- <xsl:with-param name="cellStyleName" select="$cellStyleName" />
- </xsl:apply-templates>
- </ss:Data>
- </xsl:when>
- <!-- float, time, percentage, currency (no 'Error' setting) -->
- <xsl:otherwise>
- <ss:Data ss:Type="Number" xmlns="http://www.w3.org/TR/REC-html40">
- <xsl:apply-templates>
- <xsl:with-param name="cellStyleName" select="$cellStyleName" />
- </xsl:apply-templates>
- </ss:Data>
- </xsl:otherwise>
- </xsl:choose>
- </xsl:when>
- <xsl:otherwise>
- <xsl:element name="Data">
- <xsl:call-template name="ss:Type">
- <xsl:with-param name="valueType" select="$valueType" />
- </xsl:call-template>
- </xsl:element>
- </xsl:otherwise>
- </xsl:choose>
- </xsl:template>
- <xsl:template name="ss:Type">
- <xsl:param name="valueType" select="'string'" />
- <xsl:choose>
- <xsl:when test="$valueType = 'string'">
- <xsl:attribute name="ss:Type">String</xsl:attribute>
- <xsl:apply-templates select="*"/>
- </xsl:when>
- <xsl:when test="$valueType = 'boolean'">
- <xsl:attribute name="ss:Type">Boolean</xsl:attribute>
- <xsl:choose>
- <xsl:when test="@office:boolean-value = 'true'">1</xsl:when>
- <xsl:otherwise>0</xsl:otherwise>
- </xsl:choose>
- </xsl:when>
- <xsl:when test="$valueType = 'date' or $valueType = 'time'">
- <!-- issue in Excel: can not have an empty 'DateTime' cell -->
- <xsl:attribute name="ss:Type">DateTime</xsl:attribute>
- <!-- Gathering information of two StarOffice date/time attributes
- Excel always needs both informations in one attribute -->
- <xsl:choose>
- <xsl:when test="@office:date-value">
- <!-- office:date-value may contain time (after 'T')-->
- <xsl:choose>
- <xsl:when test="contains(@office:date-value, 'T')">
- <!-- in case time is also part of the date -->
- <xsl:value-of select="substring-before(@office:date-value, 'T')" />
- <xsl:text>T</xsl:text>
- <xsl:value-of select="substring-after(@office:date-value,'T')" />
- <xsl:if test="not(contains(@office:date-value,'.'))">
- <xsl:text>.</xsl:text>
- </xsl:if>
- <xsl:text>000</xsl:text>
- </xsl:when>
- <xsl:when test="@office:time-value">
- <!-- conatains date and time (time will be evaluated later -->
- <xsl:value-of select="@office:date-value" />
- <xsl:text>T</xsl:text>
- <xsl:choose>
- <xsl:when test="@table:formula or contains(@office:time-value,',')">
- <!-- customized number types not implemented yet -->
- <xsl:text>00:00:00.000</xsl:text>
- </xsl:when>
- <xsl:otherwise>
- <xsl:value-of select="translate(substring-after(@office:time-value,'PT'),'HMS','::.')" />
- <xsl:if test="not(contains(@office:time-value,'S'))">
- <xsl:text>.</xsl:text>
- </xsl:if>
- <xsl:text>000</xsl:text>
- </xsl:otherwise>
- </xsl:choose>
- </xsl:when>
- <xsl:otherwise>
- <xsl:value-of select="@office:date-value" />
- <xsl:text>T00:00:00.000</xsl:text>
- </xsl:otherwise>
- </xsl:choose>
- </xsl:when>
- <xsl:otherwise>
- <xsl:if test="@office:time-value">
- <xsl:text>1899-12-31T</xsl:text>
- <xsl:choose>
- <xsl:when test="@table:formula or contains(@office:time-value,',')">
- <!-- customized number types not implemented yet -->
- <xsl:text>00:00:00.000</xsl:text>
- </xsl:when>
- <xsl:otherwise>
- <xsl:value-of select="translate(substring-after(@office:time-value,'PT'),'HMS','::.')" />
- <xsl:if test="not(contains(@office:time-value,'S'))">
- <xsl:text>.</xsl:text>
- </xsl:if>
- <xsl:text>000</xsl:text>
- </xsl:otherwise>
- </xsl:choose>
- </xsl:if>
- </xsl:otherwise>
- </xsl:choose>
- </xsl:when>
- <!-- float, percentage, currency (no 'Error' setting) -->
- <xsl:otherwise>
- <xsl:attribute name="ss:Type">Number</xsl:attribute>
- <xsl:value-of select="@office:value" />
- </xsl:otherwise>
- </xsl:choose>
- </xsl:template>
- <!-- ******************** -->
- <!-- *** Common Rules *** -->
- <!-- ******************** -->
- <xsl:template match="*">
- <xsl:param name="cellStyleName" />
- <!-- LineBreak in Cell -->
- <xsl:if test="preceding-sibling::text:p[1]"><xsl:text> </xsl:text></xsl:if>
- <xsl:call-template name="style-and-contents">
- <xsl:with-param name="cellStyleName" select="$cellStyleName" />
- </xsl:call-template>
- </xsl:template>
- <!-- disabling draw:frames -->
- <xsl:template match="draw:frame" />
- <xsl:template match="text:s">
- <xsl:call-template name="write-breakable-whitespace">
- <xsl:with-param name="whitespaces" select="@text:c" />
- </xsl:call-template>
- </xsl:template>
- <!--write the number of 'whitespaces' -->
- <xsl:template name="write-breakable-whitespace">
- <xsl:param name="whitespaces" />
- <xsl:text> </xsl:text>
- <xsl:if test="$whitespaces >= 1">
- <xsl:call-template name="write-breakable-whitespace">
- <xsl:with-param name="whitespaces" select="$whitespaces - 1" />
- </xsl:call-template>
- </xsl:if>
- </xsl:template>
- <!-- allowing all matched text nodes -->
- <xsl:template match="text()"><xsl:value-of select="." /></xsl:template>
- </xsl:stylesheet>
|