home *** CD-ROM | disk | FTP | other *** search
/ PC World 2004 January / PCWorld_2004-01_cd.bin / akce / openoffice / f_0375 / global_document.xsl
Text File  |  2003-04-24  |  87KB  |  1,674 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.                 extension-element-prefixes="xt"
  78.                 xmlns:urlencoder="http://www.jclark.com/xt/java/java.net.URLEncoder"
  79.                 xmlns:sxghelper="http://www.jclark.com/xt/java/com.sun.star.xslt.helper.SxgChildTransformer"
  80.                 xmlns:xalan="http://xml.apache.org/xalan"
  81.                 xmlns:java="http://xml.apache.org/xslt/java"
  82.                 exclude-result-prefixes="java">
  83.  
  84.  
  85.  
  86.  
  87.     <!-- ********************************************** -->
  88.     <!-- *** Global Document -  Table of Content    *** -->
  89.     <!-- ********************************************** -->
  90.  
  91.  
  92.  
  93.     <xsl:template match="text:table-of-content">
  94.         <xsl:param name="collectedGlobalData"/>
  95.  
  96.         <xsl:apply-templates>
  97.             <xsl:with-param name="collectedGlobalData" select="$collectedGlobalData"/>
  98.         </xsl:apply-templates>
  99.     </xsl:template>
  100.  
  101.  
  102.  
  103.     <xsl:template match="text:index-body">
  104.         <xsl:param name="collectedGlobalData"/>
  105.  
  106.         <xsl:apply-templates mode="content-table">
  107.             <xsl:with-param name="collectedGlobalData" select="$collectedGlobalData"/>
  108.         </xsl:apply-templates>
  109.     </xsl:template>
  110.  
  111.  
  112.  
  113.     <xsl:template match="text:index-title" mode="content-table">
  114.         <xsl:param name="collectedGlobalData"/>
  115.  
  116.         <xsl:apply-templates>
  117.             <xsl:with-param name="collectedGlobalData" select="$collectedGlobalData"/>
  118.         </xsl:apply-templates>
  119.     </xsl:template>
  120.  
  121.     <xsl:template match="text:reference-ref">
  122.         <xsl:param name="collectedGlobalData"/>
  123.  
  124.         <!-- Java is needed as we have to encode the relative links (bug#102311) -->
  125.         <xsl:if test="not($isJavaDisabled)">
  126.             <xsl:element name="a">
  127.                 <xsl:attribute name="href">
  128.                     <xsl:text>#</xsl:text>
  129.                     <xsl:call-template name="encode-string">
  130.                         <!-- the space has to be normalized,
  131.                             otherwise an illegal argument exception will be thrown for XT-->
  132.                          <xsl:with-param name="textToBeEncoded" select="@text:ref-name"/>
  133.                     </xsl:call-template>
  134.                 </xsl:attribute>
  135.  
  136.                 <xsl:apply-templates>
  137.                     <xsl:with-param name="collectedGlobalData" select="$collectedGlobalData"/>
  138.                 </xsl:apply-templates>
  139.  
  140.             </xsl:element>
  141.         </xsl:if>
  142.     </xsl:template>
  143.  
  144.     <xsl:template match="text:reference-mark">
  145.         <xsl:param name="collectedGlobalData"/>
  146.  
  147.         <!-- Java is needed as we have to encode the relative links (bug#102311) -->
  148.         <xsl:if test="not($isJavaDisabled)">
  149.             <xsl:element name="a">
  150.                 <xsl:attribute name="name">
  151.                     <xsl:call-template name="encode-string">
  152.                         <!-- the space has to be normalized,
  153.                             otherwise an illegal argument exception will be thrown for XT-->
  154.                         <xsl:with-param name="textToBeEncoded" select="@text:name"/>
  155.                     </xsl:call-template>
  156.                 </xsl:attribute>
  157.  
  158.                 <xsl:apply-templates>
  159.                     <xsl:with-param name="collectedGlobalData" select="$collectedGlobalData"/>
  160.                 </xsl:apply-templates>
  161.  
  162.             </xsl:element>
  163.         </xsl:if>
  164.     </xsl:template>
  165.  
  166.  
  167.  
  168.     <xsl:template match="text:reference-mark-start">
  169.         <xsl:param name="collectedGlobalData"/>
  170.  
  171.         <!-- Java is needed as we have to encode the relative links (bug#102311) -->
  172.         <xsl:if test="not($isJavaDisabled)">
  173.             <xsl:element name="a">
  174.                 <xsl:attribute name="name">
  175.                     <xsl:call-template name="encode-string">
  176.                         <!-- the space has to be normalized,
  177.                             otherwise an illegal argument exception will be thrown for XT-->
  178.                         <xsl:with-param name="textToBeEncoded" select="@text:name"/>
  179.                     </xsl:call-template>
  180.                 </xsl:attribute>
  181.  
  182.                 <xsl:variable name="endOfReference">
  183.                     <xsl:for-each select="text:reference-mark-end[@name=current()/@text:name]">
  184.                         <xsl:value-of select="position()"/>
  185.                     </xsl:for-each>
  186.                 </xsl:variable>
  187.  
  188.                 <xsl:for-each select="following-sibling::*[position() < $endOfReference]">
  189.                     <xsl:apply-templates>
  190.                         <xsl:with-param name="collectedGlobalData" select="$collectedGlobalData"/>
  191.                     </xsl:apply-templates>
  192.                 </xsl:for-each>
  193.             </xsl:element>
  194.        </xsl:if>
  195.     </xsl:template>
  196.  
  197.  
  198.  
  199.  
  200.      <!-- content table link  -->
  201.     <xsl:template match="text:a" mode="content-table">
  202.         <xsl:param name="collectedGlobalData"/>
  203.  
  204.  
  205.         <!-- For anchors in content-headers a bug exists (cp. bug id# 102311) and they have to be worked out separately.
  206.             Currently the link used in the content-table of an Office XML (e.g. in the content table as '#7.Some%20Example%20Headline%7Outline')
  207.             is not a valid URL (cp. bug id# 102311). No file destination is specified nor exist any anchor element for these
  208.             links in the Office XML, nor is the chapter no. known in the linked files.
  209.             A workaround for this transformation therefore had to be made. This time-consuming mechanism is disabled by default and
  210.             can be activated by a parameter (i.e. 'disableLinkedTableOfContent'). A creation of an anchor is made for each header element.
  211.             All header titles gonna be encoding to be usable in a relative URL. -->
  212.         <xsl:choose>
  213.             <xsl:when test="$disableLinkedTableOfContent or $isJavaDisabled">
  214.                 <xsl:call-template name="create-common-link">
  215.                     <xsl:with-param name="collectedGlobalData" select="$collectedGlobalData"/>
  216.                 </xsl:call-template>
  217.             </xsl:when>
  218.             <xsl:otherwise>
  219.                 <xsl:call-template name="create-content-table-link">
  220.                     <xsl:with-param name="collectedGlobalData"       select="$collectedGlobalData"/>
  221.                 </xsl:call-template>
  222.             </xsl:otherwise>
  223.         </xsl:choose>
  224.     </xsl:template>
  225.  
  226.  
  227.  
  228.     <xsl:template name="get-absolute-chapter-no">
  229.         <xsl:param name="collectedGlobalData"/>
  230.         <xsl:param name="precedingChapterLevel1"/>
  231.  
  232.         <xsl:choose>
  233.             <xsl:when test="$globalDocumentRefToCurrentFile">
  234.  
  235.                 <xsl:variable name="currentFileHeadingNo">
  236.                     <xsl:call-template name="get-current-file-heading-no"/>
  237.                 </xsl:variable>
  238.                 <xsl:variable name="testResult" select="$contentTableHeadings/heading[$globalDocumentRefToCurrentFile = @file-url][number($currentFileHeadingNo)]"/>
  239.  
  240.                 <xsl:call-template name="get-global-heading-no">
  241.                     <xsl:with-param name="currentFileHeadingNo" select="translate($testResult/@absolute-chapter-level, '+', '.')"/>
  242.                     <xsl:with-param name="precedingChapterLevel1" select="$precedingChapterLevel1"/>
  243.                 </xsl:call-template>
  244.  
  245.            </xsl:when>
  246.            <xsl:otherwise>
  247.                 <!-- When the chapter is in the global document itself the link has to be relative (e.g. #index) a absolute href does not
  248.                     work with the browser. In case of chapter in the global document, the output URL of the global document was taken. -->
  249.                 <xsl:variable name="currentFileHeadingNo">
  250.                     <xsl:call-template name="get-current-file-heading-no"/>
  251.                 </xsl:variable>
  252.                 <xsl:variable name="testResult" select="$collectedGlobalData/content-table-headings/heading[$contentTableURL = @file-url][number($currentFileHeadingNo)]"/>
  253.  
  254.                 <xsl:call-template name="get-global-heading-no">
  255.                     <xsl:with-param name="currentFileHeadingNo" select="translate($testResult/@absolute-chapter-level, '+', '.')"/>
  256.                     <xsl:with-param name="precedingChapterLevel1" select="$precedingChapterLevel1"/>
  257.                 </xsl:call-template>
  258.             </xsl:otherwise>
  259.         </xsl:choose>
  260.     </xsl:template>
  261.  
  262.  
  263.     <xsl:template name="get-current-file-heading-no">
  264.         <xsl:choose>
  265.             <xsl:when test="function-available('sxghelper:get-current-child-heading-no')">
  266.                 <xsl:value-of select="sxghelper:get-current-child-heading-no()"/>
  267.             </xsl:when>
  268.             <xsl:when test="function-available('java:com.sun.star.xslt.helper.SxgChildTransformer.getCurrentChildHeadingNo')">
  269.                 <xsl:value-of select="java:com.sun.star.xslt.helper.SxgChildTransformer.getCurrentChildHeadingNo()"/>
  270.             </xsl:when>
  271.         </xsl:choose>
  272.     </xsl:template>
  273.  
  274.  
  275.     <xsl:template name="get-next-current-file-heading-no">
  276.         <xsl:param name="file"/>
  277.         <xsl:choose>
  278.             <xsl:when test="function-available('sxghelper:get-next-current-child-heading-no')">
  279.                 <xsl:value-of select="sxghelper:get-next-current-child-heading-no($file)"/>
  280.             </xsl:when>
  281.             <xsl:when test="function-available('java:com.sun.star.xslt.helper.SxgChildTransformer.getNextCurrentChildHeadingNo')">
  282.                 <xsl:value-of select="java:com.sun.star.xslt.helper.SxgChildTransformer.getNextCurrentChildHeadingNo($file)"/>
  283.             </xsl:when>
  284.         </xsl:choose>
  285.     </xsl:template>
  286.  
  287.  
  288.     <xsl:template name="get-global-heading-no">
  289.         <xsl:param name="currentFileHeadingNo"/>
  290.         <xsl:param name="precedingChapterLevel1"/>
  291.  
  292.         <xsl:choose>
  293.             <xsl:when test="function-available('sxghelper:get-global-heading-no')">
  294.                 <xsl:value-of select="sxghelper:get-global-heading-no(string($currentFileHeadingNo), number($precedingChapterLevel1))"/>
  295.             </xsl:when>
  296.             <xsl:when test="function-available('java:com.sun.star.xslt.helper.SxgChildTransformer.getGlobalHeadingNo')">
  297.                 <xsl:value-of select="java:com.sun.star.xslt.helper.SxgChildTransformer.getGlobalHeadingNo(string($currentFileHeadingNo), number($precedingChapterLevel1))"/>
  298.             </xsl:when>
  299.         </xsl:choose>
  300.     </xsl:template>
  301.  
  302.  
  303.  
  304.  
  305.     <!-- necessary as anchor for the content table -->
  306.     <xsl:template name="create-heading-anchor">
  307.         <xsl:param name="collectedGlobalData"/>
  308.  
  309.         <!--
  310.         Currently the link used in the Office XML (e.g. in the content table as '#7.Some%20Example%20Headline%7Outline')
  311.         is not a valid URL (cmp. bug id# 102311). No file destination is specified nor exist any anchor element for these
  312.         links in the Office XML.
  313.         Here we are creating an anchor with the space normalized text of this header as potential jump address of the content table -->
  314.  
  315.         <xsl:choose>
  316.             <xsl:when test="$globalDocumentRefToCurrentFile">
  317.  
  318.                 <xsl:variable name="currentFileHeadingNo">
  319.                     <xsl:call-template name="get-next-current-file-heading-no">
  320.                          <xsl:with-param name="file" select="$globalDocumentRefToCurrentFile"/>
  321.                     </xsl:call-template>
  322.                 </xsl:variable>
  323.  
  324.  
  325.                 <xsl:variable name="testResult" select="$contentTableHeadings/heading[$globalDocumentRefToCurrentFile = @file-url][number($currentFileHeadingNo)]"/>
  326.                 <xsl:if test="$isDebugMode">
  327.                     <xsl:message>Matching child document header No. <xsl:value-of select="$currentFileHeadingNo"/></xsl:message>
  328.                     <xsl:message>absolute-chapter-level:         <xsl:value-of select="$testResult/@absolute-chapter-level"/></xsl:message>
  329.                     <xsl:message>encodedTitle:                   <xsl:value-of select="$testResult/@encoded-title"/></xsl:message>
  330.                     <xsl:message>globalDocumentRefToCurrentFile: <xsl:value-of select="$globalDocumentRefToCurrentFile"/></xsl:message>
  331.                     <xsl:message>*** </xsl:message>
  332.                 </xsl:if>
  333.  
  334.                 <xsl:element name="a">
  335.                     <xsl:attribute name="name">
  336.                         <xsl:value-of select="$testResult/@absolute-chapter-level"/>
  337.                         <xsl:text>+</xsl:text>
  338.                         <xsl:value-of select="$testResult/@encoded-title"/>
  339.                     </xsl:attribute>
  340.                 </xsl:element>
  341.            </xsl:when>
  342.  
  343.            <xsl:otherwise>
  344.                 <!-- When the chapter is in the global document itself the link has to be relative (e.g. #index) a absolute href does not
  345.                     work with the browser. In case of chapter in the global document, the output URL of the global document was taken. -->
  346.                 <xsl:variable name="currentFileHeadingNo">
  347.                     <xsl:call-template name="get-next-current-file-heading-no">
  348.                          <xsl:with-param name="file" select="$contentTableURL"/>
  349.                     </xsl:call-template>
  350.                 </xsl:variable>
  351.  
  352.  
  353.                 <xsl:variable name="testResult" select="$collectedGlobalData/content-table-headings/heading[$contentTableURL = @file-url][number($currentFileHeadingNo)]"/>
  354.  
  355.                 <xsl:if test="$isDebugMode">
  356.                     <xsl:message>Matching global document header No. <xsl:value-of select="$currentFileHeadingNo"/></xsl:message>
  357.                     <xsl:message>absolute-chapter-level:  <xsl:value-of select="$testResult/@absolute-chapter-level"/></xsl:message>
  358.                     <xsl:message>encodedTitle:            <xsl:value-of select="$testResult/@encoded-title"/></xsl:message>
  359.                     <xsl:message>contentTableURL:         <xsl:value-of select="$contentTableURL"/></xsl:message>
  360.                     <xsl:message>*** </xsl:message>
  361.                 </xsl:if>
  362.  
  363.                 <xsl:element name="a">
  364.                     <xsl:attribute name="name">
  365.                         <xsl:value-of select="$testResult/@absolute-chapter-level"/>
  366.                         <xsl:text>+</xsl:text>
  367.                         <xsl:value-of select="$testResult/@encoded-title"/>
  368.                     </xsl:attribute>
  369.                 </xsl:element>
  370.  
  371.             </xsl:otherwise>
  372.         </xsl:choose>
  373.  
  374.  
  375.  
  376. <!--
  377.  
  378.         <xsl:variable name="title" select="normalize-space(.)"/>
  379.         <!~~DON'T WORK    <xsl:variable name="title" select="normalize-space(descendant::text())"/>        ~~>
  380.          <xsl:choose>
  381.             <xsl:when test="$globalDocumentRefToCurrentFile">
  382.                 <xsl:variable name="testResults" select="$contentTableHeadings/heading[$globalDocumentRefToCurrentFile = @file-url][$title = @title][current()/@text:level = @level]"/>
  383.                 <xsl:if test="1 < count($testResults)">
  384.                     <xsl:message> *** CAUTION: Multiple chapter headings with similar names: </xsl:message>
  385.                     <xsl:message> *** Title: <xsl:value-of select="$title"/> Level: <xsl:value-of select="@text:level"/></xsl:message>
  386.                 </xsl:if>
  387.  
  388.                  <xsl:variable name="encodedTitle" select="$testResults/@encoded-title"/>
  389.                  <xsl:choose>
  390.                      <xsl:when test="$encodedTitle">
  391.                          <xsl:element name="a">
  392.                             <xsl:attribute name="name">
  393.                                 <xsl:value-of select="$encodedTitle"/>
  394.                             </xsl:attribute>
  395.                          </xsl:element>
  396.                      </xsl:when>
  397.                      <xsl:otherwise>
  398.                         <!~~ even when it is not ~~>
  399.                         <xsl:variable name="newEncodedTitle">
  400.                             <xsl:call-template name="encode-string">
  401.                                 <!~~ the space has to be normalized,
  402.                                     otherwise an illegal argument exception will be thrown for XT~~>
  403.                                  <xsl:with-param name="textToBeEncoded" select="$title"/>
  404.                             </xsl:call-template>
  405.                         </xsl:variable>
  406.                          <xsl:element name="a">
  407.                             <xsl:attribute name="name">
  408.                                 <xsl:value-of select="$newEncodedTitle"/>
  409.                             </xsl:attribute>
  410.                          </xsl:element>
  411.                      </xsl:otherwise>
  412.                  </xsl:choose>
  413.             </xsl:when>
  414.             <xsl:otherwise>
  415.                 <xsl:variable name="testResults" select="$collectedGlobalData/content-table-headings/heading[$contentTableURL = @file-url][$title = @title][current()/@text:level = @level]"/>
  416.                 <xsl:if test="1 < count($testResults)">
  417.                     <xsl:message> *** CAUTION: Multiple chapter headings with similar names: </xsl:message>
  418.                     <xsl:message> *** Title: <xsl:value-of select="$title"/> Level: <xsl:value-of select="@text:level"/></xsl:message>
  419.                     <xsl:message> *** </xsl:message>
  420.                 </xsl:if>
  421.  
  422.                 <xsl:variable name="encodedTitle" select="$testResults/@encoded-title"/>
  423.                 <xsl:choose>
  424.                      <xsl:when test="$encodedTitle">
  425.                          <xsl:element name="a">
  426.                             <xsl:attribute name="name">
  427.                                 <xsl:value-of select="$encodedTitle"/>
  428.                             </xsl:attribute>
  429.                          </xsl:element>
  430.                      </xsl:when>
  431.                      <xsl:otherwise>
  432.                         <!~~ even when it is not ~~>
  433.                         <xsl:variable name="newEncodedTitle">
  434.                             <xsl:call-template name="encode-string">
  435.                                 <!~~ the space has to be normalized,
  436.                                     otherwise an illegal argument exception will be thrown for XT~~>
  437.                                  <xsl:with-param name="textToBeEncoded" select="$title"/>
  438.                             </xsl:call-template>
  439.                         </xsl:variable>
  440.                          <xsl:element name="a">
  441.                             <xsl:attribute name="name">
  442.                                 <xsl:value-of select="$newEncodedTitle"/>
  443.                             </xsl:attribute>
  444.                          </xsl:element>
  445.                      </xsl:otherwise>
  446.                  </xsl:choose>
  447.             </xsl:otherwise>
  448.         </xsl:choose>
  449.  
  450. -->
  451.  
  452.     </xsl:template>
  453.  
  454.  
  455.  
  456.  
  457.     <!-- ************************************** -->
  458.     <!--    CREATION OF A CONTENT TABLE LINK    -->
  459.     <!-- ************************************** -->
  460.  
  461.  
  462.     <!-- a special behavior of text:a
  463.         (called from the 'text:a' template) -->
  464.  
  465.     <xsl:template name="create-content-table-link">
  466.         <xsl:param name="collectedGlobalData"/>
  467.  
  468.         <xsl:choose>
  469.             <xsl:when test="not($outputType = 'WML')">
  470.                 <xsl:element name="a">
  471.                     <xsl:attribute name="href">
  472.                         <xsl:choose>
  473.                             <xsl:when test="starts-with(@xlink:href, '#')">
  474.                                 <xsl:variable name="correctHeading" select="$collectedGlobalData/content-table-headings/heading[current()/@xlink:href = @content-table-id]"/>
  475.  
  476.                                 <xsl:value-of select="$correctHeading/@out-file-url"/>
  477.                                 <xsl:text>#</xsl:text>
  478.                                 <xsl:value-of select="$correctHeading/@absolute-chapter-level"/>
  479.                                 <xsl:text>+</xsl:text>
  480.                                 <xsl:value-of select="$correctHeading/@encoded-title"/>
  481.                             </xsl:when>
  482.                             <xsl:otherwise>
  483.                                 <xsl:call-template name="create-common-link">
  484.                                     <xsl:with-param name="collectedGlobalData" select="$collectedGlobalData"/>
  485.                                 </xsl:call-template>
  486.                             </xsl:otherwise>
  487.                         </xsl:choose>
  488.                     </xsl:attribute>
  489.  
  490.                     <xsl:call-template name="apply-styles-and-content">
  491.                         <xsl:with-param name="collectedGlobalData" select="$collectedGlobalData"/>
  492.                     </xsl:call-template>
  493.                 </xsl:element>
  494.             </xsl:when>
  495.             <xsl:otherwise>
  496.                 <!-- 2DO: currently no WML support
  497.  
  498.                 <!~~ no nested p tags in wml1.1 allowed ~~>
  499.                 <xsl:choose>
  500.                     <xsl:when test="ancestor::*[contains($wap-paragraph-elements, name())]">
  501.                         <xsl:element name="a">
  502.                             <xsl:attribute name="href"><xsl:value-of select="@xlink:href"/></xsl:attribute>
  503.                             <xsl:apply-templates select="."/>
  504.                         </xsl:element>
  505.                     </xsl:when>
  506.                     <xsl:otherwise>
  507.                         <xsl:element name="p">
  508.                             <xsl:element name="a">
  509.                                 <xsl:attribute name="href"><xsl:value-of select="@xlink:href"/></xsl:attribute>
  510.                                 <xsl:apply-templates select="."/>
  511.                             </xsl:element>
  512.                         </xsl:element>
  513.                     </xsl:otherwise>
  514.                 </xsl:choose>  -->
  515.             </xsl:otherwise>
  516.         </xsl:choose>
  517.     </xsl:template>
  518.  
  519.  
  520.     <!--
  521.         CREATION OF A HELPER VARIABLE AS WORKAROUND FOR THE CONTENT TABLE ULR BUG
  522.  
  523.  
  524.         As no valid URL from the content table to the child documents exist in the content table,
  525.         a work-around is done:
  526.  
  527.         First two helper variables are being created.
  528.  
  529.         One containing the list of all references of the global document:
  530.         containg all their title,
  531.         for example:
  532.  
  533.               <chapter-ref title="aTitle 1"/>
  534.               <chapter-ref title="aTitle 2"/>
  535.               <chapter-ref title="aTitle 2/>
  536.               <chapter-ref title="aTitle 3/>
  537.  
  538.         The other containing all heading from the child documents linked from the global document.
  539.         The variable 'childrenHeadings' contains their title and the number of preceding similar titles,
  540.         for example:
  541.  
  542.  
  543.               <child file-url="aURL">
  544.                   <heading title="aTitle1" level="1">
  545.                   <heading title="aTitle2" level="2">
  546.                   <heading title="aTitle3" level="1">
  547.             </child>
  548.  
  549.         For each chapter reference from the content table the
  550.  
  551.          by encoding the chapter names of the child document with the java URLEncoder and
  552.         use this as a part of a link. Furthermore for all heading elements a encoded anchor will be created from the heading.
  553.         Last the workaround parses all children documents for this anhor, as there is no distinction of files from the content table entries.
  554.  
  555.         The new added node set to the collectedGlobalData variable concering the content table is written as
  556.  
  557.  
  558.         <content-table-headings content-table-url="aURL_ToTheGeneratedContentTable">
  559.               <heading file-url="aFileURLToTheGeneratedHeading1" level="1">
  560.               <heading file-url="aFileURLToTheGeneratedHeading2" level="2">
  561.               <heading file-url="aFileURLToTheGeneratedHeading1" level="1">
  562.               <heading file-url="aFileURLToTheGeneratedHeading2" level="2">
  563.         </content-table-headings>
  564.  
  565.  
  566.         Preconditions:
  567.         The correct sequence of child documents according to the Content Table is necessary, granted by the office.
  568.     -->
  569.     <xsl:template name="Create-helper-variables-for-Content-Table">
  570.         <xsl:param name="collectedGlobalData"/>
  571.  
  572.         <xsl:if test="$isDebugMode"><xsl:message>Creation of global document helper variable for the content table....</xsl:message></xsl:if>
  573.  
  574.         <!-- Here a helper variable of the content table is created, of all chapter-references which point to a child document.
  575.              an 'chapter-ref' element will be created, containg their title and the number of preceding similar titles,
  576.              for example:
  577.  
  578.                   <chapter-ref title="aTitle 1"/>
  579.                   <chapter-ref title="aTitle 2"/>
  580.                   <chapter-ref title="aTitle 2"/>
  581.                   <chapter-ref title="aTitle 3"/>
  582.             -->
  583.         <xsl:variable name="chapterRefs-RTF">
  584.             <!-- '/*/' as the flat and the zipped XML file format have different root elements -->
  585.             <xsl:for-each select="/*/office:body/text:table-of-content/text:index-body/text:p/text:a">
  586.                 <xsl:variable name="currentTitle" select="normalize-space(string(.))"/>
  587.                 <xsl:element name="chapter-ref">
  588.                     <xsl:attribute name="title">
  589.                         <xsl:value-of select="$currentTitle"/>
  590.                     </xsl:attribute>
  591.                     <xsl:attribute name="content-table-id">
  592.                         <xsl:value-of select="@xlink:href"/>
  593.                     </xsl:attribute>
  594.                </xsl:element>
  595.             </xsl:for-each>
  596.         </xsl:variable>
  597.         <xsl:if test="$isDebugMode"><xsl:message>Finished the Creation of global document helper variable for the content table!</xsl:message></xsl:if>
  598.  
  599.  
  600.  
  601.  
  602.         <xsl:if test="$isDebugMode"><xsl:message>Creation of global document helper variable for the child documents....</xsl:message></xsl:if>
  603.         <!-- Here a helper variable of created from the children documents.
  604.              Containg all heading elements from the child documents. Some or all of them are
  605.              chapters referenced by the Global Document.
  606.              The variable contains their title, the level of the heading and the file URL of the child,
  607.              for example:
  608.  
  609.                   <heading title="aTitle1" level="1" file-url="aURL1">
  610.                   <heading title="aTitle2" level="2" file-url="aURL1">
  611.                   <heading title="aTitle3" level="1" file-url="aURL1">
  612.                   <heading title="aTitle4" level="1" file-url="aURL2">
  613.                   <heading title="aTitle5" level="2" file-url="aURL2">
  614.                   <heading title="aTitle2" level="3" file-url="aURL2">
  615.                   <heading title="aTitle6" level="3" file-url="aURL2">
  616.                 <heading-count>7</heading-count>
  617.             -->
  618.         <xsl:variable name="childrenHeadings-RTF">
  619.             <!-- all headers from children documents will be added -->
  620.             <xsl:apply-templates select="/*/office:body/text:section" mode="creation-of-variable"/>
  621.         </xsl:variable>
  622.         <xsl:if test="$isDebugMode"><xsl:message>Finished the Creation of global document helper variable for the child documents!</xsl:message></xsl:if>
  623.  
  624.  
  625.         <xsl:choose>
  626.             <xsl:when test="function-available('xt:node-set')">
  627.                 <xsl:call-template name="Create-global-variable-for-Content-Table">
  628.                     <xsl:with-param name="chapterRefs"     select="xt:node-set($chapterRefs-RTF)"/>
  629.                     <xsl:with-param name="childrenHeadings"     select="xt:node-set($childrenHeadings-RTF)"/>
  630.                     <xsl:with-param name="collectedGlobalData"  select="$collectedGlobalData"/>
  631.                 </xsl:call-template>
  632.             </xsl:when>
  633.             <xsl:when test="function-available('xalan:nodeset')">
  634.                 <xsl:call-template name="Create-global-variable-for-Content-Table">
  635.                     <xsl:with-param name="chapterRefs"     select="xalan:nodeset($chapterRefs-RTF)"/>
  636.                     <xsl:with-param name="childrenHeadings"     select="xalan:nodeset($childrenHeadings-RTF)"/>
  637.                     <xsl:with-param name="collectedGlobalData"  select="$collectedGlobalData"/>
  638.                 </xsl:call-template>
  639.             </xsl:when>
  640.         </xsl:choose>
  641.     </xsl:template>
  642.  
  643.  
  644.  
  645.  
  646.     <xsl:template name="Create-global-variable-for-Content-Table">
  647.         <xsl:param name="chapterRefs"/>
  648.         <xsl:param name="childrenHeadings"/>
  649.         <xsl:param name="collectedGlobalData"/>
  650.  
  651.  
  652.         <xsl:if test="$isDebugMode">
  653.             <!-- helper variable collecting all headings from the global document file children-->
  654.             <xsl:for-each select="$childrenHeadings/heading">
  655.                 <xsl:message>#              <xsl:value-of select="position()"/></xsl:message>
  656.                 <xsl:message>level:         <xsl:value-of select="@level"/></xsl:message>
  657.                 <xsl:message>title:         <xsl:value-of select="@title"/></xsl:message>
  658.                 <xsl:message>encoded-title: <xsl:value-of select="@encoded-title"/></xsl:message>
  659.                 <xsl:message>file-url:      <xsl:value-of select="@file-url"/></xsl:message>
  660.                 <xsl:message>header-no:     <xsl:value-of select="@header-no"/></xsl:message>
  661.                 <xsl:message>**</xsl:message>
  662.             </xsl:for-each>
  663.             <xsl:message>**</xsl:message>
  664.             <xsl:message>**</xsl:message>
  665.  
  666.             <!-- helper variable collecting all heading references from the content table of the the global document -->
  667.             <xsl:message>childrenHeadings/heading-count: <xsl:value-of select="$childrenHeadings/heading-count"/></xsl:message>
  668.             <xsl:for-each select="$chapterRefs/chapter-ref">
  669.                 <xsl:message># <xsl:value-of select="position()"/></xsl:message>
  670.                 <xsl:message>title: <xsl:value-of select="@title"/></xsl:message>
  671.                 <xsl:message>**</xsl:message>
  672.             </xsl:for-each>
  673.         </xsl:if>
  674.  
  675.  
  676.         <xsl:choose>
  677.             <xsl:when test="function-available('sxghelper:set-heading-no')">
  678.                     <xsl:value-of select="sxghelper:set-heading-no(1)"/>
  679.                     <xsl:value-of select="sxghelper:set-current-child-no(1)"/>
  680.                     <xsl:value-of select="sxghelper:set-current-child-url(string($childrenHeadings/heading/@file-url))"/>
  681.             </xsl:when>
  682.             <xsl:when test="function-available('java:com.sun.star.xslt.helper.SxgChildTransformer.setHeadingNo')">
  683.                     <xsl:value-of select="java:com.sun.star.xslt.helper.SxgChildTransformer.setHeadingNo(1)"/>
  684.                     <xsl:value-of select="java:com.sun.star.xslt.helper.SxgChildTransformer.setCurrentChildNo(1)"/>
  685.                     <xsl:value-of select="java:com.sun.star.xslt.helper.SxgChildTransformer.setCurrentChildUrl(string($childrenHeadings/heading/@file-ur))"/>
  686.             </xsl:when>
  687.         </xsl:choose>
  688.  
  689.         <xsl:if test="$isDebugMode"><xsl:message>Creating global document variable for chapter relations....</xsl:message></xsl:if>
  690.         <xsl:variable name="contentTableHeadingsGlobalData-RTF">
  691.             <xsl:element name="content-table-headings">
  692.                 <!-- all headings are linked from the current global document input file -->
  693.                 <xsl:attribute name="content-table-url">
  694.                     <xsl:value-of select="$contentTableURL"/>
  695.                 </xsl:attribute>
  696.  
  697.                 <!-- had to use a for loop, as a recursion ends with an stackoverflow exception after about 600 recursive calls -->
  698.                 <xsl:choose>
  699.                     <xsl:when test="function-available('sxghelper:get-heading-no')">
  700.                          <xsl:for-each select="$chapterRefs/chapter-ref">
  701.                             <xsl:call-template name="searchHeadingInChildDocument">
  702.                                 <xsl:with-param name="chapterRefs"         select="$chapterRefs"/>
  703.                                 <xsl:with-param name="childrenHeadings"    select="$childrenHeadings"/>
  704.                                 <xsl:with-param name="currentChapterRefNo" select="position()"/>
  705.                                 <xsl:with-param name="currentHeadingNo"    select="sxghelper:get-heading-no()"/>
  706.                                 <xsl:with-param name="currentChildURL"     select="sxghelper:get-current-child-url()"/>
  707.                                 <xsl:with-param name="currentChildNo"      select="sxghelper:get-current-child-no()"/>
  708.                             </xsl:call-template>
  709.                         </xsl:for-each>
  710.                      </xsl:when>
  711.                     <xsl:when test="function-available('java:com.sun.star.xslt.helper.SxgChildTransformer.getHeadingNo')">
  712.                          <xsl:for-each select="$chapterRefs/chapter-ref">
  713.                             <xsl:call-template name="searchHeadingInChildDocument">
  714.                                 <xsl:with-param name="chapterRefs"         select="$chapterRefs"/>
  715.                                 <xsl:with-param name="childrenHeadings"    select="$childrenHeadings"/>
  716.                                 <xsl:with-param name="currentChapterRefNo" select="position()"/>
  717.                                 <xsl:with-param name="currentHeadingNo"    select="java:com.sun.star.xslt.helper.SxgChildTransformer.getHeadingNo()"/>
  718.                                 <xsl:with-param name="currentChildURL"     select="java:com.sun.star.xslt.helper.SxgChildTransformer.getCurrentChildUrl()"/>
  719.                                 <xsl:with-param name="currentChildNo"      select="java:com.sun.star.xslt.helper.SxgChildTransformer.getCurrentChildNo()"/>
  720.                             </xsl:call-template>
  721.                         </xsl:for-each>
  722.                     </xsl:when>
  723.                 </xsl:choose>
  724.             </xsl:element>
  725.  
  726.             <!-- adding the already exisiting global data environment -->
  727.             <xsl:copy-of select="$collectedGlobalData"/>
  728.         </xsl:variable>
  729.         <xsl:if test="$isDebugMode"><xsl:message>Finished global document variable for chapter relations!</xsl:message></xsl:if>
  730.  
  731.         <xsl:choose>
  732.             <xsl:when test="function-available('xt:node-set')">
  733.                 <xsl:call-template name="start-self-and-children-transformation">
  734.                     <xsl:with-param name="collectedGlobalData"       select="xt:node-set($contentTableHeadingsGlobalData-RTF)"/>
  735.                 </xsl:call-template>
  736.             </xsl:when>
  737.             <xsl:when test="function-available('xalan:nodeset')">
  738.                 <xsl:call-template name="start-self-and-children-transformation">
  739.                     <xsl:with-param name="collectedGlobalData"       select="xalan:nodeset($contentTableHeadingsGlobalData-RTF)"/>
  740.                 </xsl:call-template>
  741.             </xsl:when>
  742.         </xsl:choose>
  743.     </xsl:template>
  744.  
  745.  
  746.     <xsl:template name="searchHeadingInChildDocument">
  747.         <xsl:param name="chapterRefs"/>
  748.         <xsl:param name="childrenHeadings"/>
  749.         <xsl:param name="currentChapterRefNo"/>
  750.         <xsl:param name="currentHeadingNo"/>
  751.         <xsl:param name="currentChildURL"/>
  752.         <xsl:param name="currentChildNo"/>
  753.  
  754.  
  755.         <xsl:variable name="currentChapterRef"      select="$chapterRefs/chapter-ref[$currentChapterRefNo]"/>
  756.         <xsl:variable name="currentChapterID"       select="$currentChapterRef/@content-table-id"/>
  757.         <xsl:variable name="currentChapterTitle"    select="$currentChapterRef/@title"/>
  758.  
  759.         <xsl:variable name="currentChildHeading"    select="$childrenHeadings/heading[$currentHeadingNo]"/>
  760.         <xsl:variable name="headingTitle"           select="$currentChildHeading/@title"/>
  761.         <xsl:variable name="headingLevel"           select="$currentChildHeading/@level"/>
  762.         <xsl:variable name="headingNo"              select="$currentChildHeading/@header-no"/>
  763.         <xsl:variable name="newChildURL"            select="$currentChildHeading/@file-url"/>
  764.  
  765.         <xsl:if test="$isDebugMode">
  766.             <xsl:message>*** new heading </xsl:message>
  767.             <xsl:message>currentChapterID:    <xsl:value-of select="$currentChapterID"/></xsl:message>
  768.             <xsl:message>currentChapterTitle: <xsl:value-of select="$currentChapterTitle"/></xsl:message>
  769.             <xsl:message>currentChapterID:    <xsl:value-of select="$currentChapterID"/></xsl:message>
  770.             <xsl:message>currentHeadingNo:    <xsl:value-of select="$currentHeadingNo"/></xsl:message>
  771.             <xsl:message>headingTitle:        <xsl:value-of select="$headingTitle"/></xsl:message>
  772.             <xsl:message>headingLevel:        <xsl:value-of select="$headingLevel"/></xsl:message>
  773.             <xsl:message>headingNo:           <xsl:value-of select="$headingNo"/></xsl:message>
  774.             <xsl:message>newChildURL:         <xsl:value-of select="$newChildURL"/></xsl:message>
  775.         </xsl:if>
  776.  
  777.         <xsl:variable name="outFileURL">
  778.             <xsl:choose>
  779.                  <xsl:when test="substring-before($newChildURL,'.xml')">
  780.                     <xsl:value-of select="concat(substring-before($newChildURL,'.xml'),'.htm')"/>
  781.                  </xsl:when>
  782.                  <xsl:when test="substring-before($newChildURL,'.sx')">
  783.                     <xsl:value-of select="concat(substring-before($newChildURL,'.sx'),'.htm')"/>
  784.                  </xsl:when>
  785.             </xsl:choose>
  786.         </xsl:variable>
  787.         <xsl:variable name="isChapterHeading" select="$headingTitle = $currentChapterTitle"/>
  788.         <xsl:variable name="isNewFile" select="string($newChildURL) != string($currentChildURL)"/>
  789.  
  790.  
  791.  
  792.  
  793.         <xsl:if test="$isNewFile">
  794.             <!-- reset of the already collected child headers -->
  795.             <xsl:call-template name="calc-chapter-numbers">
  796.                  <xsl:with-param name="level" select="0"/>
  797.             </xsl:call-template>
  798.         </xsl:if>
  799.         <xsl:variable name="absoluteChapterLevel">
  800.             <xsl:call-template name="calc-chapter-numbers">
  801.                  <xsl:with-param name="level" select="number($headingLevel)"/>
  802.             </xsl:call-template>
  803.         </xsl:variable>
  804.  
  805.  
  806.         <xsl:element name="heading">
  807.             <!-- necessary to as ID from the content table to get the correct heading element (the buggy URL used as ID)-->
  808.             <xsl:attribute name="content-table-id">
  809.                 <xsl:choose>
  810.                     <xsl:when test="$isChapterHeading">
  811.                         <xsl:value-of select="$currentChapterID"/>
  812.                     </xsl:when>
  813.                     <xsl:otherwise>
  814.                         <xsl:text>only a heading, but not a chapter</xsl:text>
  815.                     </xsl:otherwise>
  816.                 </xsl:choose>
  817.             </xsl:attribute>
  818.             <!-- no of the used child, necessary for quick finding of chapters of next file  -->
  819.             <xsl:attribute name="child-document-no">
  820.                 <xsl:choose>
  821.                     <xsl:when test="$isNewFile">
  822.                         <xsl:value-of select="$currentChildNo + 1"/>
  823.                     </xsl:when>
  824.                     <xsl:otherwise>
  825.                         <xsl:value-of select="$currentChildNo"/>
  826.                     </xsl:otherwise>
  827.                 </xsl:choose>
  828.             </xsl:attribute>
  829.             <!-- the URL of the child document source, containing the heading -->
  830.             <xsl:attribute name="file-url">
  831.                 <xsl:value-of select="$newChildURL"/>
  832.             </xsl:attribute>
  833.             <xsl:attribute name="out-file-url">
  834.                 <xsl:value-of select="$outFileURL"/>
  835.             </xsl:attribute>
  836.             <xsl:attribute name="level">
  837.                 <xsl:value-of select="$headingLevel"/>
  838.             </xsl:attribute>
  839.             <xsl:attribute name="title">
  840.                 <xsl:value-of select="$headingTitle"/>
  841.             </xsl:attribute>
  842.             <xsl:attribute name="encoded-title">
  843.                 <xsl:value-of select="$currentChildHeading/@encoded-title"/>
  844.             </xsl:attribute>
  845.             <xsl:attribute name="absolute-chapter-level">
  846.                 <xsl:value-of select="$absoluteChapterLevel"/>
  847.             </xsl:attribute>
  848.         </xsl:element>
  849.  
  850.  
  851.         <xsl:choose>
  852.             <xsl:when test="$childrenHeadings/heading-count != $currentHeadingNo">
  853.                 <!-- procede as long the list of children isn'nt worked through -->
  854.                 <xsl:choose>
  855.                     <xsl:when test="$isChapterHeading">
  856.                         <!-- global variables have to be set, so the for-each loop can access them -->
  857.                         <xsl:choose>
  858.                             <xsl:when test="function-available('sxghelper:set-heading-no')">
  859.                                 <xsl:value-of select="sxghelper:set-heading-no($currentHeadingNo + 1)"/>
  860.                                 <xsl:if test="$isNewFile">
  861.                                     <xsl:value-of select="sxghelper:set-current-child-no($currentChildNo + 1)"/>
  862.                                     <xsl:value-of select="sxghelper:set-current-child-url(string($newChildURL))"/>
  863.                                 </xsl:if>
  864.                              </xsl:when>
  865.                             <xsl:when test="function-available('java:com.sun.star.xslt.helper.SxgChildTransformer.setHeadingNo')">
  866.                                 <xsl:value-of select="java:com.sun.star.xslt.helper.SxgChildTransformer.setHeadingNo($currentHeadingNo + 1)"/>
  867.                                 <xsl:if test="$isNewFile">
  868.                                     <xsl:value-of select="java:com.sun.star.xslt.helper.SxgChildTransformer.setCurrentChildNo($currentChildNo + 1)"/>
  869.                                     <xsl:value-of select="java:com.sun.star.xslt.helper.SxgChildTransformer.setCurrentChildUrl($newChildURL)"/>
  870.                                 </xsl:if>
  871.                             </xsl:when>
  872.                         </xsl:choose>
  873.                     </xsl:when>
  874.                     <xsl:otherwise>
  875.                         <!-- not a chapter heading, call itself until a chapter ref is found or the end of headings is reached -->
  876.                         <xsl:call-template name="searchHeadingInChildDocument">
  877.                             <xsl:with-param name="chapterRefs"         select="$chapterRefs"/>
  878.                             <xsl:with-param name="childrenHeadings"    select="$childrenHeadings"/>
  879.                             <xsl:with-param name="currentChapterRefNo" select="$currentChapterRefNo"/>
  880.                             <xsl:with-param name="currentHeadingNo"    select="$currentHeadingNo + 1"/>
  881.                             <xsl:with-param name="currentChildURL"     select="$currentChildURL"/>
  882.                             <xsl:with-param name="currentChildNo"      select="$currentChildNo"/>
  883.                         </xsl:call-template>
  884.                     </xsl:otherwise>
  885.                 </xsl:choose>
  886.             </xsl:when>
  887.             <xsl:otherwise>
  888.                 <xsl:if test="$isDebugMode">
  889.                     <xsl:message>All child documents have been walked through without finding the chapter name!</xsl:message>
  890.                     <xsl:message>       childrenHeadings/heading-count:    <xsl:value-of select="$childrenHeadings/heading-count"/></xsl:message>
  891.                     <xsl:message>       currentHeadingNo:                  <xsl:value-of select="$currentHeadingNo"/></xsl:message>
  892.                 </xsl:if>
  893.             </xsl:otherwise>
  894.         </xsl:choose>
  895.     </xsl:template>
  896.  
  897.  
  898.  
  899.  
  900.  
  901.     <!-- Chapters from the Content Table have currently no anchor to child documents in OOo XML.
  902.          As solution, whenever a a global document  every header of the HTML output gets get's an anchor in the Therefore-->
  903.     <xsl:template name="encode-string">
  904.         <xsl:param name="encoding" select="'UTF-8'"/>
  905.         <xsl:param name="textToBeEncoded"/>
  906.  
  907.         <xsl:choose>
  908.             <xsl:when test="function-available('urlencoder:encode')">
  909.                 <xsl:value-of select="urlencoder:encode(normalize-space($textToBeEncoded),$encoding)"/>
  910.             </xsl:when>
  911.             <xsl:when test="function-available('java:java.net.URLEncoder.encode')">
  912.                 <xsl:value-of select="java:java.net.URLEncoder.encode(string(normalize-space($textToBeEncoded)),string($encoding))"/>
  913.             </xsl:when>
  914.         </xsl:choose>
  915.     </xsl:template>
  916.  
  917.  
  918.  
  919.  
  920.  
  921.     <!-- ******************************************************************************************************** -->
  922.     <!-- ***  TRANSFORMATION OF ALL CHILD DOCUMENTS OF THE GLOBAL DOCUMENTS BY USING A EXTERNAL HELPER CLASS  *** -->
  923.     <!-- ******************************************************************************************************** -->
  924.  
  925.  
  926.     <!-- a new element 'contentTableHeadings' will be added to the helper variable the first time a child will be transformed -->
  927.     <xsl:template name="transform-global-document-and-children">
  928.         <xsl:param name="collectedGlobalData"/>
  929.  
  930.  
  931.         <xsl:choose>
  932.             <xsl:when test="$collectedGlobalData/content-table-headings">
  933.                 <xsl:call-template name="start-child-transformation">
  934.                     <xsl:with-param name="collectedGlobalData"   select="$collectedGlobalData"/>
  935.                 </xsl:call-template>
  936.             </xsl:when>
  937.             <xsl:otherwise>
  938.                 <!-- The necessary auxiliary variable hasn't build yet.
  939.                 This variable gonna store all headers (with chapter numbers) and the URL of their files -->
  940.  
  941.                 <xsl:call-template name="Create-helper-variables-for-Content-Table">
  942.                     <xsl:with-param name="collectedGlobalData"   select="$collectedGlobalData"/>
  943.                 </xsl:call-template>
  944.  
  945.             </xsl:otherwise>
  946.         </xsl:choose>
  947.     </xsl:template>
  948.  
  949.  
  950.  
  951.     <xsl:template name="start-self-and-children-transformation">
  952.         <xsl:param name="collectedGlobalData"/>
  953.  
  954.         <xsl:if test="$isDebugMode">
  955.             <xsl:call-template name="debug-content-table-headings-variable">
  956.                 <xsl:with-param name="collectedGlobalData" select="$collectedGlobalData"/>
  957.             </xsl:call-template>
  958.  
  959.             <xsl:message>Parsing the global document...</xsl:message>
  960.         </xsl:if>
  961.  
  962.         <xsl:apply-templates>
  963.             <xsl:with-param name="collectedGlobalData" select="$collectedGlobalData"/>
  964.         </xsl:apply-templates>
  965.  
  966.  
  967.         <xsl:if test="$isDebugMode"><xsl:message>Parsing the child documents...</xsl:message></xsl:if>
  968.         <xsl:call-template name="start-child-transformation">
  969.             <xsl:with-param name="collectedGlobalData" select="$collectedGlobalData"/>
  970.         </xsl:call-template>
  971.  
  972.     </xsl:template>
  973.  
  974.  
  975.  
  976.  
  977.     <xsl:template name="start-child-transformation">
  978.         <xsl:param name="collectedGlobalData"/>
  979.  
  980.         <xsl:if test="$isDebugMode"><xsl:message>Starting the child transformations...</xsl:message></xsl:if>
  981.  
  982.         <!-- As the childs of a global document (with suffix .sxg) do not know anything about their global parent,
  983.             the transformation of global documents children have to be done implizit.
  984.             Otherwise the chapter number of the children will always start with zero, as they do not know anything about the
  985.             proceding chapters.
  986.             Furthermore, they don't have any links about preceeding and following documents and no linking for usability reasons
  987.             could be done. Therefore the children have to be transformed during the transformation of a global (sxg) document -->
  988.         <xsl:if test="$isDebugMode">
  989.             <xsl:choose>
  990.                 <xsl:when test="$collectedGlobalData/content-table-headings">
  991.                     <xsl:message>Contentable data exists as global data!</xsl:message>
  992.                 </xsl:when>
  993.                 <xsl:otherwise>
  994.                     <xsl:message>No Contentable global data exists!</xsl:message>
  995.                 </xsl:otherwise>
  996.             </xsl:choose>
  997.         </xsl:if>
  998.  
  999.         <!-- currently this function only works with node-sets from XT -->
  1000.         <xsl:choose>
  1001.             <xsl:when test="function-available('sxghelper:transform-children')">
  1002.                 <xsl:message>
  1003.                     <xsl:value-of select="sxghelper:transform-children( $collectedGlobalData/content-table-headings,
  1004.                                                                         string($jaredRootURL),
  1005.                                                                         string($absoluteSourceDirRef),
  1006.                                                                         string($optionalURLSuffix),
  1007.                                                                         string($dpi),
  1008.                                                                         string($outputType),
  1009.                                                                         $isDebugMode)"/>
  1010.                 </xsl:message>
  1011.             </xsl:when>
  1012.             <xsl:otherwise>
  1013.                 <xsl:message>Java method transformChildren to transform all children of a global document could not be found. Be sure to use the XT processor.</xsl:message>
  1014.             </xsl:otherwise>
  1015.         </xsl:choose>
  1016.     </xsl:template>
  1017.  
  1018.  
  1019.  
  1020.  
  1021.  
  1022.     <!-- ******************************************************************************* -->
  1023.     <!-- ***  Creation of helper variable of the headings of all children documents  *** -->
  1024.     <!-- ******************************************************************************* -->
  1025.  
  1026.  
  1027.     <xsl:template match="/*/office:body/text:section" mode="creation-of-variable">
  1028.         <xsl:call-template name="getChildRootNode"/>
  1029.  
  1030.         <!-- after the last child document the global document will be parsed -->
  1031.         <xsl:if test="position() = last()">
  1032.             <!-- search the global document after all child documents have been searched
  1033.  
  1034. ODK PATCH NO INDEX ELEMENT WANTED !! - null pointer exception
  1035.             <xsl:call-template name="getPreviousHeaderNo">
  1036.                 <xsl:with-param name="fileURL"                  select="$contentTableURL"/>
  1037.                 <xsl:with-param name="amountOfCurrentHeading"   select="count(following-sibling::text:h)"/>
  1038.                 <xsl:with-param name="nodeToSearchForHeading"   select="following-sibling::text:h"/>
  1039.             </xsl:call-template>
  1040. -->
  1041.            <!-- get the overall No of Headers -->
  1042.            <xsl:call-template name="getAllHeaderNo"/>
  1043.         </xsl:if>
  1044.     </xsl:template>
  1045.  
  1046.  
  1047.     <xsl:template name="getChildRootNode">
  1048.         <xsl:variable name="fileURL"    select="text:section-source/@xlink:href"/>
  1049.  
  1050.         <xsl:choose>
  1051.                <!-- if absolute URL or absolute DOS PATH or absolute Unix path -->
  1052.             <xsl:when test="contains($fileURL,'//') or (substring($fileURL,2,1) = ':') or starts-with($fileURL, '/')">
  1053.                 <xsl:variable name="childRootNode" select="document($fileURL)"/>
  1054.                 <xsl:call-template name="getPreviousHeaderNo">
  1055.                     <xsl:with-param name="fileURL"                select="$fileURL"/>
  1056.                     <!-- NO absolute source path will be added as prefix -->
  1057.                     <xsl:with-param name="amountOfCurrentHeading" select="count($childRootNode/*/office:body/descendant::text:h)"/>
  1058.                     <xsl:with-param name="nodeToSearchForHeading" select="$childRootNode/*/office:body/descendant::text:h"/>
  1059.                 </xsl:call-template>
  1060.             </xsl:when>
  1061.             <xsl:otherwise>
  1062.                 <xsl:variable name="childRootNode" select="document(concat($absoluteSourceDirRef,'/',$fileURL))"/>
  1063.                 <xsl:call-template name="getPreviousHeaderNo">
  1064.                     <xsl:with-param name="fileURL"                select="$fileURL"/>
  1065.                     <!-- the absolute source path will be added as prefix -->
  1066.                     <xsl:with-param name="amountOfCurrentHeading" select="count($childRootNode/*/office:body/descendant::text:h)"/>
  1067.                     <xsl:with-param name="nodeToSearchForHeading" select="$childRootNode/*/office:body/descendant::text:h"/>
  1068.                 </xsl:call-template>
  1069.             </xsl:otherwise>
  1070.         </xsl:choose>
  1071.     </xsl:template>
  1072.  
  1073.  
  1074.     <xsl:template name="getPreviousHeaderNo">
  1075.         <xsl:param name="fileURL"/>
  1076.         <xsl:param name="nodeToSearchForHeading"/>
  1077.         <xsl:param name="amountOfCurrentHeading"/>
  1078.  
  1079.         <xsl:choose>
  1080.             <xsl:when test="function-available('sxghelper:get-previous-child-documents-heading-count')">
  1081.                 <xsl:call-template name="addHeadingInfo">
  1082.                     <xsl:with-param name="nodeToSearchForHeading"   select="$nodeToSearchForHeading"/>
  1083.                     <xsl:with-param name="fileURL"                  select="$fileURL"/>
  1084.                     <xsl:with-param name="previousHeader"           select="sxghelper:get-previous-child-documents-heading-count($amountOfCurrentHeading)"/>
  1085.                 </xsl:call-template>
  1086.             </xsl:when>
  1087.             <xsl:when test="function-available('java:com.sun.star.xslt.helper.SxgChildTransformer.getPreviousChildDocumentsHeadingCount')">
  1088.                 <xsl:call-template name="addHeadingInfo">
  1089.                     <xsl:with-param name="nodeToSearchForHeading"   select="$nodeToSearchForHeading"/>
  1090.                     <xsl:with-param name="fileURL"                  select="$fileURL"/>
  1091.                     <xsl:with-param name="previousHeader"           select="java:com.sun.star.xslt.helper.SxgChildTransformer.getPreviousChildDocumentsHeadingCount($amountOfCurrentHeading)"/>
  1092.                 </xsl:call-template>
  1093.             </xsl:when>
  1094.         </xsl:choose>
  1095.  
  1096.     </xsl:template>
  1097.  
  1098.  
  1099.     <xsl:template name="addHeadingInfo">
  1100.         <xsl:param name="fileURL"/>
  1101.         <xsl:param name="previousHeader"/>
  1102.         <xsl:param name="nodeToSearchForHeading"/>
  1103.  
  1104.         <xsl:variable name="previousHeader2" select="number($previousHeader)"/>
  1105.         <xsl:for-each select="$nodeToSearchForHeading">
  1106.  
  1107.             <xsl:variable name="title" select="normalize-space(.)"/>
  1108.  
  1109.             <xsl:variable name="encodedTitle">
  1110.                 <xsl:call-template name="encode-string">
  1111.                     <!-- the space has to be normalized,
  1112.                         otherwise an illegal argument exception will be thrown for XT-->
  1113.                      <xsl:with-param name="textToBeEncoded" select="$title"/>
  1114.                 </xsl:call-template>
  1115.             </xsl:variable>
  1116.  
  1117.             <xsl:element name="heading">
  1118.                 <!-- odd but 'descendant:text()' didn't work, but '.', to get all text nodes of the header -->
  1119.                 <xsl:attribute name="title"><xsl:value-of select="$title"/></xsl:attribute>
  1120.                 <xsl:attribute name="encoded-title"><xsl:value-of select="$encodedTitle"/></xsl:attribute>
  1121.                 <xsl:attribute name="level"><xsl:value-of select="@text:level"/></xsl:attribute>
  1122.                 <xsl:attribute name="file-url"><xsl:value-of select="$fileURL"/></xsl:attribute>
  1123.                 <xsl:attribute name="header-no"><xsl:value-of select="position() + $previousHeader2"/></xsl:attribute>
  1124.             </xsl:element>
  1125.         </xsl:for-each>
  1126.  
  1127.     </xsl:template>
  1128.  
  1129.  
  1130.     <xsl:template name="getAllHeaderNo">
  1131.  
  1132.         <xsl:choose>
  1133.             <xsl:when test="function-available('sxghelper:get-all-child-documents-heading-count')">
  1134.                 <xsl:call-template name="addAllHeaderNoElement">
  1135.                     <xsl:with-param name="allHeader"   select="sxghelper:get-all-child-documents-heading-count()"/>
  1136.                 </xsl:call-template>
  1137.             </xsl:when>
  1138.             <xsl:when test="function-available('java:com.sun.star.xslt.helper.SxgChildTransformer.getAllChildDocumentsHeadingCount')">
  1139.                 <xsl:call-template name="addAllHeaderNoElement">
  1140.                     <xsl:with-param name="allHeader"   select="java:com.sun.star.xslt.helper.SxgChildTransformer.getAllChildDocumentsHeadingCount()"/>
  1141.                 </xsl:call-template>
  1142.             </xsl:when>
  1143.         </xsl:choose>
  1144.     </xsl:template>
  1145.  
  1146.     <xsl:template name="addAllHeaderNoElement">
  1147.         <xsl:param name="allHeader"/>
  1148.  
  1149.         <xsl:element name="heading-count">
  1150.             <xsl:value-of select="$allHeader"/>
  1151.         </xsl:element>
  1152.  
  1153.     </xsl:template>
  1154.  
  1155.  
  1156.     <!-- ******************************************************************************************************* -->
  1157.     <!-- ***  Creation of a line of links at the beginning and end of a child document to enhance usability  *** -->
  1158.     <!-- ******************************************************************************************************* -->
  1159.  
  1160.     <xsl:template name="add-child-document-usability-links">
  1161.         <xsl:element name="center">
  1162.             <xsl:element name="small">
  1163.                 <xsl:text>[ </xsl:text>
  1164.  
  1165.  
  1166.                 <xsl:variable name="globalDocumentDir" select="sxghelper:get-global-document-dir()"/>
  1167.                 <xsl:variable name="currentChildNo" select="number($contentTableHeadings/heading[$globalDocumentRefToCurrentFile = @file-url]/@child-document-no)"/>
  1168.                 <xsl:variable name="earlierDocURL" select="$contentTableHeadings/heading[($currentChildNo - 1) = @child-document-no]/@out-file-url"/>
  1169. <!--
  1170. <xsl:message>from: <xsl:value-of select="$globalDocumentRefToCurrentFile"/></xsl:message>
  1171. <xsl:message>to: <xsl:value-of select="$earlierDocURL"/></xsl:message>
  1172. <xsl:message>Is: <xsl:call-template name="get-relative-file-ref">
  1173.                     <xsl:with-param name="sourceFileRef" select="$globalDocumentRefToCurrentFile"/>
  1174.                     <xsl:with-param name="targetFileRef" select="$earlierDocURL"/>
  1175.                  </xsl:call-template>
  1176. </xsl:message>-->
  1177.  
  1178.  
  1179.                 <xsl:if test="$earlierDocURL">
  1180.                     <xsl:element name="a">
  1181.                         <xsl:attribute name="href">
  1182.                             <!-- when the links starts with a '#' it's a link to the Content Table-->
  1183.                             <xsl:choose>
  1184.                                 <xsl:when test="starts-with($earlierDocURL, '#')">
  1185.  
  1186.                                     <xsl:call-template name="get-relative-file-ref">
  1187.                                         <xsl:with-param name="sourceFileRef" select="$globalDocumentRefToCurrentFile"/>
  1188.                                         <xsl:with-param name="targetFileRef" select="."/>
  1189.                                     </xsl:call-template>
  1190. <!--        <xsl:value-of select="concat($contentTableURL, $earlierDocURL)"/>-->
  1191.                                 </xsl:when>
  1192.                                 <xsl:otherwise>
  1193.  
  1194.                                     <xsl:call-template name="get-relative-file-ref">
  1195.                                         <xsl:with-param name="sourceFileRef" select="$globalDocumentRefToCurrentFile"/>
  1196.                                         <xsl:with-param name="targetFileRef" select="$earlierDocURL"/>
  1197.                                     </xsl:call-template>
  1198. <!--
  1199.  
  1200.                                     <xsl:value-of select="concat($globalDocumentDir, $earlierDocURL)"/>-->
  1201.                                 </xsl:otherwise>
  1202.                             </xsl:choose>
  1203.                         </xsl:attribute>
  1204.                         <xsl:text>Previous document</xsl:text>
  1205.                     </xsl:element>
  1206.  
  1207.                     <xsl:text> | </xsl:text>
  1208.                 </xsl:if>
  1209.  
  1210.                 <xsl:element name="a">
  1211.                     <xsl:attribute name="href">
  1212.                         <!-- when globalDocumentRefToCurrentFile is unset the current file is the Content Table-->
  1213.                         <xsl:choose>
  1214.                             <xsl:when test="$globalDocumentRefToCurrentFile">
  1215.                                 <xsl:variable name="contentTableDir">
  1216.                                     <xsl:call-template name="get-name-of-table-of-content-document"/>
  1217.                                 </xsl:variable>
  1218.  
  1219.                                 <xsl:call-template name="get-relative-file-ref">
  1220.                                     <xsl:with-param name="sourceFileRef" select="$globalDocumentRefToCurrentFile"/>
  1221.                                     <xsl:with-param name="targetFileRef" select="$contentTableDir"/>
  1222.                                 </xsl:call-template>
  1223.                             </xsl:when>
  1224.                             <xsl:otherwise>
  1225.                                 <xsl:text>#</xsl:text>
  1226.                             </xsl:otherwise>
  1227.                         </xsl:choose>
  1228.  
  1229. <!--                    <xsl:value-of select="$contentTableURL"/>-->
  1230.                     </xsl:attribute>
  1231.                     <xsl:text>Content Table</xsl:text>
  1232.                 </xsl:element>
  1233.  
  1234.  
  1235.                 <xsl:variable name="nextDocURL" select="$contentTableHeadings/heading[($currentChildNo + 1) = @child-document-no]/@out-file-url"/>
  1236.                 <xsl:if test="$nextDocURL">
  1237.                     <xsl:text> | </xsl:text>
  1238.                     <xsl:element name="a">
  1239.                         <xsl:attribute name="href">
  1240.                             <!-- when the links starts with a '#' it's a link to the Content Table-->
  1241.                             <xsl:choose>
  1242.                                 <xsl:when test="starts-with($nextDocURL, '#')">
  1243.                                     <xsl:call-template name="get-relative-file-ref">
  1244.                                         <xsl:with-param name="sourceFileRef" select="$globalDocumentRefToCurrentFile"/>
  1245.                                         <xsl:with-param name="targetFileRef" select="."/>
  1246.                                     </xsl:call-template>
  1247. <!--                                <xsl:value-of select="concat($contentTableURL, $nextDocURL)"/>-->
  1248.                                 </xsl:when>
  1249.                                 <xsl:otherwise>
  1250.                                     <xsl:call-template name="get-relative-file-ref">
  1251.                                         <xsl:with-param name="sourceFileRef" select="$globalDocumentRefToCurrentFile"/>
  1252.                                         <xsl:with-param name="targetFileRef" select="$nextDocURL"/>
  1253.                                     </xsl:call-template>
  1254. <!--                                 <xsl:value-of select="concat($globalDocumentDir, $nextDocURL)"/>-->
  1255.                                 </xsl:otherwise>
  1256.                             </xsl:choose>
  1257.                         </xsl:attribute>
  1258.                         <xsl:text>Next document</xsl:text>
  1259.                     </xsl:element>
  1260.                 </xsl:if>
  1261.                 <xsl:text> ]</xsl:text>
  1262.             </xsl:element>
  1263.         </xsl:element>
  1264.     </xsl:template>
  1265.  
  1266.  
  1267.     <xsl:template name="get-relative-file-ref">
  1268.         <xsl:param name="sourceFileRef"/>
  1269.         <xsl:param name="targetFileRef"/>
  1270.  
  1271.         <xsl:choose>
  1272.             <xsl:when test="function-available('sxghelper:get-relative-file-ref')">
  1273.                 <xsl:value-of select="sxghelper:get-relative-file-ref(string($sourceFileRef), string($targetFileRef))"/>
  1274.             </xsl:when>
  1275.             <xsl:when test="function-available('java:com.sun.star.xslt.helper.SxgChildTransformer.getRelativeFileRef')">
  1276.                 <xsl:value-of select="java:com.sun.star.xslt.helper.SxgChildTransformer.getRelativeFileRef(string($sourceFileRef), string($targetFileRef))"/>
  1277.             </xsl:when>
  1278.         </xsl:choose>
  1279.  
  1280.     </xsl:template>
  1281.  
  1282.  
  1283.     <xsl:template name="get-name-of-table-of-content-document">
  1284.  
  1285.         <xsl:choose>
  1286.             <xsl:when test="function-available('sxghelper:get-name-of-table-of-content-document')">
  1287.                 <xsl:value-of select="sxghelper:get-name-of-table-of-content-document()"/>
  1288.             </xsl:when>
  1289.             <xsl:when test="function-available('java:com.sun.star.xslt.helper.SxgChildTransformer.getNameOfTableOfContentDocument')">
  1290.                 <xsl:value-of select="java:com.sun.star.xslt.helper.SxgChildTransformer.getNameOfTableOfContentDocument()"/>
  1291.             </xsl:when>
  1292.         </xsl:choose>
  1293.  
  1294.     </xsl:template>
  1295.  
  1296.  
  1297.     <xsl:template name="debug-content-table-headings-variable">
  1298.         <xsl:param name="collectedGlobalData"/>
  1299.  
  1300.         <xsl:message><xsl:text>**** THE HEADING VARIABLE **** </xsl:text></xsl:message>
  1301.         <xsl:message>content-table-url: <xsl:value-of select="collectedGlobalData/content-table-headings/content-table-url"/></xsl:message>
  1302.  
  1303.         <xsl:for-each select="$collectedGlobalData/content-table-headings/heading">
  1304.             <xsl:message><xsl:text>**** new heading:        </xsl:text></xsl:message>
  1305.             <xsl:message>content-table-id:      <xsl:value-of select="@content-table-id"/></xsl:message>
  1306.             <xsl:message>child-document-no:     <xsl:value-of select="@child-document-no"/></xsl:message>
  1307.             <xsl:message>file-url:              <xsl:value-of select="@file-url"/></xsl:message>
  1308.             <xsl:message>out-file-url:          <xsl:value-of select="@out-file-url"/></xsl:message>
  1309.             <xsl:message>level:                 <xsl:value-of select="@level"/></xsl:message>
  1310.             <xsl:message>title:                 <xsl:value-of select="@title"/></xsl:message>
  1311.             <xsl:message>encoded-title:         <xsl:value-of select="@encoded-title"/></xsl:message>
  1312.             <xsl:message>absolute-chapter-level:<xsl:value-of select="@absolute-chapter-level"/></xsl:message>
  1313.         </xsl:for-each>
  1314.  
  1315.     </xsl:template>
  1316.  
  1317.  
  1318.     <!-- To make the headings unique, the absolute heading is added to them
  1319.          E.g. The level 1.2.3.4. would result into a 1+2+3+4 string -->
  1320.     <xsl:template name="calc-chapter-numbers">
  1321.         <xsl:param name="level"/>
  1322.  
  1323.         <xsl:choose>
  1324.             <xsl:when test="function-available('sxghelper:calc-chapter-numbers')">
  1325.                 <xsl:value-of select="sxghelper:calc-chapter-numbers($level)"/>
  1326.             </xsl:when>
  1327.             <xsl:when test="function-available('java:com.sun.star.xslt.helper.SxgChildTransformer.calcChapterNumbers')">
  1328.                 <xsl:value-of select="java:com.sun.star.xslt.helper.SxgChildTransformer.calcChapterNumbers($level)"/>
  1329.             </xsl:when>
  1330.         </xsl:choose>
  1331.  
  1332.     </xsl:template>
  1333.  
  1334.  
  1335.  
  1336.  
  1337.     <xsl:template match="text:p" mode="content-table">
  1338.         <xsl:param name="collectedGlobalData"/>
  1339.  
  1340.         <xsl:variable name="allTabStopStyles" select="$office:automatic-styles/style:style[@style:name = current()/@text:style-name]/style:properties/style:tab-stops"/>
  1341.  
  1342.         <xsl:element name="table">
  1343.             <xsl:attribute name="border">0</xsl:attribute>
  1344.             <xsl:attribute name="class"><xsl:value-of select="@text:style-name"/></xsl:attribute>
  1345. <!--
  1346. <xsl:message>*********</xsl:message>
  1347. <xsl:message>Stylename:<xsl:value-of select="@text:style-name"/></xsl:message>
  1348. <xsl:message>position: <xsl:value-of select="count($allTabStopStyles/style:tab-stop)"/></xsl:message>
  1349. -->
  1350.  
  1351.             <xsl:element name="colgroup">
  1352.                 <xsl:call-template name="create-col-element">
  1353.                     <xsl:with-param name="lastNodePosition" select="count($allTabStopStyles/style:tab-stop)"/>
  1354.                     <xsl:with-param name="allTabStopStyles" select="$allTabStopStyles"/>
  1355.                 </xsl:call-template>
  1356.             </xsl:element>
  1357.  
  1358.  
  1359.             <!-- all elements before the first tabStop -->
  1360.             <xsl:variable name="testNo-RTF">
  1361.                 <xsl:apply-templates select="node()" mode="cell-content"/>
  1362.             </xsl:variable>
  1363.  
  1364.  
  1365.         <xsl:choose>
  1366.             <xsl:when test="function-available('xt:node-set')">
  1367.                 <xsl:variable name="tabNodePositions" select="xt:node-set($testNo-RTF)"/>
  1368.             <xsl:element name="tr">
  1369.                     <xsl:call-template name="create-td-elements">
  1370.                     <xsl:with-param name="lastNodePosition" select="count($allTabStopStyles/style:tab-stop)"/>
  1371.                     <xsl:with-param name="position"         select="1"/>
  1372.                     <xsl:with-param name="allTabStopStyles" select="$allTabStopStyles"/>
  1373.                     <xsl:with-param name="tabNodePositions" select="$tabNodePositions"/>
  1374.                     <xsl:with-param name="collectedGlobalData" select="$collectedGlobalData"/>
  1375.                 </xsl:call-template>
  1376.             </xsl:element>
  1377.  
  1378.             </xsl:when>
  1379.             <xsl:when test="function-available('xalan:nodeset')">
  1380.                 <xsl:variable name="tabNodePositions" select="xalan:nodeset($testNo-RTF)"/>
  1381.             <xsl:element name="tr">
  1382.                     <xsl:call-template name="create-td-elements">
  1383.                     <xsl:with-param name="lastNodePosition" select="count($allTabStopStyles/style:tab-stop)"/>
  1384.                     <xsl:with-param name="position"         select="1"/>
  1385.                     <xsl:with-param name="allTabStopStyles" select="$allTabStopStyles"/>
  1386.                     <xsl:with-param name="tabNodePositions" select="$tabNodePositions"/>
  1387.                     <xsl:with-param name="collectedGlobalData" select="$collectedGlobalData"/>
  1388.                 </xsl:call-template>
  1389.             </xsl:element>
  1390.  
  1391.             </xsl:when>
  1392.         </xsl:choose>
  1393.  
  1394.            <!-- <xsl:variable name="tabNodePositions" select="xt:node-set($testNo-RTF)"/>
  1395.  
  1396.             <xsl:element name="tr">
  1397.                 <xsl:call-template name="create-td-elements">
  1398.                     <xsl:with-param name="lastNodePosition" select="count($allTabStopStyles/style:tab-stop)"/>
  1399.                     <xsl:with-param name="position"         select="1"/>
  1400.                     <xsl:with-param name="allTabStopStyles" select="$allTabStopStyles"/>
  1401.                     <xsl:with-param name="tabNodePositions" select="$tabNodePositions"/>
  1402.                     <xsl:with-param name="collectedGlobalData" select="$collectedGlobalData"/>
  1403.                 </xsl:call-template>
  1404.             </xsl:element>-->
  1405.  
  1406.  
  1407.         </xsl:element>
  1408.     </xsl:template>
  1409.  
  1410.  
  1411.     <xsl:template name="create-col-element">
  1412.         <xsl:param name="lastNodePosition"/>
  1413.         <xsl:param name="allTabStopStyles"/>
  1414.  
  1415.         <xsl:for-each select="$allTabStopStyles/style:tab-stop">
  1416.             <xsl:element name="col">
  1417.                 <xsl:attribute name="style">
  1418.                     <xsl:text>width: </xsl:text>
  1419.                     <xsl:call-template name="grap-cell-width">
  1420.                         <xsl:with-param name="position"         select="position()"/>
  1421.                         <xsl:with-param name="allTabStopStyles" select="$allTabStopStyles"/>
  1422.                     </xsl:call-template>
  1423.                 </xsl:attribute>
  1424.             </xsl:element>
  1425.         </xsl:for-each>
  1426.  
  1427.     </xsl:template>
  1428. <!--
  1429. Scenarios tabstops
  1430.  
  1431. 1) style:type of style:tab-stop is 'right' and earlier tabStop is not right
  1432.  -> Earlier text-nodes and following text-nodes, will be put into an inner table, with two TD first aligned left, with proceding textnodes, the latter aligned right.
  1433.  
  1434. 2) style:type is 'right' and earlier tabStop is right
  1435.  -> following text-nodes, will be put into a right aligned TD
  1436.  
  1437. 3) style:type is 'non-right' and earlier tabStop 'non-right' as well
  1438.  -> put the preceding tab stops into a TD (left aligned is default)
  1439.  
  1440. 4) first style:type would have no right precedign tabStop
  1441.  -> works well with first sceanrios 1 and 3
  1442.  
  1443. 5) last style:type would be a special case, if it would be left aligned, but this won't happen in our case.. :D
  1444.  
  1445. Scenarios unmatched:
  1446. - text:styleposition 'center' will not be matched in our case (effort for nothing), there will be only 'right' and not 'right'
  1447. - If the last tabStop is not from text:stylepostion 'right', the length of the last cell is undefined and a document length must be found.
  1448.   Not happens in our global document case. Also the algorithm below would have to be expanded (cp. scenario 5).
  1449.  
  1450. -->
  1451.     <xsl:template name="create-td-elements">
  1452.         <xsl:param name="collectedGlobalData"/>
  1453.         <xsl:param name="lastNodePosition"/>
  1454.         <xsl:param name="position"/>
  1455.         <xsl:param name="allTabStopStyles"/>
  1456.         <xsl:param name="tabNodePositions"/>
  1457. <!--
  1458. <xsl:message>++++++++</xsl:message>
  1459. <xsl:message>Position: <xsl:value-of select="$position"/></xsl:message>
  1460. <xsl:message>lastNodePosition: <xsl:value-of select="$lastNodePosition"/></xsl:message>
  1461. -->
  1462.  
  1463.         <xsl:variable name="currentStyleType" select="$allTabStopStyles/style:tab-stop[$position]/@style:type"/>
  1464.         <xsl:variable name="earlierStyleType" select="$allTabStopStyles/style:tab-stop[$position - 1]/@style:type"/>
  1465.         <xsl:choose>
  1466.             <xsl:when test="$currentStyleType = 'right'">
  1467.                 <xsl:choose>
  1468.                     <xsl:when test="$earlierStyleType = 'right'">
  1469.                         <!--
  1470.                         2) style:type is 'right' and earlier tabStop is right
  1471.                             -> following text-nodes, will be put into a right aligned TD -->
  1472.                         <xsl:element name="td">
  1473.                             <xsl:attribute name="style">
  1474.                                 <xsl:text>align: right</xsl:text>
  1475.                             </xsl:attribute>
  1476.                             <xsl:call-template name="grap-cell-content-before-tab-stop">
  1477.                                 <xsl:with-param name="collectedGlobalData" select="$collectedGlobalData"/>
  1478.                                 <xsl:with-param name="endingTabStopPosition"  select="$position + 1"/>
  1479.                                 <xsl:with-param name="lastNodePosition" select="$lastNodePosition"/>
  1480.                                 <xsl:with-param name="tabNodePositions" select="$tabNodePositions"/>
  1481.                             </xsl:call-template>
  1482.                         </xsl:element>
  1483.                     </xsl:when>
  1484.                     <xsl:otherwise>
  1485.                     <!--
  1486.                         1) style:type of style:tab-stop is 'right' and earlier tabStop is not right
  1487.                          -> Earlier text-nodes and following text-nodes, will be put into an inner table, with two TD first aligned left, with proceding textnodes, the latter aligned right.-->
  1488. <!-- valid HTML but browsers make a line break (border=0 and paragraphstyle also missing):
  1489.                         <xsl:element name="table">
  1490.                             <xsl:element name="td">
  1491.                                 <xsl:call-template name="grap-cell-content-before-tab-stop">
  1492.                                     <xsl:with-param name="collectedGlobalData" select="$collectedGlobalData"/>
  1493.                                     <xsl:with-param name="endingTabStopPosition"  select="$position"/>
  1494.                                     <xsl:with-param name="lastNodePosition" select="$lastNodePosition"/>
  1495.                                     <xsl:with-param name="tabNodePositions" select="$tabNodePositions"/>
  1496.                                 </xsl:call-template>
  1497.                             </xsl:element>
  1498.                             <xsl:element name="td">
  1499.                                 <xsl:attribute name="style">
  1500.                                     <xsl:text>align: right</xsl:text>
  1501.                                 </xsl:attribute>
  1502.                                 <xsl:call-template name="grap-cell-content-before-tab-stop">
  1503.                                     <xsl:with-param name="collectedGlobalData" select="$collectedGlobalData"/>
  1504.                                     <xsl:with-param name="endingTabStopPosition"  select="$position + 1"/>
  1505.                                     <xsl:with-param name="lastNodePosition" select="$lastNodePosition"/>
  1506.                                     <xsl:with-param name="tabNodePositions" select="$tabNodePositions"/>
  1507.                                 </xsl:call-template>
  1508.                             </xsl:element>
  1509.                         </xsl:element>
  1510. -->
  1511.                             <xsl:element name="td">
  1512.                                 <xsl:call-template name="grap-cell-content-before-tab-stop">
  1513.                                     <xsl:with-param name="collectedGlobalData" select="$collectedGlobalData"/>
  1514.                                     <xsl:with-param name="endingTabStopPosition"  select="$position"/>
  1515.                                     <xsl:with-param name="lastNodePosition" select="$lastNodePosition"/>
  1516.                                     <xsl:with-param name="tabNodePositions" select="$tabNodePositions"/>
  1517.                                 </xsl:call-template>
  1518. <!-- ODK FEATURE NO PAGES
  1519.                                 <xsl:element name="td">
  1520.                                     <xsl:attribute name="style">
  1521.                                         <xsl:text>align: right</xsl:text>
  1522.                                     </xsl:attribute>
  1523.                                     <xsl:call-template name="grap-cell-content-before-tab-stop">
  1524.                                         <xsl:with-param name="collectedGlobalData" select="$collectedGlobalData"/>
  1525.                                         <xsl:with-param name="endingTabStopPosition"  select="$position + 1"/>
  1526.                                         <xsl:with-param name="lastNodePosition" select="$lastNodePosition"/>
  1527.                                         <xsl:with-param name="tabNodePositions" select="$tabNodePositions"/>
  1528.                                     </xsl:call-template>
  1529.                                 </xsl:element>          -->
  1530.                             </xsl:element>
  1531.                     </xsl:otherwise>
  1532.                 </xsl:choose>
  1533.             </xsl:when>
  1534.             <xsl:otherwise>
  1535.                 <xsl:choose>
  1536.                     <xsl:when test="$earlierStyleType = 'right'">
  1537.                     </xsl:when>
  1538.                     <xsl:otherwise>
  1539.                     <!--
  1540.                        3) style:type is 'non-right' and earlier tabStop 'non-right' as well
  1541.                             -> put the preceding tab stops into a TD (left aligned is default) -->
  1542.                         <xsl:element name="td">
  1543.                             <xsl:call-template name="grap-cell-content-before-tab-stop">
  1544.                                 <xsl:with-param name="collectedGlobalData" select="$collectedGlobalData"/>
  1545.                                 <xsl:with-param name="endingTabStopPosition"  select="$position"/>
  1546.                                 <xsl:with-param name="lastNodePosition" select="$lastNodePosition"/>
  1547.                                 <xsl:with-param name="tabNodePositions" select="$tabNodePositions"/>
  1548.                             </xsl:call-template>
  1549.                         </xsl:element>
  1550.                     </xsl:otherwise>
  1551.                 </xsl:choose>
  1552.             </xsl:otherwise>
  1553.         </xsl:choose>
  1554.  
  1555.         <xsl:if test="$position != $lastNodePosition">
  1556.             <xsl:call-template name="create-td-elements">
  1557.                 <xsl:with-param name="collectedGlobalData" select="$collectedGlobalData"/>
  1558.                 <xsl:with-param name="lastNodePosition" select="$lastNodePosition"/>
  1559.                 <xsl:with-param name="position"         select="$position + 1"/>
  1560.                 <xsl:with-param name="allTabStopStyles" select="$allTabStopStyles"/>
  1561.                 <xsl:with-param name="tabNodePositions" select="$tabNodePositions"/>
  1562.             </xsl:call-template>
  1563.         </xsl:if>
  1564.     </xsl:template>
  1565.  
  1566.  
  1567.     <xsl:template name="grap-cell-content-before-tab-stop">
  1568.         <xsl:param name="collectedGlobalData"/>
  1569.         <xsl:param name="endingTabStopPosition"/>
  1570.         <xsl:param name="tabNodePositions"/>
  1571.         <xsl:param name="lastNodePosition"/>
  1572.  
  1573.         <xsl:choose>
  1574.             <xsl:when test="$endingTabStopPosition = 1">
  1575.                 <xsl:apply-templates mode="content-table" select="node()[position() < $tabNodePositions/tab-stop-node-position[$endingTabStopPosition]]">
  1576.                     <xsl:with-param name="collectedGlobalData" select="$collectedGlobalData"/>
  1577.                 </xsl:apply-templates>
  1578.             </xsl:when>
  1579.             <xsl:when test="$endingTabStopPosition > $lastNodePosition">
  1580.                 <xsl:apply-templates mode="content-table" select="node()[position() > $tabNodePositions/tab-stop-node-position[$endingTabStopPosition - 1]]">
  1581.                     <xsl:with-param name="collectedGlobalData" select="$collectedGlobalData"/>
  1582.                 </xsl:apply-templates>
  1583.             </xsl:when>
  1584.             <xsl:otherwise>
  1585.                 <xsl:apply-templates mode="content-table" select="node()[position() < $tabNodePositions/tab-stop-node-position[$endingTabStopPosition]][position() > $tabNodePositions/tab-stop-node-position[$endingTabStopPosition - 1]]">
  1586.                     <xsl:with-param name="collectedGlobalData" select="$collectedGlobalData"/>
  1587.                 </xsl:apply-templates>
  1588.             </xsl:otherwise>
  1589.         </xsl:choose>
  1590.     </xsl:template>
  1591.  
  1592.     <xsl:template mode="content-table" match="text:s">
  1593.         <xsl:call-template name="write-breakable-whitespace">
  1594.             <xsl:with-param name="whitespaces" select="@text:c"/>
  1595.         </xsl:call-template>
  1596.     </xsl:template>
  1597.  
  1598.  
  1599.     <xsl:template match="*" mode="cell-content">
  1600.  
  1601.         <xsl:if test="name() = 'text:tab-stop' or *[name() = 'text:tab-stop']">
  1602.             <xsl:element name="tab-stop-node-position">
  1603.                 <xsl:value-of select="position()"/>
  1604.             </xsl:element>
  1605.         </xsl:if>
  1606.     </xsl:template>
  1607.  
  1608.  
  1609.     <xsl:template name="grap-cell-width">
  1610.         <xsl:param name="position"/>
  1611.         <xsl:param name="allTabStopStyles"/>
  1612.  
  1613.         <xsl:variable name="tabStopPosition" select="$allTabStopStyles/style:tab-stop[$position]/@style:position"/>
  1614.         <xsl:choose>
  1615.             <xsl:when test="contains($tabStopPosition, 'cm')">
  1616.                 <xsl:call-template name="create-cell-width">
  1617.                     <xsl:with-param name="width"    select="number(substring-before($tabStopPosition,'cm'))"/>
  1618.                     <xsl:with-param name="unit"     select="'cm'"/>
  1619.                     <xsl:with-param name="position" select="$position - 1"/>
  1620.                     <xsl:with-param name="allTabStopStyles" select="$allTabStopStyles"/>
  1621.                 </xsl:call-template>
  1622.             </xsl:when>
  1623.             <xsl:when test="contains($tabStopPosition, 'in')">
  1624.                 <xsl:call-template name="create-cell-width">
  1625.                     <xsl:with-param name="width"    select="number(substring-before($tabStopPosition,'in'))"/>
  1626.                     <xsl:with-param name="unit"     select="'in'"/>
  1627.                     <xsl:with-param name="position" select="$position - 1"/>
  1628.                     <xsl:with-param name="allTabStopStyles" select="$allTabStopStyles"/>
  1629.                 </xsl:call-template>
  1630.             </xsl:when>
  1631.             <xsl:when test="contains($tabStopPosition, 'ch')">
  1632.                 <xsl:call-template name="create-cell-width">
  1633.                     <xsl:with-param name="width"    select="number(substring-before($tabStopPosition,'ch'))"/>
  1634.                     <xsl:with-param name="unit"     select="'ch'"/>
  1635.                     <xsl:with-param name="position" select="$position - 1"/>
  1636.                     <xsl:with-param name="allTabStopStyles" select="$allTabStopStyles"/>
  1637.                 </xsl:call-template>
  1638.             </xsl:when>
  1639.             <xsl:when test="contains($tabStopPosition, 'pt')">
  1640.                 <xsl:call-template name="create-cell-width">
  1641.                     <xsl:with-param name="width"    select="number(substring-before($tabStopPosition,'pt'))"/>
  1642.                     <xsl:with-param name="unit"     select="'pt'"/>
  1643.                     <xsl:with-param name="position" select="$position - 1"/>
  1644.                     <xsl:with-param name="allTabStopStyles" select="$allTabStopStyles"/>
  1645.                 </xsl:call-template>
  1646.             </xsl:when>
  1647.         </xsl:choose>
  1648.     </xsl:template>
  1649.  
  1650.     <xsl:template name="create-cell-width">
  1651.         <xsl:param name="width"/>
  1652.         <xsl:param name="unit"/>
  1653.         <xsl:param name="position"/>
  1654.         <xsl:param name="allTabStopStyles"/>
  1655.  
  1656.         <xsl:choose>
  1657.             <xsl:when test="$position > 1">
  1658.                 <xsl:call-template name="create-cell-width">
  1659.                     <xsl:with-param name="width"    select="$width - number(substring-before($allTabStopStyles/style:tab-stop[$position]/@style:position,$unit))"/>
  1660.                     <xsl:with-param name="unit"     select="$unit"/>
  1661.                     <xsl:with-param name="position" select="$position - 1"/>
  1662.                     <xsl:with-param name="allTabStopStyles" select="$allTabStopStyles"/>
  1663.                 </xsl:call-template>
  1664.             </xsl:when>
  1665.             <xsl:when test="$position = 1">
  1666.                 <xsl:value-of select="concat($width - number(substring-before($allTabStopStyles/style:tab-stop[$position]/@style:position,$unit)), $unit)"/>
  1667.             </xsl:when>
  1668.             <xsl:otherwise>
  1669.                 <xsl:value-of select="concat($width, $unit)"/>
  1670.             </xsl:otherwise>
  1671.         </xsl:choose>
  1672.     </xsl:template>
  1673.  
  1674. </xsl:stylesheet>