Project

Profile

Help

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

he / tools / featureKeys / FeatureKeysToSchema.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"
4
    exclude-result-prefixes="xs"
5
    version="2.0">
6
    
7
    <!-- Stylesheet to modify the schema for configuration files (config.xsd) with
8
         documentation from the master FeatureKeys.xml documentation.
9
         
10
         The stylesheet also checks the schema for consistency with FeatureKeys.xml;
11
         the set of attributes defined in both should agree
12
    -->
13
        
14
    <xsl:param name="FeatureKeys" required="yes"/>
15
    <xsl:param name="AdditionalFeatures" required="yes"/>
16
    <xsl:param name="ConfigSchema" required="yes"/>
17
    
18
    <xsl:template match="*">
19
        <xsl:copy>
20
            <xsl:copy-of select="@*"/>
21
            <xsl:apply-templates/>
22
        </xsl:copy>
23
    </xsl:template>
24
    
25
    <xsl:template name="main">
26
        <xsl:apply-templates select="doc($ConfigSchema)"/>
27
        <xsl:call-template name="consistency-check"/>
28
    </xsl:template>
29
    
30
    <xsl:template match="xs:attribute">
31
        <xsl:variable name="key" select="concat(ancestor::xs:element/@name, '/@', @name)"/>
32
        <xsl:variable name="feature" select="(doc($FeatureKeys)//feature[configfile=$key], doc($AdditionalFeatures)//feature[configfile=$key])"/>
33
        <xsl:if test="empty($feature) and empty(xs:annotation/xs:documentation)">
34
            <xsl:message>*** No documentation for attribute <xsl:value-of select="$key"/></xsl:message>
35
        </xsl:if>
36
        <xsl:copy>
37
            <xsl:copy-of select="@*"/>
38
            <xs:annotation>
39
                <xs:documentation>
40
                    <xsl:copy-of select="if (xs:annotation/xs:documentation) then
41
                        xs:annotation/xs:documentation/node() else 
42
                        if (exists($feature/configfiledesc)) 
43
                        then $feature/configfiledesc/* 
44
                        else $feature/desc/*"/>
45
                </xs:documentation>
46
            </xs:annotation>
47
        </xsl:copy>
48
    </xsl:template>
49
    
50
    <xsl:variable name="exceptions" as="xs:string*" select="('COLLATION_URI_RESOLVER',
51
        'COLLECTION_FINDER', 'COLLECTION_URI_RESOLVER', 'CONFIGURATION', 'CONFIGURATION_FILE',
52
        'ENVIRONMENT_VARIABLE_RESOLVER', 'EXPATH_FILE_DELETE_TEMPORARY_FILES',
53
        'MODULE_URI_RESOLVER', 'NAME_POOL', 'OUTPUT_URI_RESOLVER', 'RECOVERY_POLICY',
54
        'RETAIN_DTD_ATTRIBUTE_TYPES', 'SCHEMA_URI_RESOLVER', 'SCHEMA_VALIDATION', 'TRACE_LISTENER',
55
        'TREE_MODEL', 'UNPARSED_TEXT_URI_RESOLVER', 'XML_PARSER_FEATURE', 'XML_PARSER_PROPERTY')"/>
56
    
57
    <xsl:template name="consistency-check">
58
        <xsl:for-each select="doc($FeatureKeys)//feature[not(configfile) and not(string(name) = $exceptions)]">
59
            <xsl:message>*** Feature not definable in configuration file: <xsl:value-of select="name"/></xsl:message>
60
            <!-- Either the feature should be added to the exceptions list above, or added to the
61
                configuration file: 
62
                    * add configfile element in FeatureKeys.xml
63
                    * update ConfigurationReader.java code
64
            -->
65
        </xsl:for-each>
66
        <xsl:for-each select="doc($FeatureKeys)//feature/configfile">
67
            <xsl:variable name="key" select="text()"/>
68
            <xsl:variable name="keyElement" select="substring-before($key, '/@')"/>
69
            <xsl:variable name="keyAttribute" select="substring-after($key, '/@')"/>
70
            <xsl:variable name="ConfigAtt" select="doc($ConfigSchema)//xs:element[@name eq $keyElement]//xs:attribute[@name eq $keyAttribute]"/>
71
            <xsl:if test="empty($ConfigAtt)">
72
                <xsl:message>*** Feature not included in schema: <xsl:value-of select="$key"/></xsl:message>
73
                <!-- Update the schema config.xsd -->
74
            </xsl:if>
75
        </xsl:for-each>
76
    </xsl:template>
77
    
78
    <xsl:strip-space elements="*"/>
79
    <xsl:output indent="yes" saxon:double-space="xs:element" xmlns:saxon="http://saxon.sf.net/"/>
80
    
81
</xsl:stylesheet>
(6-6/8)