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<!-- ************************************************************************************** --> 26cdf0e10cSrcweir<!-- * Transformation from New Format XCS & XCU to schema description *** --> 27cdf0e10cSrcweir<!-- ************************************************************************************** --> 28cdf0e10cSrcweir<xsl:transform version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" 29cdf0e10cSrcweir xmlns:xsi="http://www.w3.org/1999/XMLSchema-instance" 30cdf0e10cSrcweir xmlns:xs="http://www.w3.org/2001/XMLSchema" 31cdf0e10cSrcweir xmlns:oor="http://openoffice.org/2001/registry" 32cdf0e10cSrcweir xmlns:install="http://openoffice.org/2004/installation"> 33cdf0e10cSrcweir 34cdf0e10cSrcweir<!-- Get the correct format --> 35cdf0e10cSrcweir<xsl:output method="xml" indent="yes" /> 36cdf0e10cSrcweir 37cdf0e10cSrcweir<xsl:param name="xcs"/> 38cdf0e10cSrcweir<xsl:param name="schemaRoot">.</xsl:param> 39cdf0e10cSrcweir 40cdf0e10cSrcweir<xsl:variable name="schemaRootURL"> 41cdf0e10cSrcweir <xsl:value-of select="$schemaRoot"/> 42cdf0e10cSrcweir</xsl:variable> 43cdf0e10cSrcweir<xsl:variable name="schemaURL"> 44cdf0e10cSrcweir <xsl:value-of select="$xcs"/> 45cdf0e10cSrcweir</xsl:variable> 46cdf0e10cSrcweir 47cdf0e10cSrcweir<!-- ************************************** --> 48cdf0e10cSrcweir<!-- * oor:component-data *** --> 49cdf0e10cSrcweir<!-- ************************************** --> 50cdf0e10cSrcweir <xsl:template match="/oor:component-data"> 51cdf0e10cSrcweir <xsl:variable name="component-schema" select="document($schemaURL)/oor:component-schema"/> 52cdf0e10cSrcweir <xsl:for-each select="node|prop"> 53cdf0e10cSrcweir <xsl:apply-templates select="."> 54cdf0e10cSrcweir <xsl:with-param name="context" select="$component-schema/component/*[@oor:name = current()/@oor:name]"/> 55cdf0e10cSrcweir <xsl:with-param name="component-schema" select="$component-schema"/> 56cdf0e10cSrcweir </xsl:apply-templates> 57cdf0e10cSrcweir </xsl:for-each> 58cdf0e10cSrcweir </xsl:template> 59cdf0e10cSrcweir 60cdf0e10cSrcweir<!-- ****************************************** --> 61cdf0e10cSrcweir<!-- * handle template references *** --> 62cdf0e10cSrcweir<!-- ****************************************** --> 63cdf0e10cSrcweir <xsl:template name="resolve-template"> 64cdf0e10cSrcweir <xsl:param name = "node-type"/> 65cdf0e10cSrcweir <xsl:param name = "schema-type"/> 66cdf0e10cSrcweir <xsl:param name = "component-schema"/> 67cdf0e10cSrcweir <xsl:variable name = "path"> 68cdf0e10cSrcweir <xsl:call-template name="collectPath"/> 69cdf0e10cSrcweir </xsl:variable> 70cdf0e10cSrcweir 71cdf0e10cSrcweir <xsl:if test="not ($component-schema)"> 72cdf0e10cSrcweir <xsl:message terminate="yes">ERROR: Template '<xsl:value-of select="$node-type"/>', 73cdf0e10cSrcweir referenced from node '<xsl:value-of select="$path"/>' 74cdf0e10cSrcweir does not exist in schema! 75cdf0e10cSrcweir </xsl:message> 76cdf0e10cSrcweir </xsl:if> 77cdf0e10cSrcweir 78cdf0e10cSrcweir <xsl:choose> 79cdf0e10cSrcweir <xsl:when test="$schema-type='node-ref'"> 80cdf0e10cSrcweir <xsl:apply-templates select="."> 81cdf0e10cSrcweir <xsl:with-param name="context" select="$component-schema/templates/*[@oor:name = $node-type]"/> 82cdf0e10cSrcweir <xsl:with-param name="component-schema" select="$component-schema"/> 83cdf0e10cSrcweir </xsl:apply-templates> 84cdf0e10cSrcweir </xsl:when> 85cdf0e10cSrcweir <xsl:when test="$schema-type='set'"> 86cdf0e10cSrcweir <xsl:for-each select="node|prop"> 87cdf0e10cSrcweir <xsl:apply-templates select="."> 88cdf0e10cSrcweir <xsl:with-param name="context" select="$component-schema/templates/*[@oor:name = $node-type]"/> 89cdf0e10cSrcweir <xsl:with-param name="component-schema" select="$component-schema"/> 90cdf0e10cSrcweir </xsl:apply-templates> 91cdf0e10cSrcweir </xsl:for-each> 92cdf0e10cSrcweir </xsl:when> 93cdf0e10cSrcweir <xsl:otherwise> 94cdf0e10cSrcweir <xsl:message terminate="yes">ERROR: The schema element for node <xsl:value-of select="$path"/> 95cdf0e10cSrcweir is a <xsl:value-of select="$schema-type"/> and should not have a node-type. 96cdf0e10cSrcweir </xsl:message> 97cdf0e10cSrcweir </xsl:otherwise> 98cdf0e10cSrcweir </xsl:choose> 99cdf0e10cSrcweir </xsl:template> 100cdf0e10cSrcweir 101cdf0e10cSrcweir<!-- ****************************************** --> 102cdf0e10cSrcweir<!-- * node *** --> 103cdf0e10cSrcweir<!-- ****************************************** --> 104cdf0e10cSrcweir <xsl:template match="node"> 105cdf0e10cSrcweir <xsl:param name = "context"/> 106cdf0e10cSrcweir <xsl:param name = "component-schema"/> 107cdf0e10cSrcweir <xsl:variable name = "path"> 108cdf0e10cSrcweir <xsl:call-template name="collectPath"/> 109cdf0e10cSrcweir </xsl:variable> 110cdf0e10cSrcweir 111cdf0e10cSrcweir <xsl:if test="not ($context)"> 112cdf0e10cSrcweir <xsl:message terminate="yes">ERROR: Node '<xsl:value-of select="$path"/>' does not exist in schema!</xsl:message> 113cdf0e10cSrcweir </xsl:if> 114cdf0e10cSrcweir 115cdf0e10cSrcweir <xsl:call-template name="checkModule"/> 116cdf0e10cSrcweir <xsl:call-template name="checkDuplicates"/> 117cdf0e10cSrcweir 118cdf0e10cSrcweir <xsl:choose> 119cdf0e10cSrcweir <!-- look for matching templates in other components --> 120cdf0e10cSrcweir <xsl:when test="$context/@oor:node-type and $context/@oor:component"> 121cdf0e10cSrcweir <xsl:variable name="fileURL"> 122cdf0e10cSrcweir <xsl:call-template name="composeFileURL"> 123cdf0e10cSrcweir <xsl:with-param name="componentName"><xsl:value-of select="$context/@oor:component"/></xsl:with-param> 124cdf0e10cSrcweir </xsl:call-template> 125cdf0e10cSrcweir </xsl:variable> 126cdf0e10cSrcweir 127cdf0e10cSrcweir <xsl:call-template name="resolve-template"> 128cdf0e10cSrcweir <xsl:with-param name="node-type" select="$context/@oor:node-type"/> 129cdf0e10cSrcweir <xsl:with-param name="schema-type" select="local-name($context)"/> 130cdf0e10cSrcweir <xsl:with-param name="component-schema" select="document($fileURL)/oor:component-schema"/> 131cdf0e10cSrcweir </xsl:call-template> 132cdf0e10cSrcweir </xsl:when> 133cdf0e10cSrcweir <!-- look for matching templates within the same component --> 134cdf0e10cSrcweir <xsl:when test="$context/@oor:node-type"> 135cdf0e10cSrcweir <xsl:call-template name="resolve-template"> 136cdf0e10cSrcweir <xsl:with-param name="node-type" select="$context/@oor:node-type"/> 137cdf0e10cSrcweir <xsl:with-param name="schema-type" select="local-name($context)"/> 138cdf0e10cSrcweir <xsl:with-param name="component-schema" select="$component-schema"/> 139cdf0e10cSrcweir </xsl:call-template> 140cdf0e10cSrcweir </xsl:when> 141cdf0e10cSrcweir <!-- is the node extensible ? --> 142cdf0e10cSrcweir <xsl:when test="$context/@oor:extensible='true'"> 143cdf0e10cSrcweir <xsl:for-each select="node|prop"> 144cdf0e10cSrcweir <xsl:apply-templates select="." mode="extensible"> 145cdf0e10cSrcweir <xsl:with-param name="context" select="$context/*[@oor:name = current()/@oor:name]"/> 146cdf0e10cSrcweir <xsl:with-param name="component-schema" select="$component-schema"/> 147cdf0e10cSrcweir </xsl:apply-templates> 148cdf0e10cSrcweir </xsl:for-each> 149cdf0e10cSrcweir </xsl:when> 150cdf0e10cSrcweir <xsl:otherwise> 151cdf0e10cSrcweir <xsl:for-each select="node|prop"> 152cdf0e10cSrcweir <xsl:apply-templates select="."> 153cdf0e10cSrcweir <xsl:with-param name="context" select="$context/*[@oor:name = current()/@oor:name]"/> 154cdf0e10cSrcweir <xsl:with-param name="component-schema" select="$component-schema"/> 155cdf0e10cSrcweir </xsl:apply-templates> 156cdf0e10cSrcweir </xsl:for-each> 157cdf0e10cSrcweir </xsl:otherwise> 158cdf0e10cSrcweir </xsl:choose> 159cdf0e10cSrcweir </xsl:template> 160cdf0e10cSrcweir 161cdf0e10cSrcweir<!-- ****************************************** --> 162cdf0e10cSrcweir<!-- * prop *** --> 163cdf0e10cSrcweir<!-- ****************************************** --> 164cdf0e10cSrcweir <xsl:template match="prop"> 165cdf0e10cSrcweir <xsl:param name = "context"/> 166cdf0e10cSrcweir <xsl:variable name = "path"> 167cdf0e10cSrcweir <xsl:call-template name="collectPath"/> 168cdf0e10cSrcweir </xsl:variable> 169cdf0e10cSrcweir 170cdf0e10cSrcweir 171cdf0e10cSrcweir <xsl:if test="not ($context)"> 172cdf0e10cSrcweir <xsl:message terminate="yes">ERROR: Property '<xsl:value-of select="$path"/>' does not exist in schema !</xsl:message> 173cdf0e10cSrcweir </xsl:if> 174cdf0e10cSrcweir 175cdf0e10cSrcweir <xsl:if test="@oor:op"> 176cdf0e10cSrcweir <xsl:message terminate="yes">ERROR: Property '<xsl:value-of select="$path"/>' has unexpected operation '<xsl:value-of select="@oor:op"/>' !</xsl:message> 177cdf0e10cSrcweir </xsl:if> 178cdf0e10cSrcweir 179cdf0e10cSrcweir <xsl:call-template name="checkModule"/> 180cdf0e10cSrcweir <xsl:call-template name="checkDuplicates"/> 181cdf0e10cSrcweir 182cdf0e10cSrcweir <xsl:apply-templates /> 183cdf0e10cSrcweir </xsl:template> 184cdf0e10cSrcweir 185cdf0e10cSrcweir<!-- ****************************************** --> 186cdf0e10cSrcweir<!-- * value *** --> 187cdf0e10cSrcweir<!-- ****************************************** --> 188cdf0e10cSrcweir <xsl:template match="value"> 189cdf0e10cSrcweir <xsl:call-template name="checkModule"/> 190cdf0e10cSrcweir 191cdf0e10cSrcweir <xsl:if test="@install:module"> 192cdf0e10cSrcweir <xsl:variable name = "path"> 193cdf0e10cSrcweir <xsl:call-template name="collectPath"/> 194cdf0e10cSrcweir </xsl:variable> 195cdf0e10cSrcweir <xsl:variable name = "module" select="@install:module"/> 196cdf0e10cSrcweir <xsl:variable name = "lang" select="@xml:lang"/> 197cdf0e10cSrcweir 198cdf0e10cSrcweir <xsl:if test="following-sibling::value[@install:module=$module and @xml:lang=$lang]"> 199cdf0e10cSrcweir <xsl:message terminate="yes">ERROR: Property '<xsl:value-of select="$path"/>' has multiple values for module <xsl:value-of select="$module"/> and locale <xsl:value-of select="$lang"/>!</xsl:message> 200cdf0e10cSrcweir </xsl:if> 201cdf0e10cSrcweir <xsl:if test="not(preceding-sibling::value/@install:module)"> 202cdf0e10cSrcweir <xsl:message>ATTENTION: Property '<xsl:value-of select="$path"/>' has different values for different modules. Make sure the modules are mutually exclusive!</xsl:message> 203cdf0e10cSrcweir </xsl:if> 204cdf0e10cSrcweir </xsl:if> 205cdf0e10cSrcweir </xsl:template> 206cdf0e10cSrcweir 207cdf0e10cSrcweir<!-- ****************************************** --> 208cdf0e10cSrcweir<!-- * node (mode:extensible) - not supported * --> 209cdf0e10cSrcweir<!-- ****************************************** --> 210cdf0e10cSrcweir <xsl:template match="node" mode="extensible"> 211cdf0e10cSrcweir <xsl:variable name = "path"> 212cdf0e10cSrcweir <xsl:call-template name="collectPath"/> 213cdf0e10cSrcweir </xsl:variable> 214cdf0e10cSrcweir 215cdf0e10cSrcweir <xsl:message terminate="yes">ERROR: Node '<xsl:value-of select="$path"/>' is within an extensible node!</xsl:message> 216cdf0e10cSrcweir </xsl:template> 217cdf0e10cSrcweir<!-- ****************************************** --> 218cdf0e10cSrcweir<!-- * prop (mode:extensible) *** --> 219cdf0e10cSrcweir<!-- ****************************************** --> 220cdf0e10cSrcweir <xsl:template match="prop" mode="extensible"> 221cdf0e10cSrcweir <xsl:param name = "context"/> 222cdf0e10cSrcweir <xsl:variable name = "path"> 223cdf0e10cSrcweir <xsl:call-template name="collectPath"/> 224cdf0e10cSrcweir </xsl:variable> 225cdf0e10cSrcweir 226cdf0e10cSrcweir <xsl:choose> 227cdf0e10cSrcweir <xsl:when test="not(@oor:op)"> 228cdf0e10cSrcweir <xsl:if test="not ($context)"> 229cdf0e10cSrcweir <xsl:message terminate="yes">ERROR: Property '<xsl:value-of select="$path"/>' does not exist in schema!</xsl:message> 230cdf0e10cSrcweir </xsl:if> 231cdf0e10cSrcweir </xsl:when> 232cdf0e10cSrcweir <xsl:when test="@oor:op='replace'"> 233cdf0e10cSrcweir <xsl:if test="not (@oor:type)"> 234cdf0e10cSrcweir <xsl:message terminate="yes">ERROR: Property '<xsl:value-of select="$path"/>' does not have a type!</xsl:message> 235cdf0e10cSrcweir </xsl:if> 236cdf0e10cSrcweir </xsl:when> 237cdf0e10cSrcweir <xsl:otherwise> 238cdf0e10cSrcweir <xsl:message terminate="yes">ERROR: Property '<xsl:value-of select="$path"/>' has unexpected operation '<xsl:value-of select="@oor:op"/>'!</xsl:message> 239cdf0e10cSrcweir </xsl:otherwise> 240cdf0e10cSrcweir </xsl:choose> 241cdf0e10cSrcweir 242cdf0e10cSrcweir <xsl:call-template name="checkModule"/> 243cdf0e10cSrcweir <xsl:call-template name="checkDuplicates"/> 244cdf0e10cSrcweir </xsl:template> 245cdf0e10cSrcweir 246cdf0e10cSrcweir 247cdf0e10cSrcweir<!-- ************************************* --> 248cdf0e10cSrcweir<!-- * checkDuplicates *** --> 249cdf0e10cSrcweir<!-- ************************************* --> 250cdf0e10cSrcweir <xsl:template name="checkDuplicates"> 251cdf0e10cSrcweir <xsl:variable name="item-name" select="@oor:name"/> 252cdf0e10cSrcweir <xsl:if test="following-sibling::*[@oor:name = $item-name]"> 253cdf0e10cSrcweir <xsl:variable name = "path"> 254cdf0e10cSrcweir <xsl:call-template name="collectPath"/> 255cdf0e10cSrcweir </xsl:variable> 256cdf0e10cSrcweir <xsl:message terminate="yes">ERROR: Duplicate node/prop '<xsl:value-of select="$path"/>'!</xsl:message> 257cdf0e10cSrcweir </xsl:if> 258cdf0e10cSrcweir </xsl:template> 259cdf0e10cSrcweir 260cdf0e10cSrcweir 261cdf0e10cSrcweir<!-- ************************************* --> 262cdf0e10cSrcweir<!-- * checkModule *** --> 263cdf0e10cSrcweir<!-- ************************************* --> 264cdf0e10cSrcweir <xsl:template name="checkModule"> 265cdf0e10cSrcweir <xsl:if test="@install:module"> 266cdf0e10cSrcweir <xsl:if test="ancestor::*[@install:module]"> 267cdf0e10cSrcweir <xsl:message terminate="yes">ERROR: Nested modules are not supported. Found module '<xsl:value-of select="@install:module"/>' within module '<xsl:value-of select="ancestor::*/@install:module"/>'! 268cdf0e10cSrcweir </xsl:message> 269cdf0e10cSrcweir </xsl:if> 270cdf0e10cSrcweir </xsl:if> 271cdf0e10cSrcweir </xsl:template> 272cdf0e10cSrcweir 273cdf0e10cSrcweir<!-- ************************************* --> 274cdf0e10cSrcweir<!-- * collectPath *** --> 275cdf0e10cSrcweir<!-- ************************************* --> 276cdf0e10cSrcweir <xsl:template name="collectPath"> 277cdf0e10cSrcweir <xsl:for-each select="ancestor-or-self::node()[@oor:name]"> 278cdf0e10cSrcweir <xsl:text>/</xsl:text><xsl:value-of select="@oor:name"/> 279cdf0e10cSrcweir </xsl:for-each> 280cdf0e10cSrcweir </xsl:template> 281cdf0e10cSrcweir 282cdf0e10cSrcweir 283cdf0e10cSrcweir<!-- ****************************** --> 284cdf0e10cSrcweir<!-- * composeFileURL *** --> 285cdf0e10cSrcweir<!-- ****************************** --> 286cdf0e10cSrcweir <xsl:template name="composeFileURL"> 287cdf0e10cSrcweir <xsl:param name="componentName"/> 288cdf0e10cSrcweir <xsl:variable name="fileURL"> 289cdf0e10cSrcweir <xsl:value-of select="$schemaRootURL"/>/<xsl:value-of select="translate($componentName,'.','/')"/><xsl:text>.xcs</xsl:text> 290cdf0e10cSrcweir </xsl:variable> 291cdf0e10cSrcweir <xsl:value-of select="$fileURL"/> 292cdf0e10cSrcweir </xsl:template> 293cdf0e10cSrcweir 294cdf0e10cSrcweir 295cdf0e10cSrcweir</xsl:transform> 296cdf0e10cSrcweir 297