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