1cdf0e10cSrcweir<?xml version="1.0" encoding="utf-8" standalone="yes" ?> 2*1e519d8dSAndrew Rist<!--*********************************************************** 3*1e519d8dSAndrew Rist * 4*1e519d8dSAndrew Rist * Licensed to the Apache Software Foundation (ASF) under one 5*1e519d8dSAndrew Rist * or more contributor license agreements. See the NOTICE file 6*1e519d8dSAndrew Rist * distributed with this work for additional information 7*1e519d8dSAndrew Rist * regarding copyright ownership. The ASF licenses this file 8*1e519d8dSAndrew Rist * to you under the Apache License, Version 2.0 (the 9*1e519d8dSAndrew Rist * "License"); you may not use this file except in compliance 10*1e519d8dSAndrew Rist * with the License. You may obtain a copy of the License at 11*1e519d8dSAndrew Rist * 12*1e519d8dSAndrew Rist * http://www.apache.org/licenses/LICENSE-2.0 13*1e519d8dSAndrew Rist * 14*1e519d8dSAndrew Rist * Unless required by applicable law or agreed to in writing, 15*1e519d8dSAndrew Rist * software distributed under the License is distributed on an 16*1e519d8dSAndrew Rist * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 17*1e519d8dSAndrew Rist * KIND, either express or implied. See the License for the 18*1e519d8dSAndrew Rist * specific language governing permissions and limitations 19*1e519d8dSAndrew Rist * under the License. 20*1e519d8dSAndrew Rist * 21*1e519d8dSAndrew Rist ***********************************************************--> 22*1e519d8dSAndrew Rist 23cdf0e10cSrcweir 24cdf0e10cSrcweir 25cdf0e10cSrcweir<xsl:transform xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0" 26cdf0e10cSrcweir xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 27cdf0e10cSrcweir xmlns:xs="http://www.w3.org/2001/XMLSchema" 28cdf0e10cSrcweir xmlns:oor="http://openoffice.org/2001/registry" 29cdf0e10cSrcweir xmlns:install="http://openoffice.org/2004/installation" 30cdf0e10cSrcweir exclude-result-prefixes="install"> 31cdf0e10cSrcweir 32cdf0e10cSrcweir<!-- Get the correct format --> 33cdf0e10cSrcweir<xsl:output method="xml" indent="yes" encoding="UTF-8"/> 34cdf0e10cSrcweir 35cdf0e10cSrcweir<!--************************** PARAMETER ******************************** --> 36cdf0e10cSrcweir<xsl:param name="locale"/> 37cdf0e10cSrcweir<xsl:param name="module"/> 38cdf0e10cSrcweir<xsl:param name="xcs"/> 39cdf0e10cSrcweir<xsl:param name="schemaRoot">.</xsl:param> 40cdf0e10cSrcweir<xsl:param name="fallback-locale">en-US</xsl:param> 41cdf0e10cSrcweir 42cdf0e10cSrcweir<xsl:variable name="schemaRootURL"> 43cdf0e10cSrcweir <xsl:value-of select="$schemaRoot"/> 44cdf0e10cSrcweir</xsl:variable> 45cdf0e10cSrcweir<xsl:variable name="schemaURL"> 46cdf0e10cSrcweir <xsl:value-of select="$xcs"/> 47cdf0e10cSrcweir</xsl:variable> 48cdf0e10cSrcweir 49cdf0e10cSrcweir<!--************************** TEMPLATES ******************************** --> 50cdf0e10cSrcweir<!-- ensure that at least root is available --> 51cdf0e10cSrcweir <xsl:template match="/oor:component-data"> 52cdf0e10cSrcweir <xsl:copy> 53cdf0e10cSrcweir <xsl:choose> 54cdf0e10cSrcweir <xsl:when test="string-length($locale)"> 55cdf0e10cSrcweir <xsl:apply-templates select = "@*" mode="locale"/> 56cdf0e10cSrcweir <xsl:apply-templates select = "node|prop" mode="locale"/> 57cdf0e10cSrcweir </xsl:when> 58cdf0e10cSrcweir <xsl:otherwise> 59cdf0e10cSrcweir <xsl:apply-templates select = "@*"/> 60cdf0e10cSrcweir <xsl:for-each select="node|prop"> 61cdf0e10cSrcweir <xsl:variable name="component-schema" select="document($schemaURL)/oor:component-schema"/> 62cdf0e10cSrcweir <xsl:apply-templates select="."> 63cdf0e10cSrcweir <xsl:with-param name="component-schema" select="$component-schema"/> 64cdf0e10cSrcweir <xsl:with-param name="context" select="$component-schema/component/*[@oor:name = current()/@oor:name]"/> 65cdf0e10cSrcweir <xsl:with-param name="find-module" select="$module"/> 66cdf0e10cSrcweir </xsl:apply-templates> 67cdf0e10cSrcweir </xsl:for-each> 68cdf0e10cSrcweir </xsl:otherwise> 69cdf0e10cSrcweir </xsl:choose> 70cdf0e10cSrcweir </xsl:copy> 71cdf0e10cSrcweir </xsl:template> 72cdf0e10cSrcweir 73cdf0e10cSrcweir<!-- locale dependent data --> 74cdf0e10cSrcweir <xsl:template match="node|prop" mode = "locale"> 75cdf0e10cSrcweir <xsl:choose> 76cdf0e10cSrcweir <xsl:when test="$locale=$fallback-locale"> 77cdf0e10cSrcweir <xsl:if test="descendant::value[@xml:lang=$locale]/../value[not (@xml:lang)]"> 78cdf0e10cSrcweir <xsl:copy> 79cdf0e10cSrcweir <xsl:apply-templates select = "@*" mode="locale"/> 80cdf0e10cSrcweir <xsl:apply-templates select = "node|prop|value" mode = "locale"/> 81cdf0e10cSrcweir </xsl:copy> 82cdf0e10cSrcweir </xsl:if> 83cdf0e10cSrcweir </xsl:when> 84cdf0e10cSrcweir <xsl:otherwise> 85cdf0e10cSrcweir <xsl:if test="descendant::value[@xml:lang = $locale]"> 86cdf0e10cSrcweir <xsl:copy> 87cdf0e10cSrcweir <xsl:apply-templates select = "@*" mode="locale"/> 88cdf0e10cSrcweir <xsl:apply-templates select = "node|prop|value" mode = "locale"/> 89cdf0e10cSrcweir </xsl:copy> 90cdf0e10cSrcweir </xsl:if> 91cdf0e10cSrcweir </xsl:otherwise> 92cdf0e10cSrcweir </xsl:choose> 93cdf0e10cSrcweir </xsl:template> 94cdf0e10cSrcweir 95cdf0e10cSrcweir <xsl:template match="value" mode="locale"> 96cdf0e10cSrcweir <xsl:if test="@xml:lang=$locale and not(@install:module)"> 97cdf0e10cSrcweir <xsl:copy> 98cdf0e10cSrcweir <xsl:apply-templates select = "@*" mode="locale"/> 99cdf0e10cSrcweir <xsl:copy-of select="node()"/> 100cdf0e10cSrcweir </xsl:copy> 101cdf0e10cSrcweir </xsl:if> 102cdf0e10cSrcweir </xsl:template> 103cdf0e10cSrcweir 104cdf0e10cSrcweir <xsl:template match = "@*" mode="locale"> 105cdf0e10cSrcweir <xsl:copy/> 106cdf0e10cSrcweir </xsl:template> 107cdf0e10cSrcweir 108cdf0e10cSrcweir <!-- suppress all merge instructions --> 109cdf0e10cSrcweir <xsl:template match = "@oor:op" mode="locale"/> 110cdf0e10cSrcweir 111cdf0e10cSrcweir <!-- suppress all module markers --> 112cdf0e10cSrcweir <xsl:template match = "@install:module" mode="locale"/> 113cdf0e10cSrcweir 114cdf0e10cSrcweir<!-- locale independent data --> 115cdf0e10cSrcweir 116cdf0e10cSrcweir <!-- handle template references --> 117cdf0e10cSrcweir <xsl:template name="copy-resolve-template"> 118cdf0e10cSrcweir <xsl:param name = "node-type"/> 119cdf0e10cSrcweir <xsl:param name = "schema-type"/> 120cdf0e10cSrcweir <xsl:param name = "component-schema"/> 121cdf0e10cSrcweir 122cdf0e10cSrcweir <xsl:choose> 123cdf0e10cSrcweir <xsl:when test="$schema-type='node-ref'"> 124cdf0e10cSrcweir <xsl:apply-templates select="."> 125cdf0e10cSrcweir <xsl:with-param name="context" select="$component-schema/templates/*[@oor:name = $node-type]"/> 126cdf0e10cSrcweir <xsl:with-param name="component-schema" select="$component-schema"/> 127cdf0e10cSrcweir </xsl:apply-templates> 128cdf0e10cSrcweir </xsl:when> 129cdf0e10cSrcweir <xsl:when test="$schema-type='set'"> 130cdf0e10cSrcweir <xsl:copy> 131cdf0e10cSrcweir <xsl:apply-templates select = "@*" /> 132cdf0e10cSrcweir <xsl:for-each select="node|prop"> 133cdf0e10cSrcweir <xsl:apply-templates select="."> 134cdf0e10cSrcweir <xsl:with-param name="context" select="$component-schema/templates/*[@oor:name = $node-type]"/> 135cdf0e10cSrcweir <xsl:with-param name="component-schema" select="$component-schema"/> 136cdf0e10cSrcweir </xsl:apply-templates> 137cdf0e10cSrcweir </xsl:for-each> 138cdf0e10cSrcweir </xsl:copy> 139cdf0e10cSrcweir </xsl:when> 140cdf0e10cSrcweir <xsl:otherwise> 141cdf0e10cSrcweir <xsl:message terminate="yes">ERROR: The schema element for a <xsl:value-of select="$schema-type"/> 142cdf0e10cSrcweir should not have a node-type. 143cdf0e10cSrcweir </xsl:message> 144cdf0e10cSrcweir </xsl:otherwise> 145cdf0e10cSrcweir </xsl:choose> 146cdf0e10cSrcweir </xsl:template> 147cdf0e10cSrcweir 148cdf0e10cSrcweir <xsl:template name="copy-node"> 149cdf0e10cSrcweir <xsl:param name = "context"/> 150cdf0e10cSrcweir <xsl:param name = "component-schema"/> 151cdf0e10cSrcweir 152cdf0e10cSrcweir <xsl:choose> 153cdf0e10cSrcweir <!-- look for matching templates in other components --> 154cdf0e10cSrcweir <xsl:when test="$context/@oor:node-type and $context/@oor:component"> 155cdf0e10cSrcweir <xsl:variable name="fileURL"> 156cdf0e10cSrcweir <xsl:call-template name="composeFileURL"> 157cdf0e10cSrcweir <xsl:with-param name="component-schema" select="$component-schema"/> 158cdf0e10cSrcweir <xsl:with-param name="componentName"><xsl:value-of select="$context/@oor:component"/></xsl:with-param> 159cdf0e10cSrcweir </xsl:call-template> 160cdf0e10cSrcweir </xsl:variable> 161cdf0e10cSrcweir <xsl:call-template name="copy-resolve-template"> 162cdf0e10cSrcweir <xsl:with-param name="node-type" select="$context/@oor:node-type"/> 163cdf0e10cSrcweir <xsl:with-param name="schema-type" select="local-name($context)"/> 164cdf0e10cSrcweir <xsl:with-param name="component-schema" select="document($fileURL)/oor:component-schema"/> 165cdf0e10cSrcweir </xsl:call-template> 166cdf0e10cSrcweir </xsl:when> 167cdf0e10cSrcweir <!-- look for matching templates within the same component --> 168cdf0e10cSrcweir <xsl:when test="$context/@oor:node-type"> 169cdf0e10cSrcweir <xsl:call-template name="copy-resolve-template"> 170cdf0e10cSrcweir <xsl:with-param name="node-type" select="$context/@oor:node-type"/> 171cdf0e10cSrcweir <xsl:with-param name="schema-type" select="local-name($context)"/> 172cdf0e10cSrcweir <xsl:with-param name="component-schema" select="$component-schema"/> 173cdf0e10cSrcweir </xsl:call-template> 174cdf0e10cSrcweir </xsl:when> 175cdf0e10cSrcweir <xsl:otherwise> 176cdf0e10cSrcweir <xsl:copy> 177cdf0e10cSrcweir <xsl:apply-templates select = "@*" /> 178cdf0e10cSrcweir <xsl:for-each select="node|prop"> 179cdf0e10cSrcweir <xsl:apply-templates select="."> 180cdf0e10cSrcweir <xsl:with-param name="component-schema" select="$component-schema"/> 181cdf0e10cSrcweir <xsl:with-param name="context" select="$context/*[@oor:name = current()/@oor:name]"/> 182cdf0e10cSrcweir </xsl:apply-templates> 183cdf0e10cSrcweir </xsl:for-each> 184cdf0e10cSrcweir </xsl:copy> 185cdf0e10cSrcweir </xsl:otherwise> 186cdf0e10cSrcweir </xsl:choose> 187cdf0e10cSrcweir </xsl:template> 188cdf0e10cSrcweir 189cdf0e10cSrcweir <xsl:template match="node"> 190cdf0e10cSrcweir <xsl:param name = "context"/> 191cdf0e10cSrcweir <xsl:param name = "component-schema"/> 192cdf0e10cSrcweir 193cdf0e10cSrcweir <xsl:variable name="applicable-values" select="descendant::value[not (@xml:lang) or (@xml:lang=$fallback-locale) or (@install:module=$module)]"/> 194cdf0e10cSrcweir <xsl:variable name="substantive-nodes" select="descendant-or-self::*[(@oor:finalized='true') or (@oor:mandatory='true') or (@oor:op!='modify')]"/> 195cdf0e10cSrcweir 196cdf0e10cSrcweir <xsl:choose> 197cdf0e10cSrcweir <!-- go ahead, if we are in the active module --> 198cdf0e10cSrcweir <xsl:when test="ancestor-or-self::*/@install:module=$module"> 199cdf0e10cSrcweir <xsl:if test="$applicable-values | $substantive-nodes"> 200cdf0e10cSrcweir <xsl:call-template name="copy-node"> 201cdf0e10cSrcweir <xsl:with-param name="component-schema" select="$component-schema"/> 202cdf0e10cSrcweir <xsl:with-param name="context" select="$context"/> 203cdf0e10cSrcweir </xsl:call-template> 204cdf0e10cSrcweir </xsl:if> 205cdf0e10cSrcweir </xsl:when> 206cdf0e10cSrcweir <!-- strip data from wrong module --> 207cdf0e10cSrcweir <xsl:when test="ancestor-or-self::*/@install:module"/> 208cdf0e10cSrcweir <!-- looking for module --> 209cdf0e10cSrcweir <xsl:when test="$module"> 210cdf0e10cSrcweir <xsl:if test="($applicable-values | $substantive-nodes)/ancestor-or-self::*/@install:module=$module"> 211cdf0e10cSrcweir <xsl:call-template name="copy-node"> 212cdf0e10cSrcweir <xsl:with-param name="component-schema" select="$component-schema"/> 213cdf0e10cSrcweir <xsl:with-param name="context" select="$context"/> 214cdf0e10cSrcweir </xsl:call-template> 215cdf0e10cSrcweir </xsl:if> 216cdf0e10cSrcweir </xsl:when> 217cdf0e10cSrcweir <!-- copying non-module data --> 218cdf0e10cSrcweir <xsl:otherwise> 219cdf0e10cSrcweir <xsl:if test="($applicable-values | $substantive-nodes)[not(ancestor-or-self::*/@install:module)]"> 220cdf0e10cSrcweir <xsl:call-template name="copy-node"> 221cdf0e10cSrcweir <xsl:with-param name="component-schema" select="$component-schema"/> 222cdf0e10cSrcweir <xsl:with-param name="context" select="$context"/> 223cdf0e10cSrcweir </xsl:call-template> 224cdf0e10cSrcweir </xsl:if> 225cdf0e10cSrcweir </xsl:otherwise> 226cdf0e10cSrcweir </xsl:choose> 227cdf0e10cSrcweir </xsl:template> 228cdf0e10cSrcweir 229cdf0e10cSrcweir <xsl:template match="prop"> 230cdf0e10cSrcweir <xsl:param name = "context"/> 231cdf0e10cSrcweir <xsl:choose> 232cdf0e10cSrcweir <xsl:when test="$module and not((ancestor-or-self::* | child::value)/@install:module=$module)"/> 233cdf0e10cSrcweir <xsl:when test="not($module) and ancestor-or-self::*/@install:module"/> 234cdf0e10cSrcweir <xsl:when test="not ($context) or @oor:finalized='true' or @oor:op!='modify'"> 235cdf0e10cSrcweir <xsl:copy> 236cdf0e10cSrcweir <xsl:apply-templates select = "@*"/> 237cdf0e10cSrcweir <xsl:apply-templates select = "value"/> 238cdf0e10cSrcweir </xsl:copy> 239cdf0e10cSrcweir </xsl:when> 240cdf0e10cSrcweir <xsl:when test="value[not (@xml:lang) or @install:module]"> 241cdf0e10cSrcweir <xsl:if test="value[not(@install:module) or @install:module=$module]"> 242cdf0e10cSrcweir <!-- copy locale independent values only, if the values differ --> 243cdf0e10cSrcweir <xsl:variable name="isRedundant"> 244cdf0e10cSrcweir <xsl:call-template name="isRedundant"> 245cdf0e10cSrcweir <xsl:with-param name="schemaval" select="$context/value"/> 246cdf0e10cSrcweir <xsl:with-param name="dataval" select="value[(not(@xml:lang) or @install:module) and (not(@install:module) or @install:module=$module)]"/> 247cdf0e10cSrcweir </xsl:call-template> 248cdf0e10cSrcweir </xsl:variable> 249cdf0e10cSrcweir <xsl:if test="$isRedundant ='false'"> 250cdf0e10cSrcweir <xsl:copy> 251cdf0e10cSrcweir <xsl:apply-templates select = "@*"/> 252cdf0e10cSrcweir <xsl:apply-templates select = "value"/> 253cdf0e10cSrcweir </xsl:copy> 254cdf0e10cSrcweir </xsl:if> 255cdf0e10cSrcweir </xsl:if> 256cdf0e10cSrcweir </xsl:when> 257cdf0e10cSrcweir <xsl:otherwise> 258cdf0e10cSrcweir <xsl:copy> 259cdf0e10cSrcweir <xsl:apply-templates select = "@*"/> 260cdf0e10cSrcweir <xsl:apply-templates select = "value" mode="fallback-locale"/> 261cdf0e10cSrcweir </xsl:copy> 262cdf0e10cSrcweir </xsl:otherwise> 263cdf0e10cSrcweir </xsl:choose> 264cdf0e10cSrcweir </xsl:template> 265cdf0e10cSrcweir 266cdf0e10cSrcweir <xsl:template match="value"> 267cdf0e10cSrcweir <xsl:choose> 268cdf0e10cSrcweir <xsl:when test="@xml:lang and not(@install:module)"/> 269cdf0e10cSrcweir <xsl:when test="$module and not(ancestor-or-self::*/@install:module=$module)"/> 270cdf0e10cSrcweir <xsl:when test="not($module) and ancestor-or-self::*/@install:module"/> 271cdf0e10cSrcweir <xsl:otherwise> 272cdf0e10cSrcweir <xsl:copy> 273cdf0e10cSrcweir <xsl:apply-templates select = "@*"/> 274cdf0e10cSrcweir <xsl:copy-of select="node()"/> 275cdf0e10cSrcweir </xsl:copy> 276cdf0e10cSrcweir </xsl:otherwise> 277cdf0e10cSrcweir </xsl:choose> 278cdf0e10cSrcweir </xsl:template> 279cdf0e10cSrcweir 280cdf0e10cSrcweir <xsl:template match="value" mode="fallback-locale"> 281cdf0e10cSrcweir <xsl:if test="@xml:lang=$fallback-locale and not(@install:module)"> 282cdf0e10cSrcweir <xsl:copy> 283cdf0e10cSrcweir <xsl:apply-templates select = "@*"/> 284cdf0e10cSrcweir <xsl:copy-of select="node()"/> 285cdf0e10cSrcweir </xsl:copy> 286cdf0e10cSrcweir </xsl:if> 287cdf0e10cSrcweir </xsl:template> 288cdf0e10cSrcweir 289cdf0e10cSrcweir <xsl:template match = "@*"> 290cdf0e10cSrcweir <xsl:copy/> 291cdf0e10cSrcweir </xsl:template> 292cdf0e10cSrcweir 293cdf0e10cSrcweir <!-- suppress all merge instructions, that are out-of-module --> 294cdf0e10cSrcweir <xsl:template match = "@oor:op"> 295cdf0e10cSrcweir <xsl:if test="not($module) or ancestor::*/@install:module"> 296cdf0e10cSrcweir <xsl:copy/> 297cdf0e10cSrcweir </xsl:if> 298cdf0e10cSrcweir </xsl:template> 299cdf0e10cSrcweir 300cdf0e10cSrcweir <!-- suppress all module markers --> 301cdf0e10cSrcweir <xsl:template match = "@install:module"/> 302cdf0e10cSrcweir 303cdf0e10cSrcweir<!-- compares two values --> 304cdf0e10cSrcweir <xsl:template name="isRedundant"> 305cdf0e10cSrcweir <xsl:param name = "schemaval"/> 306cdf0e10cSrcweir <xsl:param name = "dataval"/> 307cdf0e10cSrcweir <xsl:choose> 308cdf0e10cSrcweir <xsl:when test="not ($dataval)"> 309cdf0e10cSrcweir <xsl:value-of select="true()"/> 310cdf0e10cSrcweir </xsl:when> 311cdf0e10cSrcweir <xsl:when test="$dataval/@oor:external"> 312cdf0e10cSrcweir <xsl:value-of select="false()"/> 313cdf0e10cSrcweir </xsl:when> 314cdf0e10cSrcweir <xsl:when test="not ($schemaval)"> 315cdf0e10cSrcweir <xsl:choose> 316cdf0e10cSrcweir <xsl:when test="$dataval/@xsi:nil='true'"> 317cdf0e10cSrcweir <xsl:value-of select="true()"/> 318cdf0e10cSrcweir </xsl:when> 319cdf0e10cSrcweir <xsl:otherwise> 320cdf0e10cSrcweir <xsl:value-of select="false()"/> 321cdf0e10cSrcweir </xsl:otherwise> 322cdf0e10cSrcweir </xsl:choose> 323cdf0e10cSrcweir </xsl:when> 324cdf0e10cSrcweir <xsl:when test="$schemaval != $dataval"> 325cdf0e10cSrcweir <xsl:value-of select="false()"/> 326cdf0e10cSrcweir </xsl:when> 327cdf0e10cSrcweir <xsl:otherwise> 328cdf0e10cSrcweir <xsl:value-of select="true()"/> 329cdf0e10cSrcweir </xsl:otherwise> 330cdf0e10cSrcweir </xsl:choose> 331cdf0e10cSrcweir </xsl:template> 332cdf0e10cSrcweir 333cdf0e10cSrcweir <xsl:template name="composeFileURL"> 334cdf0e10cSrcweir <xsl:param name="componentName"/> 335cdf0e10cSrcweir <xsl:variable name="fileURL"> 336cdf0e10cSrcweir <xsl:value-of select="$schemaRootURL"/>/<xsl:value-of select="translate($componentName,'.','/')"/><xsl:text>.xcs</xsl:text> 337cdf0e10cSrcweir </xsl:variable> 338cdf0e10cSrcweir <xsl:value-of select="$fileURL"/> 339cdf0e10cSrcweir </xsl:template> 340cdf0e10cSrcweir 341cdf0e10cSrcweir</xsl:transform> 342