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