Project

Profile

Help

How to connect?
Download (9.85 KB) Statistics
| Branch: | Revision:

he / tools / featureKeys / FeatureKeysToCSharp.xsl @ 2699858e

1
<?xml version="1.0" encoding="UTF-8"?>
2
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
3
    xmlns:xs="http://www.w3.org/2001/XMLSchema" exclude-result-prefixes="xs"
4
    xmlns:xd="http://www.oxygenxml.com/ns/doc/xsl" version="3.0">
5

    
6
    <xd:doc scope="stylesheet">
7
        <xd:desc>
8
            <xd:p><xd:b>(re)Created on:</xd:b> October 17, 2018</xd:p>
9
            <xd:p><xd:b>Author:</xd:b> O'Neil Delpratt, Saxonica</xd:p>
10
            <xd:p>Generates FeatureKeys.cs from FeatureKeys.xml</xd:p>
11
        </xd:desc>
12
    </xd:doc>
13

    
14

    
15
    <xsl:output method="text"/>
16

    
17
    <xsl:template match="features">
18
        <xsl:call-template name="validate"/>
19
        <xsl:apply-templates select="." mode="FeatureKeys.cs"/>
20
        <xsl:apply-templates select="." mode="Feature.cs"/>
21
    </xsl:template>
22

    
23
    <xsl:template match="features" mode="FeatureKeys.cs">
24
        <xsl:result-document href="FeatureKeys.cs" method="text">
25
            <xsl:text><![CDATA[
26
using System;
27

    
28
// AUTO-GENERATED FROM FeatureKeys.xml - DO NOT EDIT THIS FILE
29

    
30
namespace Saxon.Api 
31
{
32

    
33
/// <summary>
34
/// <c>FeatureKeys</c> defines a set of constants, representing the names of Saxon configuration
35
/// options which can be supplied to the Saxon implementations of the JAXP
36
/// interfaces <c>TransformerFactory</c>, <c>SchemaFactory</c>, <c>Validator</c>, and <c>ValidationHandler</c>,
37
/// and to other interfaces such as the s9api <c>net.sf.saxon.s9api.Processor</c> 
38
/// </summary>
39

    
40
public abstract class FeatureKeys 
41
{
42

    
43
]]></xsl:text>
44
            <xsl:apply-templates select="//feature" mode="#current"/>
45
            <xsl:text><![CDATA[
46
} 
47
}
48

    
49
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
50
// Copyright (c) 2018 Saxonica Limited.
51
// This Source Code Form is subject to the terms of the Mozilla Public License, v. 2.0.
52
// If a copy of the MPL was not distributed with this file, You can obtain one at http://mozilla.org/MPL/2.0/.
53
// This Source Code Form is "Incompatible With Secondary Licenses", as defined by the Mozilla Public License, v. 2.0.
54
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
55
]]></xsl:text>
56
        </xsl:result-document>
57
    </xsl:template>
58

    
59
    <xsl:template match="features" mode="Feature.cs">
60
        <xsl:result-document href="Feature.cs" method="text">
61
            <xsl:text><![CDATA[
62
using System;
63

    
64
// AUTO-GENERATED FROM FeatureKeys.xml - DO NOT EDIT THIS FILE
65

    
66
namespace Saxon.Api 
67
{
68

    
69

    
70
/// <summary>
71
/// Feature defines a set of constants, representing the details of Saxon configuration
72
/// options which can be supplied to the Saxon method <c>Processor.SetProperty()</c>,
73
/// and to other interfaces.
74
/// </summary>
75

    
76
public class Feature<T> {
77
    
78
    private net.sf.saxon.lib.Feature jfeature;
79

    
80
    private Feature(String name) {
81
        jfeature = net.sf.saxon.lib.Feature.byName(name);
82
    }
83
    
84
    private Feature(net.sf.saxon.lib.Feature jf) {
85
        this.jfeature = jf;
86
    }
87
    
88
    /// <summary>
89
    /// Get the <c>Feature</c> object by string value name
90
    /// </summary>
91
    /// <param name="name">The feature name</param>
92
    /// <returns>The <c>Feature</c> object</returns>
93

    
94
    public static Feature<T> byName(String name) {
95
        return new Feature<T>(name);
96
    }
97
    
98
    /// <summary>
99
	/// The underlying <c>net.sf.saxon.lib.Feature</c> object in the Java implementation
100
    /// </summary>
101
    /// <remarks>
102
    /// <para>This property provides access to the internal Java <c>Feature</c> object in the 
103
    /// Saxon engine that is wrapped in the .NET API.</para> 
104
	/// <para>Information about the returned <see cref="net.sf.saxon.lib.Feature"/> object 
105
	/// is included in the Saxon JavaDoc docmentation.
106
    /// </para>
107
    /// </remarks>
108
        
109
	public net.sf.saxon.lib.Feature JFeature
110
    {
111
        get { return jfeature; }
112
    }
113

    
114

    
115
]]></xsl:text>
116
            <xsl:apply-templates select="//feature" mode="#current"/>
117
            <xsl:text><![CDATA[
118
} 
119
}
120

    
121
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
122
// Copyright (c) 2018 Saxonica Limited.
123
// This Source Code Form is subject to the terms of the Mozilla Public License, v. 2.0.
124
// If a copy of the MPL was not distributed with this file, You can obtain one at http://mozilla.org/MPL/2.0/.
125
// This Source Code Form is "Incompatible With Secondary Licenses", as defined by the Mozilla Public License, v. 2.0.
126
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
127
]]></xsl:text>
128
        </xsl:result-document>
