home *** CD-ROM | disk | FTP | other *** search
/ PC Professionell 2005 June / PCpro_2005_06.ISO / files / opensource / openoffice / openofficeorg3.cab / master_refs_workaround.xsl < prev    next >
Encoding:
Extensible Markup Language  |  2005-01-31  |  36.3 KB  |  705 lines

  1. <?xml version="1.0" encoding="UTF-8"?>
  2. <!--
  3.  
  4.    $RCSfile: master_refs_workaround.xsl,v $
  5.  
  6.    $Revision: 1.5 $
  7.  
  8.    last change: $Author: rt $ $Date: 2005/01/28 15:24:06 $
  9.  
  10.    The Contents of this file are made available subject to the terms of
  11.    either of the following licenses
  12.  
  13.           - GNU Lesser General Public License Version 2.1
  14.           - Sun Industry Standards Source License Version 1.1
  15.  
  16.    Sun Microsystems Inc., October, 2000
  17.  
  18.    GNU Lesser General Public License Version 2.1
  19.    =============================================
  20.    Copyright 2000 by Sun Microsystems, Inc.
  21.    901 San Antonio Road, Palo Alto, CA 94303, USA
  22.  
  23.    This library is free software; you can redistribute it and/or
  24.    modify it under the terms of the GNU Lesser General Public
  25.    License version 2.1, as published by the Free Software Foundation.
  26.  
  27.    This library is distributed in the hope that it will be useful,
  28.    but WITHOUT ANY WARRANTY; without even the implied warranty of
  29.    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
  30.    Lesser General Public License for more details.
  31.  
  32.    You should have received a copy of the GNU Lesser General Public
  33.    License along with this library; if not, write to the Free Software
  34.    Foundation, Inc., 59 Temple Place, Suite 330, Boston,
  35.    MA  02111-1307  USA
  36.  
  37.  
  38.    Sun Industry Standards Source License Version 1.1
  39.    =================================================
  40.    The contents of this file are subject to the Sun Industry Standards
  41.    Source License Version 1.1 (the "License"); You may not use this file
  42.    except in compliance with the License. You may obtain a copy of the
  43.    License at http://www.openoffice.org/license.html.
  44.  
  45.    Software provided under this License is provided on an "AS IS" basis,
  46.    WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESS OR IMPLIED, INCLUDING,
  47.    WITHOUT LIMITATION, WARRANTIES THAT THE SOFTWARE IS FREE OF DEFECTS,
  48.    MERCHANTABLE, FIT FOR A PARTICULAR PURPOSE, OR NON-INFRINGING.
  49.    See the License for the specific provisions governing your rights and
  50.    obligations concerning the Software.
  51.  
  52.    The Initial Developer of the Original Code is: Sun Microsystems, Inc.
  53.  
  54.    Copyright ┬⌐ 2002 by Sun Microsystems, Inc.
  55.  
  56.    All Rights Reserved.
  57.  
  58.    Contributor(s): _______________________________________
  59.  
  60. -->
  61. <!--
  62.     For further documentation and updates visit http://xml.openoffice.org/sx2ml
  63. -->
  64. <xsl:stylesheet
  65.         xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
  66.         xmlns:office="http://openoffice.org/2000/office"
  67.         xmlns:style="http://openoffice.org/2000/style"
  68.         xmlns:text="http://openoffice.org/2000/text"
  69.         xmlns:table="http://openoffice.org/2000/table"
  70.         xmlns:draw="http://openoffice.org/2000/drawing"
  71.         xmlns:fo="http://www.w3.org/1999/XSL/Format"
  72.         xmlns:xlink="http://www.w3.org/1999/xlink"
  73.         xmlns:number="http://openoffice.org/2000/datastyle"
  74.         xmlns:svg="http://www.w3.org/2000/svg"
  75.         xmlns:chart="http://openoffice.org/2000/chart"
  76.         xmlns:dr3d="http://openoffice.org/2000/dr3d"
  77.         xmlns:math="http://www.w3.org/1998/Math/MathML"
  78.         xmlns:form="http://openoffice.org/2000/form"
  79.         xmlns:script="http://openoffice.org/2000/script"
  80.         xmlns:dc="http://purl.org/dc/elements/1.1/"
  81.         xmlns:meta="http://openoffice.org/2000/meta"
  82.         xmlns:config="http://openoffice.org/2001/config"
  83.         xmlns:help="http://openoffice.org/2000/help"
  84.         xmlns:java="http://xml.apache.org/xslt/java"
  85.         xmlns:sxg="http://www.jclark.com/xt/java/org.openoffice.xslt.OOoMasterDocument"
  86.         xmlns:xt="http://www.jclark.com/xt"
  87.         xmlns:common="http://exslt.org/common"
  88.         xmlns:xalan="http://xml.apache.org/xalan"
  89.         xmlns="http://www.w3.org/1999/xhtml"
  90.         version="1.0"
  91.         exclude-result-prefixes="office style text table draw fo xlink number svg chart dr3d math form script dc meta config help java sxg xt common xalan">
  92.  
  93.  
  94.     <!--
  95.     SUMMARY:
  96.      following parameter triggers a (quite time consuming) workaround for enabling of chapter links in the table-of-content.
  97.  
  98.     IN DETAIL:
  99.      Currently some links used in the Office XML (for example, in the content table as '#7.Some%20Example%20Headline%7Outline')
  100.      are not a valid URLs (cmp. bug id# 102311).
  101.      No file destination is specified nor exist any anchor element for these links in the Office XML.
  102.      A workaround for this transformation therefore had to be made. This time-consuming mechanism is disabled by default and
  103.      can be activated by a parameter (i.e. 'childDocumentExist'). A creation of an anchor is made for each header element.
  104.      All header titles gonna be encoded to be usable in a relative URL.  -->
  105.  
  106.  
  107.     <!--
  108.         CREATION OF A HELPER VARIABLE AS WORKAROUND FOR THE CONTENT TABLE ULR BUG
  109.  
  110.  
  111.         As no valid URL from the content table to the child documents exist in the content table,
  112.         a work-around is done:
  113.  
  114.         First two helper variables are being created.
  115.  
  116.         One containing the list of all references of the master document:
  117.         containg all their title,
  118.         for example:
  119.  
  120.             <chapter-ref title="aTitle 1" />
  121.             <chapter-ref title="aTitle 2" />
  122.             <chapter-ref title="aTitle 2/>
  123.             <chapter-ref title="aTitle 3/>
  124.  
  125.         The other containing all heading from the child documents linked from the master document.
  126.         The variable 'childrenHeadings' contains their title and the number of preceding similar titles,
  127.         for example:
  128.  
  129.  
  130.             <child file-url="aURL">
  131.                 <heading title="aTitle1" level="1">
  132.                 <heading title="aTitle2" level="2">
  133.                 <heading title="aTitle3" level="1">
  134.             </child>
  135.  
  136.         For each chapter reference from the content table the
  137.  
  138.          by encoding the chapter names of the child document with the java URLEncoder and
  139.         use this as a part of a link. Furthermore for all heading elements a encoded anchor will be created from the heading.
  140.         Last the workaround parses all children documents for this anhor, as there is no distinction of files from the content table entries.
  141.  
  142.         The new added node set to the globalData variable concering the content table is written as
  143.  
  144.  
  145.         <content-table-headings>
  146.             <heading file-url="aFileURLToTheGeneratedHeading1" level="1">
  147.             <heading file-url="aFileURLToTheGeneratedHeading2" level="2">
  148.             <heading file-url="aFileURLToTheGeneratedHeading1" level="1">
  149.             <heading file-url="aFileURLToTheGeneratedHeading2" level="2">
  150.         </content-table-headings>
  151.  
  152.  
  153.         Preconditions:
  154.         The correct sequence of child documents according to the Content Table is necessary, granted by the office.
  155.     -->
  156.     <xsl:template name="create-helper-variables-for-Content-Table">
  157.         <xsl:param name="globalData" />
  158.  
  159.         <xsl:if test="$debugEnabled">
  160.             <xsl:message>Creation of master document helper variable for the content table....</xsl:message>
  161.         </xsl:if>
  162.         <!-- Here a helper variable for the content table is created, containing
  163.              all chapter-references which point to a child document.
  164.              In the variable, a 'chapter-ref' element will be created,
  165.              containg the title, stripped from surrounding spaces,
  166.              and the reference, for example:
  167.  
  168.                 <chapter-ref
  169.                     title="sample-Title 1"
  170.                     content-table-id="../dummy.sxw" />
  171.                 <chapter-ref title="a-Title 2" />
  172.                 <chapter-ref title="cTitle 1" />
  173.                 <chapter-ref title="aTitle 3" />
  174.             -->
  175.         <xsl:variable name="chapterRefs-RTF">
  176.             <!-- XPATH starting with '/*/' as the flat and the zipped XML file format have different root elements -->
  177.             <xsl:for-each select="/*/office:body/text:table-of-content/text:index-body/text:p/text:a">
  178.                 <xsl:element name="chapter-ref" namespace="">
  179.                     <xsl:variable name="title"><xsl:apply-templates mode="concatenate" /></xsl:variable>
  180.                     <xsl:attribute name="title">
  181.                         <xsl:value-of select="normalize-space(string($title))"/>
  182.                     </xsl:attribute>
  183.                     <xsl:attribute name="content-table-id">
  184.                         <xsl:value-of select="@xlink:href" />
  185.                     </xsl:attribute>
  186.                 </xsl:element>
  187.             </xsl:for-each>
  188.         </xsl:variable>
  189.  
  190.         <xsl:if test="$debugEnabled">
  191.             <xsl:message>Finished the Creation of master document helper variable for the content table!</xsl:message>
  192.             <xsl:message>Creation of master document helper variable for the child documents...</xsl:message>
  193.         </xsl:if>
  194.         <!-- Here a helper variable of created from the children documents.
  195.              Containg all heading elements from the child documents. Some or all of them are
  196.              chapters referenced by the Global Document.
  197.              The variable contains their title, the level of the heading and the file URL of the child,
  198.              for example:
  199.  
  200.                 <heading title="aTitle1" level="1" file-url="aURL1">
  201.                 <heading title="aTitle2" level="2" file-url="aURL1">
  202.                 <heading title="aTitle3" level="1" file-url="aURL1">
  203.                 <heading title="aTitle4" level="1" file-url="aURL2">
  204.                 <heading title="aTitle5" level="2" file-url="aURL2">
  205.                 <heading title="aTitle2" level="3" file-url="aURL2">
  206.                 <heading title="aTitle6" level="3" file-url="aURL2">
  207.                 <heading-count>7</heading-count>
  208.             -->
  209.         <!-- all headers from children documents will be added -->
  210.         <xsl:variable name="childrenHeadings-RTF">
  211.             <xsl:apply-templates select="/*/office:body/text:section" mode="creation-of-variable" />
  212.         </xsl:variable>
  213.         <xsl:if test="$debugEnabled">
  214.             <xsl:message>Finished the Creation of master document helper variable for the child documents!</xsl:message>
  215.         </xsl:if>
  216.         <xsl:choose>
  217.             <xsl:when test="function-available('xalan:nodeset')">
  218.                 <xsl:call-template name="create-global-variable-for-Content-Table">
  219.                     <xsl:with-param name="chapterRefs" select="xalan:nodeset($chapterRefs-RTF)" />
  220.                     <xsl:with-param name="childrenHeadings" select="xalan:nodeset($childrenHeadings-RTF)" />
  221.                     <xsl:with-param name="globalData" select="$globalData" />
  222.                 </xsl:call-template>
  223.             </xsl:when>
  224.             <xsl:when test="function-available('common:node-set')">
  225.                 <xsl:call-template name="create-global-variable-for-Content-Table">
  226.                     <xsl:with-param name="chapterRefs" select="common:node-set($chapterRefs-RTF)" />
  227.                     <xsl:with-param name="childrenHeadings" select="common:node-set($childrenHeadings-RTF)" />
  228.                     <xsl:with-param name="globalData" select="$globalData" />
  229.                 </xsl:call-template>
  230.             </xsl:when>
  231.             <xsl:when test="function-available('xt:node-set')">
  232.                 <xsl:call-template name="create-global-variable-for-Content-Table">
  233.                     <xsl:with-param name="chapterRefs" select="xt:node-set($chapterRefs-RTF)" />
  234.                     <xsl:with-param name="childrenHeadings" select="xt:node-set($childrenHeadings-RTF)" />
  235.                     <xsl:with-param name="globalData" select="$globalData" />
  236.                 </xsl:call-template>
  237.             </xsl:when>
  238.             <xsl:otherwise>
  239.                 <xsl:message terminate="yes">ERROR: Functions for node-set conversion not found!</xsl:message>
  240.             </xsl:otherwise>
  241.         </xsl:choose>
  242.     </xsl:template>
  243.  
  244.  
  245.     <xsl:template name="create-global-variable-for-Content-Table">
  246.         <xsl:param name="chapterRefs" />
  247.         <xsl:param name="childrenHeadings" />
  248.         <xsl:param name="globalData" />
  249.  
  250.         <xsl:if test="$debugEnabled">
  251.             <!-- helper variable collecting all headings from the master document file children-->
  252.             <xsl:for-each select="$childrenHeadings/heading">
  253.                 <xsl:message>#              <xsl:value-of select="position()" />
  254.                 </xsl:message>
  255.                 <xsl:message>level:         <xsl:value-of select="@level" />
  256.                 </xsl:message>
  257.                 <xsl:message>title:         <xsl:value-of select="@title" />
  258.                 </xsl:message>
  259.                 <xsl:message>encoded-title: <xsl:value-of select="@encoded-title" />
  260.                 </xsl:message>
  261.                 <xsl:message>file-url:      <xsl:value-of select="@file-url" />
  262.                 </xsl:message>
  263.                 <xsl:message>header-no:     <xsl:value-of select="@header-no" />
  264.                 </xsl:message>
  265.                 <xsl:message>**</xsl:message>
  266.             </xsl:for-each>
  267.             <!-- helper variable collecting all heading references from the content table of the the master document -->
  268.             <xsl:message>+-+-+ childrenHeadings/heading-count: <xsl:value-of select="$childrenHeadings/heading-count" />
  269.             </xsl:message>
  270.             <xsl:for-each select="$chapterRefs/chapter-ref">
  271.                 <xsl:message># <xsl:value-of select="position()" />
  272.                 </xsl:message>
  273.                 <xsl:message>title: <xsl:value-of select="@title" />
  274.                 </xsl:message>
  275.                 <xsl:message>**</xsl:message>
  276.             </xsl:for-each>
  277.         </xsl:if>
  278.  
  279.         <xsl:choose>
  280.             <xsl:when test="function-available('sxg:set-heading-no')">
  281.                 <xsl:value-of select="sxg:set-heading-no(1)" />
  282.                 <xsl:value-of select="sxg:set-current-child-no(1)" />
  283.                 <xsl:value-of select="sxg:set-current-child-url(string($childrenHeadings/heading/@file-url))" />
  284.             </xsl:when>
  285.             <xsl:when test="function-available('java:org.openoffice.xslt.OOoMasterDocument.setHeadingNo')">
  286.                 <xsl:value-of select="java:org.openoffice.xslt.OOoMasterDocument.setHeadingNo(1)" />
  287.                 <xsl:value-of select="java:org.openoffice.xslt.OOoMasterDocument.setCurrentChildNo(1)" />
  288.                 <xsl:value-of select="java:org.openoffice.xslt.OOoMasterDocument.setCurrentChildUrl(string($childrenHeadings/heading/@file-ur))" />
  289.             </xsl:when>
  290.         </xsl:choose>
  291.  
  292.         <xsl:if test="$debugEnabled">
  293.             <xsl:message>Creating master document variable for chapter relations....</xsl:message>
  294.         </xsl:if>
  295.         <xsl:variable name="contentTableHeadingsGlobalData-RTF">
  296.             <xsl:element name="content-table-headings" namespace="">
  297.  
  298.                 <!-- had to use a for loop, as a recursion ends with an stackoverflow exception after about 600 recursive calls -->
  299.                 <xsl:choose>
  300.                     <xsl:when test="function-available('sxg:get-heading-no')">
  301.                         <xsl:for-each select="$chapterRefs/chapter-ref">
  302.                             <xsl:call-template name="searchHeadingInChildDocument">
  303.                                 <xsl:with-param name="chapterRefs" select="$chapterRefs" />
  304.                                 <xsl:with-param name="childrenHeadings" select="$childrenHeadings" />
  305.                                 <xsl:with-param name="currentChapterRefNo" select="position()" />
  306.                                 <xsl:with-param name="currentHeadingNo" select="sxg:get-heading-no()" />
  307.                                 <xsl:with-param name="currentChildURL" select="sxg:get-current-child-url()" />
  308.                                 <xsl:with-param name="currentChildNo" select="sxg:get-current-child-no()" />
  309.                             </xsl:call-template>
  310.                         </xsl:for-each>
  311.                     </xsl:when>
  312.                     <xsl:when test="function-available('java:org.openoffice.xslt.OOoMasterDocument.getHeadingNo')">
  313.                         <xsl:for-each select="$chapterRefs/chapter-ref">
  314.                             <xsl:call-template name="searchHeadingInChildDocument">
  315.                                 <xsl:with-param name="chapterRefs" select="$chapterRefs" />
  316.                                 <xsl:with-param name="childrenHeadings" select="$childrenHeadings" />
  317.                                 <xsl:with-param name="currentChapterRefNo" select="position()" />
  318.                                 <xsl:with-param name="currentHeadingNo" select="java:org.openoffice.xslt.OOoMasterDocument.getHeadingNo()" />
  319.                                 <xsl:with-param name="currentChildURL" select="java:org.openoffice.xslt.OOoMasterDocument.getCurrentChildUrl()" />
  320.                                 <xsl:with-param name="currentChildNo" select="java:org.openoffice.xslt.OOoMasterDocument.getCurrentChildNo()" />
  321.                             </xsl:call-template>
  322.                         </xsl:for-each>
  323.                     </xsl:when>
  324.                     <xsl:otherwise>
  325.                         <xsl:message terminate="yes">ERROR: Function not found: java:org.openoffice.xslt.OOoMasterDocument.getHeadingNo()</xsl:message>
  326.                     </xsl:otherwise>
  327.                 </xsl:choose>
  328.             </xsl:element>
  329.  
  330.             <!-- adding the already exisiting global data environment -->
  331.             <xsl:copy-of select="$globalData" />
  332.         </xsl:variable>
  333.         <xsl:if test="$debugEnabled">
  334.             <xsl:message>Finished master document variable for chapter relations!</xsl:message>
  335.         </xsl:if>
  336.  
  337.         <xsl:choose>
  338.             <xsl:when test="function-available('xalan:nodeset')">
  339.                 <xsl:call-template name="start-self-and-children-transformation">
  340.                     <xsl:with-param name="globalData" select="xalan:nodeset($contentTableHeadingsGlobalData-RTF)" />
  341.                 </xsl:call-template>
  342.             </xsl:when>
  343.             <xsl:when test="function-available('xt:node-set')">
  344.                 <xsl:call-template name="start-self-and-children-transformation">
  345.                     <xsl:with-param name="globalData" select="xt:node-set($contentTableHeadingsGlobalData-RTF)" />
  346.                 </xsl:call-template>
  347.             </xsl:when>
  348.             <xsl:when test="function-available('common:node-set')">
  349.                 <xsl:call-template name="start-self-and-children-transformation">
  350.                     <xsl:with-param name="globalData" select="common:node-set($contentTableHeadingsGlobalData-RTF)" />
  351.                 </xsl:call-template>
  352.             </xsl:when>
  353.             <xsl:otherwise>
  354.                 <xsl:message terminate="yes">ERROR: Function not found: java:org.openoffice.xslt.OOoMasterDocument.getOutputURLForHTML</xsl:message>
  355.             </xsl:otherwise>
  356.         </xsl:choose>
  357.     </xsl:template>
  358.  
  359.  
  360.     <xsl:template name="searchHeadingInChildDocument">
  361.         <xsl:param name="chapterRefs" />
  362.         <xsl:param name="childrenHeadings" />
  363.         <xsl:param name="currentChapterRefNo" />
  364.         <xsl:param name="currentHeadingNo" />
  365.         <xsl:param name="currentChildURL" />
  366.         <xsl:param name="currentChildNo" />
  367.         <xsl:variable name="currentChapterRef" select="$chapterRefs/chapter-ref[$currentChapterRefNo]" />
  368.         <xsl:variable name="currentChapterID" select="$currentChapterRef/@content-table-id" />
  369.         <xsl:variable name="currentChapterTitle" select="$currentChapterRef/@title" />
  370.         <xsl:variable name="currentChildHeading" select="$childrenHeadings/heading[$currentHeadingNo]" />
  371.         <xsl:variable name="headingTitle" select="$currentChildHeading/@title" />
  372.         <xsl:variable name="headingLevel" select="$currentChildHeading/@level" />
  373.         <xsl:variable name="headingNo" select="$currentChildHeading/@header-no" />
  374.         <xsl:variable name="newChildURL" select="string($currentChildHeading/@file-url)" />
  375.  
  376.         <xsl:if test="$debugEnabled">
  377.             <xsl:message>*** new heading </xsl:message>
  378.             <xsl:message>currentChapterID:    <xsl:value-of select="$currentChapterID" />
  379.             </xsl:message>
  380.             <xsl:message>currentChapterTitle: <xsl:value-of select="$currentChapterTitle" />
  381.             </xsl:message>
  382.             <xsl:message>currentChapterID:    <xsl:value-of select="$currentChapterID" />
  383.             </xsl:message>
  384.             <xsl:message>currentHeadingNo:    <xsl:value-of select="$currentHeadingNo" />
  385.             </xsl:message>
  386.             <xsl:message>headingTitle:        <xsl:value-of select="$headingTitle" />
  387.             </xsl:message>
  388.             <xsl:message>headingLevel:        <xsl:value-of select="$headingLevel" />
  389.             </xsl:message>
  390.             <xsl:message>headingNo:           <xsl:value-of select="$headingNo" />
  391.             </xsl:message>
  392.             <xsl:message>newChildURL:         <xsl:value-of select="$newChildURL" />
  393.             </xsl:message>
  394.         </xsl:if>
  395.  
  396.         <xsl:variable name="isNewFile" select="string($newChildURL) != string($currentChildURL)" />
  397.         <xsl:if test="$isNewFile">
  398.             <!-- reset of the already collected child headers -->
  399.             <xsl:call-template name="calc-chapter-numbers">
  400.                 <xsl:with-param name="level" select="0" />
  401.             </xsl:call-template>
  402.         </xsl:if>
  403.         <xsl:variable name="absoluteChapterLevel">
  404.             <xsl:call-template name="calc-chapter-numbers">
  405.                 <xsl:with-param name="level" select="number($headingLevel)" />
  406.             </xsl:call-template>
  407.         </xsl:variable>
  408.  
  409.         <xsl:variable name="isChapterHeading" select="$headingTitle = $currentChapterTitle" />
  410.  
  411.         <xsl:variable name="outFileURL">
  412.             <xsl:choose>
  413.                 <xsl:when test="function-available('sxg:get-output-u-r-l-for-h-t-m-l')">
  414.                     <xsl:value-of select="sxg:get-output-u-r-l-for-h-t-m-l($newChildURL)" />
  415.                 </xsl:when>
  416.                 <xsl:when test="function-available('java:org.openoffice.xslt.OOoMasterDocument.getOutputURLForHTML')">
  417.                     <xsl:value-of select="java:org.openoffice.xslt.OOoMasterDocument.getOutputURLForHTML($newChildURL)" />
  418.                 </xsl:when>
  419.                 <xsl:otherwise>
  420.                     <xsl:message terminate="yes">ERROR: Function not found: java:org.openoffice.xslt.OOoMasterDocument.getOutputURLForHTML</xsl:message>
  421.                 </xsl:otherwise>
  422.             </xsl:choose>
  423.         </xsl:variable>
  424.  
  425.         <xsl:element name="heading" namespace="">
  426.             <!-- necessary to as ID from the content table to get the correct heading element (the buggy URL used as ID)-->
  427.             <xsl:attribute name="content-table-id">
  428.                 <xsl:choose>
  429.                     <xsl:when test="$isChapterHeading">
  430.                         <xsl:value-of select="$currentChapterID" />
  431.                     </xsl:when>
  432.                     <xsl:otherwise>
  433.                         <xsl:text>only a heading, but not a chapter</xsl:text>
  434.                     </xsl:otherwise>
  435.                 </xsl:choose>
  436.             </xsl:attribute>
  437.             <!-- no of the used child, necessary for quick finding of chapters of next file  -->
  438.             <xsl:attribute name="child-document-no">
  439.                 <xsl:choose>
  440.                     <xsl:when test="$isNewFile">
  441.                         <xsl:value-of select="$currentChildNo + 1" />
  442.                     </xsl:when>
  443.                     <xsl:otherwise>
  444.                         <xsl:value-of select="$currentChildNo" />
  445.                     </xsl:otherwise>
  446.                 </xsl:choose>
  447.             </xsl:attribute>
  448.             <!-- the URL of the child document source, containing the heading -->
  449.             <xsl:attribute name="file-url">
  450.                 <xsl:value-of select="$newChildURL" />
  451.             </xsl:attribute>
  452.             <xsl:attribute name="out-file-url">
  453.                 <xsl:value-of select="$outFileURL" />
  454.             </xsl:attribute>
  455.             <xsl:attribute name="level">
  456.                 <xsl:value-of select="$headingLevel" />
  457.             </xsl:attribute>
  458.             <xsl:attribute name="title">
  459.                 <xsl:value-of select="$headingTitle" />
  460.             </xsl:attribute>
  461.             <xsl:attribute name="encoded-title">
  462.                 <xsl:value-of select="$currentChildHeading/@encoded-title" />
  463.             </xsl:attribute>
  464.             <xsl:attribute name="absolute-chapter-level">
  465.                 <xsl:value-of select="$absoluteChapterLevel" />
  466.             </xsl:attribute>
  467.         </xsl:element>
  468.  
  469.  
  470.         <xsl:choose>
  471.             <xsl:when test="$childrenHeadings/heading-count != $currentHeadingNo">
  472.                 <!-- procede as long the list of children isn'nt worked through -->
  473.                 <xsl:choose>
  474.                     <xsl:when test="$isChapterHeading">
  475.                         <!-- global variables have to be set, so the for-each loop can access them -->
  476.                         <xsl:choose>
  477.                             <xsl:when test="function-available('sxg:set-heading-no')">
  478.                                 <xsl:value-of select="sxg:set-heading-no($currentHeadingNo + 1)" />
  479.                                 <xsl:if test="$isNewFile">
  480.                                     <xsl:value-of select="sxg:set-current-child-no($currentChildNo + 1)" />
  481.                                     <xsl:value-of select="sxg:set-current-child-url(string($newChildURL))" />
  482.                                 </xsl:if>
  483.                             </xsl:when>
  484.                             <xsl:when test="function-available('java:org.openoffice.xslt.OOoMasterDocument.setHeadingNo')">
  485.                                 <xsl:value-of select="java:org.openoffice.xslt.OOoMasterDocument.setHeadingNo($currentHeadingNo + 1)" />
  486.                                 <xsl:if test="$isNewFile">
  487.                                     <xsl:value-of select="java:org.openoffice.xslt.OOoMasterDocument.setCurrentChildNo($currentChildNo + 1)" />
  488.                                     <xsl:value-of select="java:org.openoffice.xslt.OOoMasterDocument.setCurrentChildUrl($newChildURL)" />
  489.                                 </xsl:if>
  490.                             </xsl:when>
  491.                             <xsl:otherwise>
  492.                                 <xsl:message terminate="yes">ERROR: Function not found: java:org.openoffice.xslt.OOoMasterDocument.setHeadingNo</xsl:message>
  493.                             </xsl:otherwise>
  494.                         </xsl:choose>
  495.                     </xsl:when>
  496.                     <xsl:otherwise>
  497.                         <!-- not a chapter heading, call itself until a chapter ref is found or the end of headings is reached -->
  498.                         <xsl:call-template name="searchHeadingInChildDocument">
  499.                             <xsl:with-param name="chapterRefs" select="$chapterRefs" />
  500.                             <xsl:with-param name="childrenHeadings" select="$childrenHeadings" />
  501.                             <xsl:with-param name="currentChapterRefNo" select="$currentChapterRefNo" />
  502.                             <xsl:with-param name="currentHeadingNo" select="$currentHeadingNo + 1" />
  503.                             <xsl:with-param name="currentChildURL" select="$currentChildURL" />
  504.                             <xsl:with-param name="currentChildNo" select="$currentChildNo" />
  505.                         </xsl:call-template>
  506.                     </xsl:otherwise>
  507.                 </xsl:choose>
  508.             </xsl:when>
  509.             <xsl:otherwise>
  510.                 <xsl:if test="$debugEnabled">
  511.                     <xsl:message>All child documents have been walked through without finding the chapter name!</xsl:message>
  512.                     <xsl:message>       childrenHeadings/heading-count:    <xsl:value-of select="$childrenHeadings/heading-count" />
  513.                     </xsl:message>
  514.                     <xsl:message>       currentHeadingNo:                  <xsl:value-of select="$currentHeadingNo" />
  515.                     </xsl:message>
  516.                 </xsl:if>
  517.             </xsl:otherwise>
  518.         </xsl:choose>
  519.     </xsl:template>
  520.  
  521.  
  522.     <!-- To make the headings unique, the absolute heading is added to them
  523.          E.g. The level 1.2.3.4. would result into a 1_2_3_4 string -->
  524.     <xsl:template name="calc-chapter-numbers">
  525.         <xsl:param name="level" />
  526.  
  527.         <xsl:choose>
  528.             <xsl:when test="function-available('sxg:calc-chapter-numbers')">
  529.                 <xsl:value-of select="sxg:calc-chapter-numbers($level)" />
  530.             </xsl:when>
  531.             <xsl:when test="function-available('java:org.openoffice.xslt.OOoMasterDocument.calcChapterNumbers')">
  532.                 <xsl:value-of select="java:org.openoffice.xslt.OOoMasterDocument.calcChapterNumbers($level)" />
  533.             </xsl:when>
  534.             <xsl:otherwise>
  535.                 <xsl:message terminate="yes">ERROR: Function not found: java:org.openoffice.xslt.OOoMasterDocument.calcChapterNumbers</xsl:message>
  536.             </xsl:otherwise>
  537.         </xsl:choose>
  538.     </xsl:template>
  539.  
  540.     <!-- ******************************************************************************* -->
  541.     <!-- ***  Creation of helper variable of the headings of all children documents  *** -->
  542.     <!-- ******************************************************************************* -->
  543.  
  544.  
  545.     <xsl:template match="/*/office:body/text:section" mode="creation-of-variable">
  546.  
  547.         <xsl:call-template name="parseHeadingsFromChildren" />
  548.  
  549.         <!-- after the last child document the master document will be parsed -->
  550.         <xsl:if test="position() = last()">
  551.             <!-- search the master document after all child documents have been searched
  552.  
  553.  
  554.             Office SDK PATCH NO INDEX ELEMENT WANTED !! - null pointer exception
  555.             <xsl:call-template name="getPreviousHeaderNo">
  556.                 <xsl:with-param name="amountOfCurrentHeading"   select="count(following-sibling::text:h)" />
  557.                 <xsl:with-param name="nodeToSearchForHeading"   select="following-sibling::text:h" />
  558.             </xsl:call-template>
  559.                                                                     -->
  560.  
  561.            <!-- get the overall No of Headers -->
  562.             <xsl:call-template name="getAllHeaderNo" />
  563.         </xsl:if>
  564.     </xsl:template>
  565.  
  566.  
  567.     <!-- redirection to have a speakable template name -->
  568.     <xsl:template name="parseHeadingsFromChildren">
  569.         <xsl:variable name="fileRef" select="string(text:section-source/@xlink:href)" />
  570.         <xsl:choose>
  571.             <xsl:when test="function-available('sxg:get-content-u-r-l')">
  572.                 <xsl:call-template name="getContentRootNode">
  573.                     <xsl:with-param name="fileURL" select="sxg:get-content-u-r-l($fileRef)" />
  574.                 </xsl:call-template>
  575.             </xsl:when>
  576.             <xsl:when test="function-available('java:org.openoffice.xslt.OOoMasterDocument.getContentURL')">
  577.                 <xsl:call-template name="getContentRootNode">
  578.                     <xsl:with-param name="fileURL" select="java:org.openoffice.xslt.OOoMasterDocument.getContentURL($fileRef)" />
  579.                 </xsl:call-template>
  580.             </xsl:when>
  581.             <xsl:otherwise>
  582.                 <xsl:message terminate="yes">ERROR: Function not found: java:org.openoffice.xslt.OOoMasterDocument.getContentURL!</xsl:message>
  583.             </xsl:otherwise>
  584.         </xsl:choose>
  585.     </xsl:template>
  586.  
  587.  
  588.     <xsl:template name="getContentRootNode">
  589.         <xsl:param name="fileURL" />
  590.  
  591.         <xsl:variable name="childRootNode" select="document($fileURL)" />
  592.         <xsl:call-template name="getPreviousHeaderNo">
  593.             <xsl:with-param name="fileURL" select="$fileURL" />
  594.             <!-- the absolute source path will be added as prefix -->
  595.             <xsl:with-param name="amountOfCurrentHeading" select="count($childRootNode/*/office:body/descendant::text:h)" />
  596.             <xsl:with-param name="nodeToSearchForHeading" select="$childRootNode/*/office:body/descendant::text:h" />
  597.         </xsl:call-template>
  598.  
  599.     </xsl:template>
  600.  
  601.  
  602.     <xsl:template name="getPreviousHeaderNo">
  603.         <xsl:param name="fileURL" />
  604.         <xsl:param name="nodeToSearchForHeading" />
  605.         <xsl:param name="amountOfCurrentHeading" />
  606.  
  607.         <xsl:choose>
  608.             <xsl:when test="function-available('sxg:get-previous-child-documents-heading-count')">
  609.                 <xsl:call-template name="addHeadingInfo">
  610.                     <xsl:with-param name="nodeToSearchForHeading" select="$nodeToSearchForHeading" />
  611.                     <xsl:with-param name="fileURL" select="$fileURL" />
  612.                     <xsl:with-param name="previousHeader" select="sxg:get-previous-child-documents-heading-count($amountOfCurrentHeading)" />
  613.                 </xsl:call-template>
  614.             </xsl:when>
  615.             <xsl:when test="function-available('java:org.openoffice.xslt.OOoMasterDocument.getPreviousChildDocumentsHeadingCount')">
  616.                 <xsl:call-template name="addHeadingInfo">
  617.                     <xsl:with-param name="nodeToSearchForHeading" select="$nodeToSearchForHeading" />
  618.                     <xsl:with-param name="fileURL" select="$fileURL" />
  619.                     <xsl:with-param name="previousHeader" select="java:org.openoffice.xslt.OOoMasterDocument.getPreviousChildDocumentsHeadingCount($amountOfCurrentHeading)" />
  620.                 </xsl:call-template>
  621.             </xsl:when>
  622.             <xsl:otherwise>
  623.                 <xsl:message terminate="yes">ERROR: Function not found: java:org.openoffice.xslt.OOoMasterDocument.getPreviousChildDocumentsHeadingCount</xsl:message>
  624.             </xsl:otherwise>
  625.         </xsl:choose>
  626.  
  627.     </xsl:template>
  628.  
  629.  
  630.     <xsl:template name="addHeadingInfo">
  631.         <xsl:param name="fileURL" />
  632.         <xsl:param name="previousHeader" />
  633.         <xsl:param name="nodeToSearchForHeading" />
  634.  
  635.         <xsl:variable name="previousHeader2" select="number($previousHeader)" />
  636.         <xsl:for-each select="$nodeToSearchForHeading">
  637.             <xsl:variable name="title"><xsl:apply-templates mode="concatenate" /></xsl:variable>
  638.             <xsl:variable name="encodedTitle">
  639.                 <xsl:call-template name="encode-string">
  640.                     <!-- the space has to be normalized,
  641.                         otherwise an illegal argument exception will be thrown for XT-->
  642.                     <xsl:with-param name="textToBeEncoded" select="normalize-space(string($title))" />
  643.                 </xsl:call-template>
  644.             </xsl:variable>
  645.             <!--
  646.             <xsl:if test="$debugEnabled">
  647.                 <xsl:message>
  648.                     title:<xsl:value-of select="$title" />
  649.                     encoded-title:<xsl:value-of select="$encodedTitle" />
  650.                     level:<xsl:value-of select="@text:level" />
  651.                     file-uRL:<xsl:value-of select="$fileURL" />
  652.                     header-no:<xsl:value-of select="position() + $previousHeader2" />
  653.                 </xsl:message>
  654.             </xsl:if>
  655.             -->
  656.             <xsl:element name="heading" namespace="">
  657.                 <!-- odd but 'descendant:text()' didn't work, but '.', to get all text nodes of the header -->
  658.                 <xsl:attribute name="title">
  659.                     <xsl:value-of select="normalize-space(string($title))" />
  660.                 </xsl:attribute>
  661.                 <xsl:attribute name="encoded-title">
  662.                     <xsl:value-of select="$encodedTitle" />
  663.                 </xsl:attribute>
  664.                 <xsl:attribute name="level">
  665.                     <xsl:value-of select="@text:level" />
  666.                 </xsl:attribute>
  667.                 <xsl:attribute name="file-url">
  668.                     <xsl:value-of select="$fileURL" />
  669.                 </xsl:attribute>
  670.                 <xsl:attribute name="header-no">
  671.                     <xsl:value-of select="position() + $previousHeader2" />
  672.                 </xsl:attribute>
  673.             </xsl:element>
  674.         </xsl:for-each>
  675.     </xsl:template>
  676.  
  677.  
  678.     <xsl:template name="getAllHeaderNo">
  679.         <xsl:choose>
  680.             <xsl:when test="function-available('sxg:get-all-child-documents-heading-count')">
  681.                 <xsl:call-template name="addAllHeaderNoElement">
  682.                     <xsl:with-param name="allHeader" select="sxg:get-all-child-documents-heading-count()" />
  683.                 </xsl:call-template>
  684.             </xsl:when>
  685.             <xsl:when test="function-available('java:org.openoffice.xslt.OOoMasterDocument.getAllChildDocumentsHeadingCount')">
  686.                 <xsl:call-template name="addAllHeaderNoElement">
  687.                     <xsl:with-param name="allHeader" select="java:org.openoffice.xslt.OOoMasterDocument.getAllChildDocumentsHeadingCount()" />
  688.                 </xsl:call-template>
  689.             </xsl:when>
  690.             <xsl:otherwise>
  691.                 <xsl:message terminate="yes">ERROR: Function not found: nodeset</xsl:message>
  692.             </xsl:otherwise>
  693.         </xsl:choose>
  694.     </xsl:template>
  695.  
  696.     <xsl:template name="addAllHeaderNoElement">
  697.         <xsl:param name="allHeader" />
  698.  
  699.         <xsl:element name="heading-count" namespace="">
  700.             <xsl:value-of select="$allHeader" />
  701.         </xsl:element>
  702.     </xsl:template>
  703.  
  704. </xsl:stylesheet>
  705.