home *** CD-ROM | disk | FTP | other *** search
/ PC World 2004 October / PCWorld_2004-10_cd.bin / akce / openoffice / f_0392 / style_inlined.xsl
Text File  |  2003-04-04  |  24KB  |  399 lines

  1. <!--
  2.  
  3.    The Contents of this file are made available subject to the terms of
  4.    either of the following licenses
  5.  
  6.           - GNU Lesser General Public License Version 2.1
  7.           - Sun Industry Standards Source License Version 1.1
  8.  
  9.    Sun Microsystems Inc., October, 2000
  10.  
  11.    GNU Lesser General Public License Version 2.1
  12.    =============================================
  13.    Copyright 2000 by Sun Microsystems, Inc.
  14.    901 San Antonio Road, Palo Alto, CA 94303, USA
  15.  
  16.    This library is free software; you can redistribute it and/or
  17.    modify it under the terms of the GNU Lesser General Public
  18.    License version 2.1, as published by the Free Software Foundation.
  19.  
  20.    This library is distributed in the hope that it will be useful,
  21.    but WITHOUT ANY WARRANTY; without even the implied warranty of
  22.    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
  23.    Lesser General Public License for more details.
  24.  
  25.    You should have received a copy of the GNU Lesser General Public
  26.    License along with this library; if not, write to the Free Software
  27.    Foundation, Inc., 59 Temple Place, Suite 330, Boston,
  28.    MA  02111-1307  USA
  29.  
  30.  
  31.    Sun Industry Standards Source License Version 1.1
  32.    =================================================
  33.    The contents of this file are subject to the Sun Industry Standards
  34.    Source License Version 1.1 (the "License"); You may not use this file
  35.    except in compliance with the License. You may obtain a copy of the
  36.    License at http://www.openoffice.org/license.html.
  37.  
  38.    Software provided under this License is provided on an "AS IS" basis,
  39.    WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESS OR IMPLIED, INCLUDING,
  40.    WITHOUT LIMITATION, WARRANTIES THAT THE SOFTWARE IS FREE OF DEFECTS,
  41.    MERCHANTABLE, FIT FOR A PARTICULAR PURPOSE, OR NON-INFRINGING.
  42.    See the License for the specific provisions governing your rights and
  43.    obligations concerning the Software.
  44.  
  45.    The Initial Developer of the Original Code is: Sun Microsystems, Inc.
  46.  
  47.    Copyright ┬⌐ 2002 by Sun Microsystems, Inc.
  48.  
  49.    All Rights Reserved.
  50.  
  51.    Contributor(s): _______________________________________
  52.  
  53. -->
  54. <xsl:stylesheet version="1.0"
  55.                 xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
  56.                 xmlns:office="http://openoffice.org/2000/office"
  57.                 xmlns:style="http://openoffice.org/2000/style"
  58.                 xmlns:text="http://openoffice.org/2000/text"
  59.                 xmlns:table="http://openoffice.org/2000/table"
  60.                 xmlns:draw="http://openoffice.org/2000/drawing"
  61.                 xmlns:fo="http://www.w3.org/1999/XSL/Format"
  62.                 xmlns:xlink="http://www.w3.org/1999/xlink"
  63.                 xmlns:number="http://openoffice.org/2000/datastyle"
  64.                 xmlns:svg="http://www.w3.org/2000/svg"
  65.                 xmlns:chart="http://openoffice.org/2000/chart"
  66.                 xmlns:dr3d="http://openoffice.org/2000/dr3d"
  67.                 xmlns:math="http://www.w3.org/1998/Math/MathML"
  68.                 xmlns:form="http://openoffice.org/2000/form"
  69.                 xmlns:script="http://openoffice.org/2000/script"
  70.                 office:class="text"
  71.                 office:version="1.0"
  72.                 xmlns:dc="http://purl.org/dc/elements/1.1/"
  73.                 xmlns:meta="http://openoffice.org/2000/meta"
  74.                 xmlns:config="http://openoffice.org/2001/config"
  75.                 xmlns:help="http://openoffice.org/2000/help"
  76.                 xmlns:xt="http://www.jclark.com/xt"
  77.                 xmlns:system="http://www.jclark.com/xt/java/java.lang.System"
  78.                 xmlns:xalan="http://xml.apache.org/xalan"
  79.                 xmlns:java="http://xml.apache.org/xslt/java"
  80.                 exclude-result-prefixes="java">
  81.  
  82.  
  83.  
  84.     <!-- ********************************************* -->
  85.     <!-- *** hard attributed (inlined) properties  *** -->
  86.     <!-- ********************************************* -->
  87.  
  88.  
  89.     <!-- RESTRICTIONS:
  90.             1)  As the styles-node-variables are NOT global, the style variables are not global, either!!
  91.             2)  As a list of elements can only be added to a variable as a result tree fragment the
  92.                 extension is neccessary!!
  93.     -->
  94.  
  95.     <!-- 2DO: Inline styles do not inherit from XML office defaults nor font:family defaults as the style header does
  96.               (cp. stylesheet 'style_header.xsl' and the 'write-default-styles' template) -->
  97.  
  98.     <xsl:template name='create-all-inline-styles'>
  99.  
  100.         <!--** traversee all style trees and their branches collecting style properties **-->
  101.         <xsl:element name="allstyles">
  102.         <!--** traversee all office:styles trees beginning with the top-level styles**-->
  103.             <xsl:for-each select="$office:styles/style:style[not(@style:parent-style-name)]">
  104.  
  105.                 <!--** give out the style properties of the parent node **-->
  106.                 <xsl:call-template name='write-current-and-inherited-style-properties'>
  107.                     <xsl:with-param name="styles-node"                  select="$office:styles"/>
  108.                     <xsl:with-param name="style-family"                 select="@style:family"/>
  109.                     <xsl:with-param name="style-name-tokenized"         select="translate(@style:name, '. %()/\', '')"/>
  110.                 </xsl:call-template>
  111.  
  112.                 <!--** all office:styles children of the current top-level office:styles **-->
  113.                 <xsl:call-template name='for-all-templates-child-styles'>
  114.                     <xsl:with-param name="parentStyleName"              select="@style:name"/>
  115.                     <xsl:with-param name="parentStyleFamily"            select="@style:family"/>
  116.                     <xsl:with-param name="style-name-tokenized"         select="translate(@style:name, '. %()/\', '')"/>
  117.                 </xsl:call-template>
  118.  
  119.                 <!--** all office:automatic-styles children of the current top-level style **-->
  120.                 <xsl:call-template name='for-all-automatic-child-styles'>
  121.                     <xsl:with-param name="parentStyleName"              select="@style:name"/>
  122.                     <xsl:with-param name="parentStyleFamily"            select="@style:family"/>
  123.                     <xsl:with-param name="style-name-tokenized"         select="translate(@style:name, '. %()/\', '')"/>
  124.                 </xsl:call-template>
  125.             </xsl:for-each>
  126.  
  127.         <!--** traversee all office:automatic-styles trees beginning with the top-level styles **-->
  128.             <xsl:for-each select="$office:automatic-styles/style:style[not(@style:parent-style-name)]">
  129.                 <!--** give out the style properties of the parent node **-->
  130.                 <xsl:call-template name='write-current-and-inherited-style-properties'>
  131.                     <xsl:with-param name="styles-node"                  select="$office:automatic-styles"/>
  132.                     <xsl:with-param name="style-family"                 select="@style:family"/>
  133.                     <xsl:with-param name="style-name-tokenized"         select="translate(@style:name, '. %()/\', '')"/>
  134.                 </xsl:call-template>
  135.  
  136.                 <!--** all children of the top-level office:automatic-styless  **-->
  137.                 <xsl:call-template name='for-all-automatic-child-styles'>
  138.                     <xsl:with-param name="parentStyleName"              select="@style:name"/>
  139.                     <xsl:with-param name="parentStyleFamily"            select="@style:family"/>
  140.                     <xsl:with-param name="style-name-tokenized"         select="translate(@style:name, '. %()/\', '')"/>
  141.                 </xsl:call-template>
  142.             </xsl:for-each>
  143.         </xsl:element>
  144.     </xsl:template>
  145.  
  146.  
  147.  
  148.     <xsl:template name='for-all-templates-child-styles'>
  149.         <xsl:param name="parentStyleName"/>
  150.         <xsl:param name="parentStyleFamily"/>
  151.         <xsl:param name="style-name-tokenized"/>
  152.  
  153.         <xsl:for-each select="../style:style[@style:family=$parentStyleFamily and @style:parent-style-name=$parentStyleName]">
  154.             <!--** give out the style properties of the current node **-->
  155.             <xsl:element name="{$style-name-tokenized}">
  156.                 <xsl:call-template name='write-current-and-inherited-style-properties'>
  157.                     <xsl:with-param name="styles-node"                  select="$office:styles"/>
  158.                     <xsl:with-param name="style-family"                 select="@style:family"/>
  159.                     <xsl:with-param name="style-name-tokenized"         select="translate(@style:name, '. %()/\', '')"/>
  160.                 </xsl:call-template>
  161.             </xsl:element>
  162.  
  163.             <!--** for all template-children of the current office:styles  **-->
  164.             <xsl:call-template name='for-all-templates-child-styles'>
  165.                 <xsl:with-param name="styles-node"                  select="$office:styles"/>
  166.                 <xsl:with-param name="parentStyleName"              select="@style:name"/>
  167.                 <xsl:with-param name="parentStyleFamily"            select="@style:family"/>
  168.                 <xsl:with-param name="style-name-tokenized"         select="translate(@style:name, '. %()/\', '')"/>
  169.             </xsl:call-template>
  170.  
  171.             <!--** for all automatic-children of the current office:styles  **-->
  172.             <xsl:call-template name='for-all-automatic-child-styles'>
  173.                 <xsl:with-param name="styles-node"                  select="$office:automatic-styles"/>
  174.                 <xsl:with-param name="parentStyleName"              select="@style:name"/>
  175.                 <xsl:with-param name="parentStyleFamily"            select="@style:family"/>
  176.                 <xsl:with-param name="style-name-tokenized"         select="translate(@style:name, '. %()/\', '')"/>
  177.             </xsl:call-template>
  178.  
  179.         </xsl:for-each>
  180.     </xsl:template>
  181.  
  182.  
  183.  
  184.     <xsl:template name='for-all-automatic-child-styles'>
  185.         <xsl:param name="styles-node"/>
  186.         <xsl:param name="parentStyleName"/>
  187.         <xsl:param name="parentStyleFamily"/>
  188.         <xsl:param name="style-name-tokenized"/>
  189.  
  190.         <xsl:for-each select="$office:automatic-styles/style:style[@style:family=$parentStyleFamily and @style:parent-style-name=$parentStyleName]">
  191.             <!--** give out the style properties of the current node **-->
  192.             <xsl:element name="{$style-name-tokenized}">
  193.                 <xsl:call-template name='write-current-and-inherited-style-properties'>
  194.                     <xsl:with-param name="styles-node"                  select="$office:automatic-styles"/>
  195.                     <xsl:with-param name="style-family"                 select="@style:family"/>
  196.                     <xsl:with-param name="style-name-tokenized"         select="translate(@style:name, '. %()/\', '')"/>
  197.                 </xsl:call-template>
  198.             </xsl:element>
  199.  
  200.             <!--** for all automatic-children of the current office:automatic-styles  **-->
  201.             <xsl:call-template name='for-all-automatic-child-styles'>
  202.                 <xsl:with-param name="styles-node"                  select="$office:automatic-styles"/>
  203.                 <xsl:with-param name="parentStyleName"              select="@style:name"/>
  204.                 <xsl:with-param name="parentStyleFamily"            select="@style:family"/>
  205.                 <xsl:with-param name="style-name-tokenized"         select="translate(@style:name, '. %()/\', '')"/>
  206.             </xsl:call-template>
  207.         </xsl:for-each>
  208.     </xsl:template>
  209.  
  210.  
  211.     <xsl:template name='write-current-and-inherited-style-properties'>
  212.         <xsl:param name="style-family"/>
  213.         <xsl:param name="styles-node"/>
  214.         <xsl:param name="style-name-tokenized"/>
  215.  
  216.         <xsl:element name="{$style-name-tokenized}">
  217.             <xsl:variable name="current-style-name" select="@style:name"/>
  218.             <xsl:variable name="parent-style-name" select="@style:parent-style-name"/>
  219.  
  220.             <xsl:variable name="new-property-list">
  221.                 <!--*** COLLECT STYLE ATTRIBUTES (only toplevel) ***-->
  222.                 <xsl:call-template name="write-style-properties">
  223.                     <xsl:with-param name="styleAttributePath"   select="$styles-node/style:style[@style:family=$style-family and @style:name=$current-style-name]/style:properties/@*"/>
  224.                 </xsl:call-template>
  225.             </xsl:variable>
  226.             <xsl:choose>
  227.                 <!--*** @End: GIVE OUT All COLLECTED STYLE ATTRIBUTES (only toplevel) ***-->
  228.                 <xsl:when test="string-length($parent-style-name)=0">
  229.                 <!--** if no styleParent is given, the properties are given out at once **-->
  230.                     <xsl:value-of select="normalize-space($new-property-list)"/>
  231.                 </xsl:when>
  232.                 <xsl:otherwise>
  233.                     <xsl:variable name="new-property-names">
  234.                         <xsl:for-each select="$styles-node/style:style[@style:family=$style-family and @style:name=$current-style-name]/style:properties/@*">
  235.                             <xsl:value-of select="name()"/>
  236.                         </xsl:for-each>
  237.                     </xsl:variable>
  238.                     <!--** further attributes of the parent style must be collected **-->
  239.                     <xsl:call-template name="add-parent-style-attributes">
  240.                         <xsl:with-param name="property-name-list"       select="$new-property-names"/>
  241.                         <xsl:with-param name="complete-property-list"   select="normalize-space($new-property-list)"/>
  242.                         <xsl:with-param name="current-style-name"       select="$current-style-name"/>
  243.                         <xsl:with-param name="parent-style-name"        select="$parent-style-name"/>
  244.                         <xsl:with-param name="style-family"             select="$style-family"/>
  245.                     </xsl:call-template>
  246.                 </xsl:otherwise>
  247.             </xsl:choose>
  248.         </xsl:element>
  249.     </xsl:template>
  250.  
  251.  
  252.  
  253.     <xsl:template name="add-parent-style-attributes">
  254.         <xsl:param name="property-name-list"/>
  255.         <xsl:param name="complete-property-list"/>
  256.         <xsl:param name="current-style-name"/>
  257.         <xsl:param name="parent-style-name"/>
  258.         <xsl:param name="style-family"/>
  259.  
  260.         <!--*** New two be added property names will be collected (only one variable per template) ***-->
  261.         <xsl:variable name="new-property-names">
  262.             <xsl:call-template name="get-new-style-names">
  263.                 <xsl:with-param name="property-name-list"       select="$property-name-list"/>
  264.                 <xsl:with-param name="parent-style-name"        select="$parent-style-name"/>
  265.                 <xsl:with-param name="current-style-name"       select="$current-style-name"/>
  266.             </xsl:call-template>
  267.         </xsl:variable>
  268.  
  269.         <xsl:choose>
  270.             <!--*** check if the new parent style exist in the office:automatic-styles section (defined by name and family) ***-->
  271.             <xsl:when test="$office:automatic-styles/style:style[@style:family='paragraph' and @style:name=$current-style-name]">
  272.                 <!--*** RECURSION: adding new parent style attributes to the current style ***-->
  273.                 <xsl:variable name="new-property-attributes">
  274.                     <xsl:call-template name="get-new-style-attributes">
  275.                         <xsl:with-param name="new-property-names"           select="$new-property-names"/>
  276.                         <xsl:with-param name="current-style-name"           select="$current-style-name"/>
  277.                         <xsl:with-param name="parent-style-name"            select="$parent-style-name"/>
  278.                     </xsl:call-template>
  279.                 </xsl:variable>
  280.                 <!--*** End CONDITION: the last style parent has already been executed ***-->
  281.                 <xsl:variable name="new-parent-style-name"  select="$office:automatic-styles/style:style[@style:family='paragraph' and @style:name=$parent-style-name]/@style:parent-style-name"/>
  282.                 <xsl:choose>
  283.                     <xsl:when test="string-length($new-parent-style-name)=0">
  284.                     <!--** no further parent is found, the given parameter property-node is the final style -->
  285.                         <xsl:value-of select="concat($complete-property-list,$new-property-attributes)"/>
  286.                     </xsl:when>
  287.                     <xsl:otherwise>
  288.                     <!--** further attributes of the parent style must be collected **-->
  289.                         <xsl:call-template name="add-parent-style-attributes">
  290.                             <xsl:with-param name="property-name-list"       select="concat($property-name-list, $new-property-names)"/>
  291.                             <xsl:with-param name="complete-property-list"   select="concat($complete-property-list,$new-property-attributes)"/>
  292.                             <xsl:with-param name="current-style-name"       select="$parent-style-name"/>
  293.                             <xsl:with-param name="parent-style-name"        select="$new-parent-style-name"/>
  294.                             <xsl:with-param name="style-family"             select="$style-family"/>
  295.                         </xsl:call-template>
  296.                     </xsl:otherwise>
  297.                 </xsl:choose>
  298.             </xsl:when>
  299.  
  300.             <!--** the specific style (defined by name and family) must be found in the office:styles section -->
  301.             <xsl:otherwise>
  302.                 <!--*** RECURSION: adding new parent style attributes to the current style ***-->
  303.                 <!--*** adding new parent style attributes to the current style ***-->
  304.                 <xsl:variable name="new-property-attributes">
  305.                     <xsl:call-template name="get-new-style-attributes">
  306.                         <xsl:with-param name="new-property-names"           select="$new-property-names"/>
  307.                         <xsl:with-param name="current-style-name"           select="$current-style-name"/>
  308.                         <xsl:with-param name="parent-style-name"            select="$parent-style-name"/>
  309.                     </xsl:call-template>
  310.                 </xsl:variable>
  311.                 <!--*** End CONDITION: the last style parent has already been executed ***-->
  312.                 <xsl:variable name="new-parent-style-name"  select="$office:styles/style:style[@style:family='paragraph' and @style:name=$parent-style-name]/@style:parent-style-name"/>
  313.                 <xsl:choose>
  314.                     <xsl:when test="string-length($new-parent-style-name)=0">
  315.                     <!--** no further parent is found, the given parameter property-node is the final style -->
  316.                         <xsl:value-of select="concat($complete-property-list,$new-property-attributes)"/>
  317.                     </xsl:when>
  318.                     <xsl:otherwise>
  319.                     <!--** further attributes of the parent style must be collected **  -->
  320.                         <xsl:call-template name="add-parent-style-attributes">
  321.                             <xsl:with-param name="property-name-list"       select="concat($property-name-list, $new-property-names)"/>
  322.                             <xsl:with-param name="complete-property-list"   select="concat($complete-property-list,$new-property-attributes)"/>
  323.                             <xsl:with-param name="current-style-name"       select="$parent-style-name"/>
  324.                             <xsl:with-param name="parent-style-name"        select="$new-parent-style-name"/>
  325.                             <xsl:with-param name="style-family"             select="$style-family"/>
  326.                         </xsl:call-template>
  327.                     </xsl:otherwise>
  328.                 </xsl:choose>
  329.             </xsl:otherwise>
  330.         </xsl:choose>
  331.     </xsl:template>
  332.  
  333.  
  334.  
  335.     <xsl:template name="get-new-style-names">
  336.         <xsl:param name="property-name-list"/>
  337.         <xsl:param name="parent-style-name"/>
  338.         <xsl:param name="current-style-name"/>
  339.         <!--** where to find the specific style (defined by name and family) wheter in office:automatic-styles or office:styles section -->
  340.         <xsl:choose>
  341.             <!--** if the specific style (defined by name and family) can be found in the office:automatic-styles section -->
  342.             <xsl:when test="$office:automatic-styles/style:style[@style:family='paragraph' and @style:name=$parent-style-name]">
  343.                 <xsl:variable name="parent-property-node" select="$office:automatic-styles/style:style[@style:family='paragraph' and @style:name=$parent-style-name]/style:properties"/>
  344.  
  345.                 <xsl:variable name="new-property-name-list">
  346.                     <xsl:for-each select="$parent-property-node/@*[not(contains($property-name-list, name()))]">
  347.                         <xsl:value-of select="name()"/>
  348.                     </xsl:for-each>
  349.                 </xsl:variable>
  350.                 <xsl:value-of select="$new-property-name-list"/>
  351.             </xsl:when>
  352.             <!--** the specific style (defined by name and family) should be found in the office:styles section -->
  353.             <xsl:otherwise>
  354.                 <xsl:variable name="parent-property-node" select="$office:styles/style:style[@style:family='paragraph' and @style:name=$parent-style-name]/style:properties"/>
  355.                 <xsl:variable name="new-property-name-list">
  356.                     <xsl:for-each select="$parent-property-node/@*[not(contains($property-name-list, name()))]">
  357.                         <xsl:value-of select="name()"/>
  358.                     </xsl:for-each>
  359.                 </xsl:variable>
  360.                 <xsl:value-of select="$new-property-name-list"/>
  361.             </xsl:otherwise>
  362.         </xsl:choose>
  363.     </xsl:template>
  364.  
  365.  
  366.  
  367.     <xsl:template name="get-new-style-attributes">
  368.         <xsl:param name="new-property-names"/>
  369.         <xsl:param name="current-style-name"/>
  370.         <xsl:param name="parent-style-name"/>
  371.  
  372.         <!--** where to find the specific style (defined by name and family) whether in office:automatic-styles or office:styles section -->
  373.         <xsl:choose>
  374.             <!--** if the specific style (defined by name and family) can be found in the office:automatic-styles section -->
  375.             <xsl:when test="$office:automatic-styles/style:style[@style:family='paragraph' and @style:name=$parent-style-name]">
  376.                 <xsl:variable name="parent-property-node" select="$office:automatic-styles/style:style[@style:family='paragraph' and @style:name=$parent-style-name]/style:properties"/>
  377.                 <xsl:variable name="new-property-name-list">
  378.                     <xsl:call-template name="write-style-properties">
  379.                         <xsl:with-param name="styleAttributePath"   select="$parent-property-node/@*[contains($new-property-names, name())]"/>
  380.                     </xsl:call-template>
  381.                 </xsl:variable>
  382.                 <xsl:value-of select="normalize-space($new-property-name-list)"/>
  383.             </xsl:when>
  384.             <!--** otherwise the specific style (defined by name and family) should be found in the office:styles section -->
  385.             <xsl:otherwise>
  386.                 <xsl:variable name="parent-property-node" select="$office:styles/style:style[@style:family='paragraph' and @style:name=$parent-style-name]/style:properties"/>
  387.                 <xsl:variable name="new-property-name-list">
  388.                     <xsl:call-template name="write-style-properties">
  389.                         <xsl:with-param name="styleAttributePath"   select="$parent-property-node/@*[contains($new-property-names, name())]"/>
  390.                     </xsl:call-template>
  391.                 </xsl:variable>
  392.                 <xsl:value-of select="normalize-space($new-property-name-list)"/>
  393.             </xsl:otherwise>
  394.         </xsl:choose>
  395.     </xsl:template>
  396.  
  397.  
  398. </xsl:stylesheet>
  399.