<!-- 
    Copyright © ART-DECOR Expert Group and ART-DECOR Open Tools
    see https://docs.art-decor.org/copyright and https://docs.art-decor.org/licenses
    
    This program is free software; you can redistribute it and/or modify it under the terms 
    of the GNU General Public License as published by the Free Software Foundation; 
    either version 3 of the License, or (at your option) any later version.
    
    This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; 
    without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. 
    See the GNU General Public License for more details.
    
    See http://www.gnu.org/licenses/gpl.html
    
--><!-- DECOR internationalization i18n schema -->
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:sch="http://purl.oclc.org/dsdl/schematron">
    <xs:element name="artXformResourcesBundle">
        <xs:annotation>
            <xs:appinfo>
                <sch:pattern>
                    <sch:title>Validate Unique Resource Bundles</sch:title>
                    <sch:rule context="artXformResources">
                        <sch:let name="key" value="@packageRoot"/>
                        <sch:assert test="not(preceding-sibling::*[@packageRoot=$key])">Package root <sch:value-of select="$key"/> occurs more than once in the same bundle</sch:assert>
                    </sch:rule>
                </sch:pattern>
            </xs:appinfo>
        </xs:annotation>
        <xs:complexType>
            <xs:sequence>
                <xs:element ref="artXformResources" minOccurs="0" maxOccurs="unbounded"/>
            </xs:sequence>
        </xs:complexType>
    </xs:element>
    
    <xs:element name="artXformResources">
        <xs:complexType>
            <xs:sequence>
                <xs:element name="resources" type="languageResources" minOccurs="0" maxOccurs="unbounded"/>
            </xs:sequence>
            <xs:attribute name="packageRoot" use="optional">
                <xs:annotation>
                    <xs:documentation xml:lang="en-US">Contains the database path if it is not /db/apps/art</xs:documentation>
                </xs:annotation>
            </xs:attribute>
        </xs:complexType>
    </xs:element>

    <xs:complexType name="languageResources">
        <xs:annotation>
            <xs:appinfo>
                <sch:pattern>
                    <sch:title>Validate Unique Keys</sch:title>
                    <sch:rule context="resources/*">
                        <sch:let name="key" value="name()"/>
                        <sch:assert test="not(preceding-sibling::*[name()=$key])">Key <sch:value-of select="$key"/> occurs more than once in the same resources</sch:assert>
                        <sch:let name="languageCount" value="count(../../resources)"/>
                        <sch:assert test="count(../../resources/*[name()=$key])=$languageCount">Key <sch:value-of select="$key"/> is not present in all <sch:value-of select="$languageCount"/> languages</sch:assert>
                    </sch:rule>
                </sch:pattern>
            </xs:appinfo>
        </xs:annotation>
        <xs:sequence>
            <xs:any minOccurs="0" maxOccurs="unbounded" processContents="skip"/>
        </xs:sequence>
        <xs:anyAttribute processContents="skip"/>
    </xs:complexType>

</xs:schema>