1<?xml version='1.0' encoding="UTF-8"?>
2<!-- =====================================================================
3
4  DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5
6  Copyright 2000, 2010 Oracle and/or its affiliates.
7
8  OpenOffice.org - a multi-platform office productivity suite
9
10  This file is part of OpenOffice.org.
11
12  OpenOffice.org is free software: you can redistribute it and/or modify
13  it under the terms of the GNU Lesser General Public License version 3
14  only, as published by the Free Software Foundation.
15
16  OpenOffice.org is distributed in the hope that it will be useful,
17  but WITHOUT ANY WARRANTY; without even the implied warranty of
18  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
19  GNU Lesser General Public License version 3 for more details
20  (a copy is included in the LICENSE file that accompanied this code).
21
22  You should have received a copy of the GNU Lesser General Public License
23  version 3 along with OpenOffice.org.  If not, see
24  <http://www.openoffice.org/license.html>
25  for a copy of the LGPLv3 License.
26
27====================================================================== -->
28<xsl:stylesheet version="1.0"
29                xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
30                xmlns:redirect="http://xml.apache.org/xalan/redirect"
31                extension-element-prefixes="redirect">
32<xsl:output method="text" indent="no" omit-xml-declaration="no" version="1.0" encoding="UTF-8" />
33
34    <!-- OPTIONAL: output directory for the IDL
35                   Have to end with path separator -->
36    <xsl:param name="IDL_DIRECTORY" />
37
38    <xsl:key name="same-context-elements"
39             match="/api/element[@type='constant']"
40             use="normalize-space(source/context)" />
41
42    <xsl:template match="/">
43        <!-- once for each enumeration -->
44        <xsl:for-each select="/api/element[@type='enumeration']">
45            <xsl:sort select="normalize-space(source/name)" />
46
47            <redirect:write select="concat($IDL_DIRECTORY, normalize-space(source/name),'.idl')">
48                <xsl:call-template name="write-idl-prefix-1" />
49                <xsl:call-template name="write-idl-prefix-2" />
50                <!-- write IDL content -->
51                <xsl:for-each select="key('same-context-elements', normalize-space(source/name))">
52                    <xsl:call-template name="write-idl-content" />
53                </xsl:for-each>
54                <xsl:call-template name="write-idl-suffix" />
55            </redirect:write>
56        </xsl:for-each>
57    </xsl:template>
58
59
60    <!-- writing the IDL prefix -->
61    <xsl:template name="write-idl-prefix-1">
62	<xsl:variable name="submod" select="source/@id"/>
63	<xsl:variable name="period" select="'.'"/>
64	<xsl:variable name="lcletters">abcdefghijklmnopqrstuvwxyz</xsl:variable>
65	<xsl:variable name="ucletters">ABCDEFGHIJKLMNOPQRSTUVWXYZ</xsl:variable>
66<xsl:text>
67        module org { module openoffice { module </xsl:text><xsl:value-of select="translate(substring-before($submod,$period),$ucletters,$lcletters)"/>
68    </xsl:template>
69    <xsl:template name="write-idl-prefix-2">
70<xsl:text> {
71            constants </xsl:text><xsl:value-of select="normalize-space(source/name)" /><xsl:text> {</xsl:text>
72    </xsl:template>
73
74    <!-- writing the IDL content -->
75    <xsl:template name="write-idl-content">
76<xsl:text>
77                const long </xsl:text><xsl:value-of select="source/name" /><xsl:text> = </xsl:text><xsl:value-of select="source/value" /><xsl:text>;</xsl:text>
78    </xsl:template>
79
80    <!-- writing the IDL suffix -->
81    <xsl:template name="write-idl-suffix">
82<xsl:text>
83            };
84        }; }; };
85</xsl:text>
86    </xsl:template>
87</xsl:stylesheet>
88
89