129
    </xsl:template>
130

    
131
    <xsl:template match="feature" mode="FeatureKeys.cs">
132
        <xsl:message>Processing <xsl:value-of select="name"/></xsl:message>
133
        <xsl:apply-templates select="desc, name, uri" mode="#current"/>
134
    </xsl:template>
135

    
136

    
137
    <xsl:template match="name" mode="FeatureKeys.cs"><!-- TODO or public static readonly ??? -->
138
        <xsl:text>&#xa;&#xa;    public const String </xsl:text>
139
        <xsl:value-of select="."/>
140
        <xsl:text> = </xsl:text>
141
    </xsl:template>
142

    
143
    <xsl:template match="feature/*" priority="-0.1" mode="#all"/>
144

    
145
    <xsl:template match="uri" mode="FeatureKeys.cs">
146
        <xsl:text>&#xa;        "</xsl:text>
147
        <xsl:value-of select="."/>
148
        <xsl:text>";&#xa;</xsl:text>
149
        <xsl:text>&#xa;// AUTO-GENERATED FROM FeatureKeys.xml - DO NOT EDIT THIS FILE&#xa;&#xa;</xsl:text>
150
    </xsl:template>
151

    
152
    <xsl:template match="desc" mode="#all">
153
        <xsl:text>&#xa;    /// &lt;summary&gt;</xsl:text>
154
        <xsl:apply-templates select="p[1]" mode="#current"/>
155
        <xsl:text>&#xa;    /// &lt;/summary&gt;</xsl:text>
156
        <xsl:if test="count(child::*) gt 1">
157
            <xsl:text>&#xa;    /// &lt;remarks&gt;</xsl:text>
158
            <xsl:apply-templates select="p[1]/following-sibling::node()" mode="#current"/>
159
            <xsl:text>&#xa;    /// &lt;/remarks&gt;</xsl:text>
160
        </xsl:if>
161
    </xsl:template>
162

    
163
    <xsl:template match="desc//*" mode="#all">
164
        <xsl:text>&lt;</xsl:text>
165
        <xsl:value-of select="name()"/>
166
        <xsl:text>&gt;</xsl:text>
167
        <xsl:apply-templates mode="#current"/>
168
        <xsl:text>&lt;/</xsl:text>
169
        <xsl:value-of select="name()"/>
170
        <xsl:text>&gt;</xsl:text>
171
    </xsl:template>
172
    
173
    <xsl:template match="desc//p" priority="2" mode="#all">
174
        <xsl:text>&lt;para&gt;</xsl:text>
175
        <xsl:apply-templates mode="#current"/>
176
        <xsl:text>&lt;/para&gt;</xsl:text>
177
    </xsl:template>
178
    
179
    <xsl:template match="desc//ul" priority="2" mode="#all">
180
        <xsl:text>&lt;list&gt;</xsl:text>
181
        <xsl:apply-templates mode="#current"/>
182
        <xsl:text>&lt;/list&gt;</xsl:text>
183
    </xsl:template>
184
    
185
    <xsl:template match="desc//li" priority="2" mode="#all">
186
        <xsl:text>&lt;item&gt;</xsl:text>
