1 | <?xml version="1.0" encoding="UTF-8"?> |
---|
2 | <xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="2.0" |
---|
3 | xmlns:dcif="http://www.isocat.org/ns/dcif" xmlns:dcr="http://www.isocat.org/ns/dcr" |
---|
4 | xmlns:isocat="http://www.isocat.org/" xmlns:xs="http://www.w3.org/2001/XMLSchema" |
---|
5 | xmlns:sch="http://purl.oclc.org/dsdl/schematron" exclude-result-prefixes="dcif isocat"> |
---|
6 | <xsl:output method="xml" encoding="utf-8" indent="yes"/> |
---|
7 | <xsl:param name="props"/> |
---|
8 | <xsl:variable name="NL" select="system-property('line.separator')"/> |
---|
9 | <xsl:variable name="indent" select="'    '"/> |
---|
10 | <xsl:template match="text()"/> |
---|
11 | |
---|
12 | <xsl:template match="dcif:dataCategorySelection"> |
---|
13 | <xs:schema> |
---|
14 | <xsl:comment> |
---|
15 | <xsl:value-of select="$indent"/> |
---|
16 | <xsl:text>This XML Schema document is mainly a template to be further developed in a full</xsl:text> |
---|
17 | <xsl:value-of select="$NL"/> |
---|
18 | <xsl:value-of select="$indent"/> |
---|
19 | <xsl:text>schema. It's main purpose is to provide dcr:datcat annotation attributes to</xsl:text> |
---|
20 | <xsl:value-of select="$NL"/> |
---|
21 | <xsl:value-of select="$indent"/> |
---|
22 | <xsl:text>maintain the link between the generated elements and values and the used Data</xsl:text> |
---|
23 | <xsl:value-of select="$NL"/> |
---|
24 | <xsl:value-of select="$indent"/> |
---|
25 | <xsl:text>Categories.</xsl:text> |
---|
26 | <xsl:value-of select="$NL"/> |
---|
27 | </xsl:comment> |
---|
28 | <xsl:apply-templates select="dcif:dataCategory"/> |
---|
29 | </xs:schema> |
---|
30 | </xsl:template> |
---|
31 | |
---|
32 | <xsl:template match="dcif:dataCategory[@type='container']"> |
---|
33 | <xsl:variable name="name" select="./@isocat:identifier"/> |
---|
34 | <xsl:variable name="datcatref" select="./@pid"/> |
---|
35 | <xs:element name="{$name}" dcr:datcat="{$datcatref}"> |
---|
36 | <xs:complexType> |
---|
37 | <xsl:comment> |
---|
38 | <xsl:value-of select="$indent"/> |
---|
39 | <xsl:text>Embed (references to) other elements related to container or complex</xsl:text> |
---|
40 | <xsl:value-of select="$NL"/> |
---|
41 | <xsl:value-of select="$indent"/> |
---|
42 | <xsl:text>Data Categories here.</xsl:text> |
---|
43 | <xsl:value-of select="$NL"/> |
---|
44 | </xsl:comment> |
---|
45 | </xs:complexType> |
---|
46 | </xs:element> |
---|
47 | </xsl:template> |
---|
48 | |
---|
49 | <xsl:template match="dcif:dataCategory[@type='complex']"> |
---|
50 | <xsl:variable name="name" select="./@isocat:identifier"/> |
---|
51 | <xsl:variable name="datcatref" select="./@pid"/> |
---|
52 | <xsl:variable name="datatype" select="./dcif:conceptualDomain[1]/dcif:dataType"/> |
---|
53 | <xs:element name="{$name}" dcr:datcat="{$datcatref}"> |
---|
54 | <xsl:choose> |
---|
55 | <xsl:when test="./@isocat:type eq 'open'"> |
---|
56 | <xsl:attribute name="type" select="concat('xs:',$datatype)"/> |
---|
57 | </xsl:when> |
---|
58 | <xsl:when test="./@isocat:type eq 'constrained'"> |
---|
59 | <xsl:call-template name="conceptualDomainTemplate"/> |
---|
60 | </xsl:when> |
---|
61 | <xsl:when test="./@isocat:type eq 'closed'"> |
---|
62 | <xs:simpleType> |
---|
63 | <xs:restriction base="xs:{$datatype}"> |
---|
64 | <xsl:for-each-group select="dcif:conceptualDomain/dcif:value[empty(@isocat:suppress) or (@isocat:suppress!='true')]" group-by="@isocat:name"> |
---|
65 | <xsl:for-each select="current-group()"> |
---|
66 | <xsl:variable name="datcat" select="./@pid"/> |
---|
67 | <xsl:variable name="groupname" |
---|
68 | select="current-grouping-key()"/> |
---|
69 | <xsl:choose> |
---|
70 | <xsl:when test="position() eq 1"> |
---|
71 | <xs:enumeration value="{$groupname}" |
---|
72 | dcr:datcat="{$datcat}"/> |
---|
73 | </xsl:when> |
---|
74 | <xsl:otherwise> |
---|
75 | <xsl:value-of select="$NL"/> |
---|
76 | <xsl:comment> |
---|
77 | <xsl:text><xs:enumeration value="</xsl:text> |
---|
78 | <xsl:value-of select="$groupname"/> |
---|
79 | <xsl:text>" dcr:datcat="</xsl:text> |
---|
80 | <xsl:value-of select="$datcat"/> |
---|
81 | <xsl:text>"/></xsl:text> |
---|
82 | </xsl:comment> |
---|
83 | <xsl:value-of select="$NL"/> |
---|
84 | </xsl:otherwise> |
---|
85 | </xsl:choose> |
---|
86 | </xsl:for-each> |
---|
87 | </xsl:for-each-group> |
---|
88 | </xs:restriction> |
---|
89 | </xs:simpleType> |
---|
90 | </xsl:when> |
---|
91 | </xsl:choose> |
---|
92 | </xs:element> |
---|
93 | </xsl:template> |
---|
94 | |
---|
95 | <!-- skip simple DCs as they are handled through the value domain of a closed DC --> |
---|
96 | <xsl:template match="dcif:dataCategory[@type='simple']"/> |
---|
97 | |
---|
98 | <xsl:template name="conceptualDomainTemplate"> |
---|
99 | <xsl:choose> |
---|
100 | <xsl:when test="dcif:conceptualDomain[dcif:ruleType='XML Schema facet']"> |
---|
101 | <xsl:variable name="datatype" select="(dcif:conceptualDomain/dcif:dataType)[1]"/> |
---|
102 | <xs:simpleType> |
---|
103 | <xs:restriction base="xs:{$datatype}"> |
---|
104 | <xsl:copy-of copy-namespaces="no" |
---|
105 | select="(dcif:conceptualDomain[dcif:ruleType='XML Schema facet']/dcif:rule/*)[1]"/> |
---|
106 | </xs:restriction> |
---|
107 | </xs:simpleType> |
---|
108 | </xsl:when> |
---|
109 | <xsl:when test="dcif:conceptualDomain[dcif:ruleType='XML Schema regular expression']"> |
---|
110 | <xsl:variable name="datatype" select="(dcif:conceptualDomain/dcif:dataType)[1]"/> |
---|
111 | <xs:simpleType> |
---|
112 | <xs:restriction base="xs:{$datatype}"> |
---|
113 | <xsl:variable name="pattern" |
---|
114 | select="(dcif:conceptualDomain[dcif:ruleType='XML Schema regular expression']/dcif:rule)[1]"/> |
---|
115 | <xs:pattern value="{$pattern}"/> |
---|
116 | </xs:restriction> |
---|
117 | </xs:simpleType> |
---|
118 | </xsl:when> |
---|
119 | <xsl:when test="dcif:conceptualDomain[dcif:ruleType='Schematron rule']"> |
---|
120 | <xsl:variable name="datatype" select="(dcif:conceptualDomain/dcif:dataType)[1]"/> |
---|
121 | <xsl:attribute name="type" select="concat('xs:',$datatype)"/> |
---|
122 | <xsl:copy-of copy-namespaces="no" |
---|
123 | select="(dcif:conceptualDomain[dcif:ruleType='Schematron rule']/dcif:rule/*)[1]"/> |
---|
124 | </xsl:when> |
---|
125 | <xsl:when test="dcif:conceptualDomain[dcif:ruleType='SCHEMAcat reference']"> |
---|
126 | <xsl:variable name="datatype" select="(dcif:conceptualDomain/dcif:dataType)[1]"/> |
---|
127 | <xsl:attribute name="type" select="concat('xs:',$datatype)"/> |
---|
128 | <xs:annotation> |
---|
129 | <xs:appinfo> |
---|
130 | <xsl:copy-of copy-namespaces="no" |
---|
131 | select="(dcif:conceptualDomain[dcif:ruleType='SCHEMAcat reference']/dcif:rule/*)[1]"/> |
---|
132 | </xs:appinfo> |
---|
133 | </xs:annotation> |
---|
134 | </xsl:when> |
---|
135 | <xsl:otherwise> |
---|
136 | <xsl:variable name="datatype" select="(dcif:conceptualDomain/dcif:dataType)[1]"/> |
---|
137 | <xsl:attribute name="type" select="concat('xs:',$datatype)"/> |
---|
138 | </xsl:otherwise> |
---|
139 | </xsl:choose> |
---|
140 | </xsl:template> |
---|
141 | </xsl:stylesheet> |
---|