1<?xml version='1.0' encoding="UTF-8"?>
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<xsl:stylesheet version="1.0"
25                xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
26                xmlns:redirect="http://xml.apache.org/xalan/redirect"
27                extension-element-prefixes="redirect">
28<xsl:output method="text" indent="no" omit-xml-declaration="no" version="1.0" encoding="UTF-8" />
29
30    <!-- OPTIONAL: output directory for the IDL
31                   Have to end with path separator -->
32    <xsl:param name="IDL_DIRECTORY" />
33
34    <xsl:key name="same-context-elements"
35             match="/api/element[@type='constant']"
36             use="normalize-space(source/context)" />
37
38    <xsl:template match="/">
39        <!-- once for each enumeration -->
40        <xsl:for-each select="/api/element[@type='enumeration']">
41            <xsl:sort select="normalize-space(source/name)" />
42
43            <redirect:write select="concat($IDL_DIRECTORY, normalize-space(source/name),'.idl')">
44                <xsl:call-template name="write-idl-prefix-1" />
45                <xsl:call-template name="write-idl-prefix-2" />
46                <!-- write IDL content -->
47                <xsl:for-each select="key('same-context-elements', normalize-space(source/name))">
48                    <xsl:call-template name="write-idl-content" />
49                </xsl:for-each>
50                <xsl:call-template name="write-idl-suffix" />
51            </redirect:write>
52        </xsl:for-each>
53    </xsl:template>
54
55
56    <!-- writing the IDL prefix -->
57    <xsl:template name="write-idl-prefix-1">
58	<xsl:variable name="submod" select="source/@id"/>
59	<xsl:variable name="period" select="'.'"/>
60	<xsl:variable name="lcletters">abcdefghijklmnopqrstuvwxyz</xsl:variable>
61	<xsl:variable name="ucletters">ABCDEFGHIJKLMNOPQRSTUVWXYZ</xsl:variable>
62<xsl:text>
63        module org { module openoffice { module </xsl:text><xsl:value-of select="translate(substring-before($submod,$period),$ucletters,$lcletters)"/>
64    </xsl:template>
65    <xsl:template name="write-idl-prefix-2">
66<xsl:text> {
67            constants </xsl:text><xsl:value-of select="normalize-space(source/name)" /><xsl:text> {</xsl:text>
68    </xsl:template>
69
70    <!-- writing the IDL content -->
71    <xsl:template name="write-idl-content">
72<xsl:text>
73                const long </xsl:text><xsl:value-of select="source/name" /><xsl:text> = </xsl:text><xsl:value-of select="source/value" /><xsl:text>;</xsl:text>
74    </xsl:template>
75
76    <!-- writing the IDL suffix -->
77    <xsl:template name="write-idl-suffix">
78<xsl:text>
79            };
80        }; }; };
81</xsl:text>
82    </xsl:template>
83</xsl:stylesheet>
84
85