187
        <xsl:apply-templates mode="#current"/>
188
        <xsl:text>&lt;/item&gt;</xsl:text>
189
    </xsl:template>
190

    
191
    <xsl:template match="desc//link" priority="2" mode="Feature.cs">
192
        <xsl:text>&lt;see cref="</xsl:text>
193
        <xsl:value-of select="replace(., 'net.sf.saxon.lib.Feature#', '')"/>
194
        <!--<xsl:value-of select="."/>-->
195
        <xsl:text>" /&gt;</xsl:text>
196
    </xsl:template>
197

    
198
    <xsl:template match="desc//link" priority="2" mode="FeatureKeys.cs">
199
        <xsl:text>&lt;see cref="</xsl:text>
200
        <xsl:value-of select="replace(., 'net.sf.saxon.lib.Feature#', '')"/>
201
        <!--<xsl:value-of select="replace(., 'net.sf.saxon.lib.Feature#', 'net.sf.saxon.lib.FeatureKeys#')"/>-->
202
        <xsl:text>" /&gt;</xsl:text>
203
    </xsl:template>
204
    
205
    <xsl:template match="desc//a" priority="2" mode="#all">
206
        <xsl:text>&lt;span class="link" data-href="</xsl:text>
207
        <xsl:value-of select="@href"/>
208
        <xsl:text>"&gt;</xsl:text>
209
        <xsl:apply-templates mode="#current"/>
210
        <xsl:text>&lt;/span&gt;</xsl:text>
211
    </xsl:template>
212

    
213
    <xsl:template match="desc//text()" mode="#all">
214
        <xsl:value-of select="replace(replace(replace(., '&#xa;', '&#xa;    ///'), '&gt;', '&amp;gt;'), '&lt;', '&amp;lt;')"/>
215
    </xsl:template>
216

    
217
    <xsl:template match="feature" mode="Feature.cs" expand-text="yes">
218
        <xsl:variable name="type" as="xs:string">
219
            <xsl:apply-templates select="type"/>
220
        </xsl:variable>
221
        <xsl:variable name="angledType" select="'&lt;'||$type||'&gt;'"/>
222
        <xsl:apply-templates select="desc" mode="#current"/>
223
        <xsl:text>&#xa;&#xa;    public static Feature{$angledType} {name} = new Feature{$angledType}(&#xa;</xsl:text>
224
        <xsl:text>            net.sf.saxon.lib.Feature.{name});&#xa;</xsl:text>
225
        <xsl:text>&#xa;// AUTO-GENERATED FROM FeatureKeys.xml - DO NOT EDIT THIS FILE&#xa;&#xa;</xsl:text>
226
    </xsl:template>
227

    
228
    <xsl:template match="type[.='boolean']">
229
        <xsl:text><![CDATA[bool]]></xsl:text>
230
    </xsl:template>
231

    
232
    <xsl:template match="type[starts-with(., 'integer')]">
233
        <xsl:text><![CDATA[int]]></xsl:text>
234
    </xsl:template>
235

    
236
    <xsl:template match="type[starts-with(., 'string') or starts-with(., 'Absolute URI')]">
237
        <xsl:text><![CDATA[String]]></xsl:text>
238
    </xsl:template>
239

    
240
    <xsl:template match="type[starts-with(., 'Instance of')]" expand-text="yes">
241
        <xsl:text>{(link|code)[1]}</xsl:text>
242
    </xsl:template>
243

    
244
    <xsl:template match="type[starts-with(., 'Name of a class')]" expand-text="yes">
245
        <xsl:text><![CDATA[String]]></xsl:text>
246
    </xsl:template>
247

    
248
    <xsl:template match="type">
249
        <xsl:text><![CDATA[Object]]></xsl:text>
250
    </xsl:template>
251

    
252

    
253
<xsl:template name="validate" expand-text="yes">
254
    <xsl:if test="//feature[not(featureCode)]">
255
        <xsl:message terminate="yes">Every feature must have a numeric featureCode</xsl:message>
256
    </xsl:if>
257
    <xsl:if test="count(//featureCode) ne count(distinct-values(//featureCode))">
258
        <xsl:message terminate="yes">Every featureCode must be unique</xsl:message>
259
    </xsl:if>
260
</xsl:template>
261

    
262

    
263
</xsl:stylesheet>
(3-3/8)