1+ <?xml version =" 1.0" ?><?xar XSLT ?>
2+ <!-- Implementation for the Schematron XML Schema Language.
3+ Generates simple text output messages using XSLT2 engine
4+ -->
5+ <!--
6+ Open Source Initiative OSI - The MIT License:Licensing
7+ [OSI Approved License]
8+
9+ This source code was previously available under the zlib/libpng license.
10+ Attribution is polite.
11+
12+ The MIT License
13+
14+ Copyright (c) 2000-2010 Rick Jellife and Academia Sinica Computing Centre, Taiwan.
15+
16+ Permission is hereby granted, free of charge, to any person obtaining a copy
17+ of this software and associated documentation files (the "Software"), to deal
18+ in the Software without restriction, including without limitation the rights
19+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
20+ copies of the Software, and to permit persons to whom the Software is
21+ furnished to do so, subject to the following conditions:
22+
23+ The above copyright notice and this permission notice shall be included in
24+ all copies or substantial portions of the Software.
25+
26+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
27+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
28+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
29+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
30+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
31+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
32+ THE SOFTWARE.
33+ -->
34+
35+ <!-- Schematron message -->
36+
37+ <xsl : stylesheet
38+ version =" 2.0"
39+ xmlns : xsl =" http://www.w3.org/1999/XSL/Transform"
40+ xmlns : axsl =" http://www.w3.org/1999/XSL/TransformAlias"
41+ xmlns : iso =" http://purl.oclc.org/dsdl/schematron"
42+ xmlns : xs =" http://www.w3.org/2001/XMLSchema" >
43+
44+ <!-- The diagnostics elements -->
45+ <xsl : key name =" diag" match =" iso:diagnostic" use =" @id" />
46+
47+ <!-- Generate the message dependeng on the language
48+ - if a language code is set in the value of the $langCode parameter, the message in thet language will be presented
49+ - Otherwise, all messages will be presented
50+ -->
51+ <xsl : template name =" generateTextMassage" >
52+ <xsl : param name =" diagnostics" />
53+ <xsl : param name =" currentLanguage" required =" yes" />
54+
55+ <!-- Get all localization (diagnostics) nodes. -->
56+ <xsl : variable name =" localizationNodes" as =" item()*" >
57+ <xsl : if test =" $diagnostics != ''" >
58+ <xsl : variable name =" assert" select =" ." />
59+ <xsl : for-each select =" tokenize($diagnostics, ' ')" >
60+ <xsl : sequence select =" key('diag', current(), root($assert))" />
61+ </xsl : for-each >
62+ </xsl : if >
63+ </xsl : variable >
64+
65+ <!-- Generate the (localization) diagnostics messages for the current language-->
66+ <xsl : variable name =" localizationMessages" as =" item()*" >
67+ <xsl : for-each select =" $localizationNodes" >
68+ <xsl : call-template name =" getMessage" >
69+ <xsl : with-param name =" reqLang" select =" $currentLanguage" />
70+ <xsl : with-param name =" isAddId" select =" false()" />
71+ </xsl : call-template >
72+ </xsl : for-each >
73+ </xsl : variable >
74+
75+ <!-- Generate the message from assert only if matches the current language -->
76+ <xsl : variable name =" assertMsg" as =" item()*" >
77+ <xsl : call-template name =" getMessage" >
78+ <xsl : with-param name =" reqLang" select =" $currentLanguage" />
79+ </xsl : call-template >
80+ </xsl : variable >
81+
82+ <xsl : choose >
83+ <xsl : when
84+ test =" not(empty($localizationMessages)) or (not(empty($assertMsg)) and $localizationNodes)" >
85+ <!-- Generate the message for the current language, both from the assertion and from localization nodes -->
86+ <xsl : sequence select =" $assertMsg" />
87+ <xsl : sequence select =" $localizationMessages" />
88+ </xsl : when >
89+ <xsl : when test =" $currentLanguage != 'default'" >
90+ <!-- If no localization (diagnostics) for a specific language-->
91+ <xsl : choose >
92+ <!-- Generate the assertion message for the current language-->
93+ <xsl : when test =" not(empty($assertMsg))" >
94+ <xsl : sequence select =" $assertMsg" />
95+ </xsl : when >
96+ <xsl : otherwise >
97+ <!-- Generate the messages for all languages. -->
98+ <!-- Print assertion message -->
99+ <xsl : variable name =" assertMsgDef" >
100+ <xsl : call-template name =" getMessage" >
101+ <xsl : with-param name =" reqLang" select =" 'default'" />
102+ </xsl : call-template >
103+ </xsl : variable >
104+ <xsl : sequence select =" $assertMsgDef" />
105+ <!-- Print distinct diagnostics messages. -->
106+ <xsl : variable name =" allMessages" as =" item()*" >
107+ <xsl : for-each select =" $localizationNodes" >
108+ <xsl : call-template name =" getMessage" >
109+ <xsl : with-param name =" reqLang" select =" 'default'" />
110+ <xsl : with-param name =" isAddId" select =" true()" />
111+ </xsl : call-template >
112+ </xsl : for-each >
113+ </xsl : variable >
114+ <xsl : sequence select =" $allMessages" />
115+ </xsl : otherwise >
116+ </xsl : choose >
117+ </xsl : when >
118+ <xsl : otherwise >
119+ <!-- Generate the assertion message, if no language match-->
120+ <xsl : variable name =" assertMsgDef" >
121+ <xsl : call-template name =" getMessage" >
122+ <xsl : with-param name =" reqLang" select =" 'default'" />
123+ </xsl : call-template >
124+ </xsl : variable >
125+ <xsl : sequence select =" $assertMsgDef" />
126+ </xsl : otherwise >
127+ </xsl : choose >
128+ </xsl : template >
129+
130+ <!-- Function used to obtain the message from the current node -->
131+ <xsl : template name =" getMessage" >
132+ <xsl : param name =" reqLang" as =" xs:string" required =" yes" />
133+ <xsl : param name =" isAddId" as =" xs:boolean" select =" false()" />
134+
135+ <xsl : choose >
136+ <xsl : when test =" $reqLang != 'default'" >
137+ <!-- Get the language from the current node -->
138+ <xsl : variable name =" lang" >
139+ <xsl : variable name =" currentLang" select =" (ancestor-or-self::*/@xml:lang)[last()]" />
140+ <xsl : value-of select =" if ($currentLang) then ($currentLang) else ('#NONE')" />
141+ </xsl : variable >
142+ <!-- Generate the message from assert only if matches the current language -->
143+ <xsl : if test =" starts-with($lang, $reqLang)" >
144+ <xsl : if test =" $isAddId" >[#<xsl : value-of select =" @id" />]</xsl : if >
145+ <xsl : apply-templates mode =" text" />
146+ </xsl : if >
147+ </xsl : when >
148+ <xsl : otherwise >
149+ <!-- Generate the message with the language in front. -->
150+ <xsl : if test =" $isAddId" >[#<xsl : value-of select =" @id" />]</xsl : if >
151+ <xsl : if test =" @xml:lang" >[<xsl : value-of select =" @xml:lang" />]</xsl : if >
152+ <xsl : apply-templates mode =" text" />
153+ </xsl : otherwise >
154+ </xsl : choose >
155+ </xsl : template >
156+
157+ </xsl : stylesheet >
0 commit comments