1 | <?xml version="1.0" encoding="UTF-8"?> |
---|
2 | <xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:xs="http://www.w3.org/2001/XMLSchema" |
---|
3 | xmlns:my="myFunctions" exclude-result-prefixes="xs my" version="2.0"> |
---|
4 | |
---|
5 | <xsl:include href="smc_params.xsl"/> |
---|
6 | <xsl:include href="smc_functions.xsl"/> |
---|
7 | <xsl:include href="cmd_includes.xsl"/> |
---|
8 | <xsl:include href="dcr_rdf2terms.xsl"/> |
---|
9 | |
---|
10 | <!-- use either input (precedence) or the config-file as the termsets configuration --> |
---|
11 | <xsl:variable name="termsets_config"> |
---|
12 | <xsl:choose> |
---|
13 | <xsl:when test="exists(/Termsets)"> |
---|
14 | <xsl:copy-of select="/Termsets"></xsl:copy-of> |
---|
15 | </xsl:when> |
---|
16 | <xsl:otherwise> |
---|
17 | <xsl:copy-of select="document($termset_config_file)"></xsl:copy-of> |
---|
18 | </xsl:otherwise> |
---|
19 | </xsl:choose> |
---|
20 | </xsl:variable> |
---|
21 | |
---|
22 | <!-- needed in cmd_includes.xsl --> |
---|
23 | <xsl:variable name="cmd_components_uri" select="my:config('cmd-components','url')" /> |
---|
24 | <xsl:variable name="cmd_profiles_uri" select="my:config('cmd-profiles','url')" /> |
---|
25 | |
---|
26 | <!-- intermediate datasets bound into variables,to prevent calling the function every time --> |
---|
27 | <xsl:variable name="dcr-terms" select="my:getData('dcr-terms')" /> |
---|
28 | <xsl:variable name="cmd-terms" select="my:getData('cmd-terms')" /> |
---|
29 | <xsl:variable name="dcr-cmd-map" select="my:getData('dcr-cmd-map')" /> |
---|
30 | <xsl:variable name="isocat-languages" select="my:getData('isocat-languages')" /> |
---|
31 | |
---|
32 | <!-- serves individual datasets (cmd-profiles, dcr-termsets...) |
---|
33 | primitive cache mechanism - |
---|
34 | if data of given key is already stored, serve it, |
---|
35 | otherwise build a new (but don't store in cache - within this function) |
---|
36 | regard the cache-param - beware of the param-value in recursive calls (currently 'use' is fixed for deeper calls) --> |
---|
37 | <xsl:function name="my:getData"> |
---|
38 | <xsl:param name="key"></xsl:param> |
---|
39 | <xsl:param name="cache"></xsl:param> |
---|
40 | |
---|
41 | <xsl:variable name="cached_data_file" select="concat($cache_dir, $key, '.xml')"></xsl:variable> |
---|
42 | <xsl:message> |
---|
43 | cache: <xsl:value-of select="$cache" /> |
---|
44 | <xsl:value-of select="$cached_data_file" />: <xsl:value-of select="doc-available($cached_data_file)" /> |
---|
45 | </xsl:message> |
---|
46 | <xsl:choose> |
---|
47 | <xsl:when test="doc-available($cached_data_file) and $cache='use'"> |
---|
48 | <xsl:message>reading in: <xsl:value-of select="$cached_data_file" /> |
---|
49 | </xsl:message> |
---|
50 | <xsl:copy-of select="document($cached_data_file)"></xsl:copy-of> |
---|
51 | </xsl:when> |
---|
52 | <xsl:when test="$key='cmd-profiles-raw'"> |
---|
53 | <xsl:copy-of select="document(my:config('cmd-profiles','url'))" /> |
---|
54 | </xsl:when> |
---|
55 | <xsl:when test="$key='cmd-resolved'"> |
---|
56 | <xsl:apply-templates select="my:getData('cmd-profiles-raw')" mode="include" /> |
---|
57 | </xsl:when> |
---|
58 | <xsl:when test="$key='cmd-terms'"> |
---|
59 | <xsl:copy-of select="my:profiles2termsets(my:getData('cmd-resolved')//profileDescription)" /> |
---|
60 | </xsl:when> |
---|
61 | <xsl:when test="$key='dcr-terms'"> |
---|
62 | <xsl:call-template name="load-dcr" /> |
---|
63 | </xsl:when> |
---|
64 | <xsl:when test="$key='termsets'"> |
---|
65 | <xsl:call-template name="termsets" /> |
---|
66 | </xsl:when> |
---|
67 | <xsl:when test="$key='isocat-languages'"> |
---|
68 | <xsl:copy-of select="document(my:config('isocat-languages','url'))" /> |
---|
69 | </xsl:when> |
---|
70 | <xsl:when test="$key='dcr-cmd-map'"> |
---|
71 | <xsl:call-template name="dcr-cmd-map" /> |
---|
72 | </xsl:when> |
---|
73 | <!-- for debugging --> |
---|
74 | <xsl:when test="$key='termsets-config'"> |
---|
75 | <xsl:copy-of select="$termsets_config" /> |
---|
76 | </xsl:when> |
---|
77 | <xsl:otherwise> |
---|
78 | <diagnostics>unknown data: <xsl:value-of select="$key" /></diagnostics> |
---|
79 | </xsl:otherwise> |
---|
80 | </xsl:choose> |
---|
81 | </xsl:function> |
---|
82 | |
---|
83 | <!-- overload method with one param and value of global cache-param as default --> |
---|
84 | <xsl:function name="my:getData"> |
---|
85 | <xsl:param name="key"></xsl:param> |
---|
86 | <xsl:copy-of select="my:getData($key,$cache)"></xsl:copy-of> |
---|
87 | </xsl:function> |
---|
88 | |
---|
89 | <!-- load all dcrs from the configuration and transform them into Termsets |
---|
90 | (uses mode=dcr-templates in dcr_rdf2terms.xsl) --> |
---|
91 | <xsl:template name="load-dcr"> |
---|
92 | <Termsets type="dcr"> |
---|
93 | <xsl:for-each select="$termsets_config//*[type='dcr']" > |
---|
94 | <xsl:variable name="dcr_termset" select="document(url)" /> |
---|
95 | <xsl:apply-templates select="$dcr_termset" mode="dcr" > |
---|
96 | <xsl:with-param name="set" select="key"></xsl:with-param> |
---|
97 | </xsl:apply-templates> |
---|
98 | </xsl:for-each> |
---|
99 | </Termsets> |
---|
100 | </xsl:template> |
---|
101 | |
---|
102 | <!-- invert the profiles-termsets + match with data from DCRs = create map datcat -> cmd-elements[] --> |
---|
103 | <xsl:template name="dcr-cmd-map"> |
---|
104 | <Termset type="dcr-cmd-map" > |
---|
105 | <xsl:for-each-group select="$cmd-terms//Term[not(@datcat='')]" group-by="@datcat"> |
---|
106 | <Concept id="{@datcat}" type="datcat"> |
---|
107 | <xsl:copy-of select="$dcr-terms//Concept[@id=current()/@datcat]/Term" /> |
---|
108 | <xsl:for-each select="current-group()"> |
---|
109 | <xsl:variable name="parent_profile" select="ancestor::Termset[@type='CMD_Profile']/@id" /> |
---|
110 | <Term set="cmd" type="full-path" schema="{$parent_profile}" id="{@id}"><xsl:value-of select="@path" /></Term> |
---|
111 | <!--<xsl:copy-of select="."></xsl:copy-of>--> |
---|
112 | </xsl:for-each> |
---|
113 | </Concept> |
---|
114 | </xsl:for-each-group> |
---|
115 | </Termset> |
---|
116 | </xsl:template> |
---|
117 | |
---|
118 | <!-- list dcr-termsets + cmd (+ cmd-profiles) |
---|
119 | TODO: missing: isocat@langs, RR-sets --> |
---|
120 | <xsl:template name="termsets"> |
---|
121 | <Termsets type="list"> |
---|
122 | <!-- add dcr-termsets directly from config --> |
---|
123 | <xsl:for-each select="$termsets_config//*[type='dcr'][not(key='isocat')]" > |
---|
124 | <Termset> |
---|
125 | <xsl:copy-of select="*" /> |
---|
126 | </Termset> |
---|
127 | </xsl:for-each> |
---|
128 | <xsl:for-each select="$termsets_config//*[type='dcr'][key='isocat']" > |
---|
129 | <Termset> |
---|
130 | <xsl:copy-of select="*" /> |
---|
131 | <xsl:for-each select="$isocat-languages/languages/language" > |
---|
132 | <Termset> |
---|
133 | <!-- name="Finnish" search="finnish" tag="fi"--> |
---|
134 | <key>isocat-<xsl:value-of select="@tag"></xsl:value-of></key> |
---|
135 | <name>ISOcat <xsl:value-of select="@name"></xsl:value-of></name> |
---|
136 | </Termset> |
---|
137 | </xsl:for-each> |
---|
138 | </Termset> |
---|
139 | </xsl:for-each> |
---|
140 | |
---|
141 | <Termset type="cmd"> |
---|
142 | <xsl:for-each select="$cmd-terms//Termset" > |
---|
143 | <key>cmd-profiles</key> |
---|
144 | <id><xsl:value-of select="@id"></xsl:value-of></id> |
---|
145 | <name>CMD Profiles</name> |
---|
146 | <Termset> |
---|
147 | <key><xsl:value-of select="@name"></xsl:value-of></key> |
---|
148 | <id><xsl:value-of select="@id"></xsl:value-of></id> |
---|
149 | <name><xsl:value-of select="@name"></xsl:value-of></name> |
---|
150 | </Termset> |
---|
151 | </xsl:for-each> |
---|
152 | </Termset> |
---|
153 | </Termsets> |
---|
154 | </xsl:template> |
---|
155 | |
---|
156 | <!-- return a property of a Termset from the configuration. --> |
---|
157 | <xsl:function name="my:config"> |
---|
158 | <xsl:param name="key"></xsl:param> |
---|
159 | <xsl:param name="property"></xsl:param> |
---|
160 | <xsl:value-of select="$termsets_config//*[key=$key]/*[name()=$property]"></xsl:value-of> |
---|
161 | </xsl:function> |
---|
162 | </xsl:stylesheet> |
---|