Debian Codegraph @

mod/schematron/test/schematrontest.xml

raw
1 <testSuite>
2 <testCase>
3 <correct>
4 <schema xmlns="http://www.ascc.net/xml/schematron">
5 <pattern name="Print both cases">
6 <rule context="AAA">
7 <assert test="BBB">BBB element is missing.</assert>
8 <report test="BBB">BBB element is present.</report>
9
10 <assert test="@name">AAA misses attribute name.</assert>
11 <report test="@name">AAA contains attribute name.</report>
12 </rule>
13 </pattern>
14
15 <pattern name="Print positive result only">
16 <rule context="AAA">
17 <report test="BBB">BBB element is present.</report>
18 <report test="@name">AAA contains attribute name.</report>
19 </rule>
20 </pattern>
21
22 <pattern name="Print negative result only">
23 <rule context="AAA">
24 <assert test="BBB">BBB element is missing.</assert>
25 <assert test="@name">AAA misses attribute name.</assert>
26 </rule>
27 </pattern>
28 </schema>
29 </correct>
30 <invalid>
31
32 <AAA>
33 <BBB/>
34 </AAA>
35 </invalid>
36 <invalid>
37
38 <AAA>
39 <CCC/>
40 </AAA>
41 </invalid>
42 </testCase>
43 <testCase>
44 <correct>
45 <schema xmlns="http://www.ascc.net/xml/schematron">
46 <pattern name="Open model">
47 <rule context="AAA">
48 <assert test="BBB"> BBB element is not present</assert>
49 <assert test="CCC"> CCC element is not present</assert>
50 </rule>
51 </pattern>
52
53 <pattern name="Closed model">
54 <rule context="AAA">
55 <assert test="BBB"> BBB element is not present</assert>
56 <assert test="CCC"> CCC element is not present</assert>
57 <assert test="count(BBB|CCC) = count (*)">There is an extra element</assert>
58 </rule>
59 </pattern>
60
61 </schema></correct>
62 <invalid>
63
64 <AAA>
65 <BBB/>
66 </AAA>
67 </invalid>
68 <invalid>
69
70 <AAA>
71 <BBB/>
72 <DDD/>
73 </AAA>
74 </invalid>
75 </testCase>
76 <testCase>
77 <correct>
78 <schema xmlns="http://www.ascc.net/xml/schematron">
79 <pattern name="Attribute test">
80 <rule context="CCC">
81 <assert test="@name">attribute name is not present</assert>
82 <report test="@name">attribute name is present</report>
83 </rule>
84 </pattern>
85 </schema></correct>
86 <invalid>
87
88 <AAA>
89 <BBB>
90 <CCC/>
91 <CCC/>
92 </BBB>
93 <CCC name="c1"/>
94 <CCC name="c2"/>
95 </AAA>
96 </invalid>
97 </testCase>
98 <testCase>
99 <correct>
100 <schema xmlns="http://www.ascc.net/xml/schematron">
101 <pattern name="Root test">
102 <rule context="/*">
103 <assert test="name()='AAA'">Root element is <name/>, not AAA</assert>
104 <report test="name()='AAA'">Root element is AAA</report>
105 </rule>
106 </pattern>
107 </schema></correct>
108 <invalid>
109
110 <AAA>
111 <BBB>
112 <CCC/>
113 <CCC/>
114 </BBB>
115 </AAA>
116 </invalid>
117 <invalid>
118
119
120 <XXX>
121 <BBB>
122 <CCC/>
123 <CCC/>
124 </BBB>
125 </XXX>
126 </invalid>
127 </testCase>
128 <testCase>
129 <correct>
130 <schema xmlns="http://www.ascc.net/xml/schematron">
131 <pattern name="Select empty elements CCC">
132 <rule context="CCC">
133 <assert test="normalize-space(.) and *">Source contains an empty element CCC </assert>
134
135 <report test="normalize-space(.) = ''">[1]An element CCC does not contain any text</report>
136 <assert test="normalize-space(.)">[2]An element CCC does not contain any text</assert>
137
138 <report test="not(*)">[1]An element CCC does not contain any child element</report>
139 <assert test="*">[2]An element CCC does not contain any child element</assert>
140 </rule>
141 </pattern>
142 </schema></correct>
143 <invalid>
144
145 <AAA>
146 <BBB>
147 <CCC/>
148 </BBB>
149 </AAA>
150 </invalid>
151 <invalid>
152
153 <AAA>
154 <BBB>
155 <CCC>I am CCC element</CCC>
156 </BBB>
157 </AAA>
158 </invalid>
159 <invalid>
160
161 <AAA>
162 <BBB>
163 <CCC>
164 <DDD/>
165 </CCC>
166 </BBB>
167 </AAA>
168 </invalid>
169 </testCase>
170 <testCase>
171 <correct>
172 <schema xmlns="http://www.ascc.net/xml/schematron">
173 <pattern name="Predefined values">
174 <rule context="AAA">
175 <report test="normalize-space(.) = 'aaa' or normalize-space(.) = 'bbb'">O.K.</report>
176 <assert test="normalize-space(.) = 'aaa' or normalize-space(.) = 'bbb'">The AAA value is not permitted.</assert>
177 </rule>
178 </pattern>
179 </schema></correct>
180 <invalid>
181
182 <AAA>
183 aaa
184 </AAA>
185 </invalid>
186 <invalid>
187
188 <AAA>
189 bbb
190 </AAA>
191 </invalid>
192 <invalid>
193
194 <AAA>
195 ccc
196 </AAA>
197 </invalid>
198 </testCase>
199 <testCase>
200 <correct>
201 <schema xmlns="http://www.ascc.net/xml/schematron">
202 <pattern name="Test integer">
203 <rule context="AAA">
204 <report test="floor(.) = number(.)">O.K.</report>
205 <assert test="floor(.) = number(.)">The AAA value is not an integer.</assert>
206 </rule>
207 </pattern>
208 </schema></correct>
209 <invalid>
210
211 <AAA>
212 aaa
213 </AAA>
214 </invalid>
215 <invalid>
216
217 <AAA>
218 12.234
219 </AAA>
220 </invalid>
221 <invalid>
222
223 <AAA>
224 45
225 </AAA>
226 </invalid>
227 <invalid>
228
229 <AAA>
230 0
231 </AAA>
232 </invalid>
233 <invalid>
234
235 <AAA>
236 -45
237 </AAA>
238 </invalid>
239 </testCase>
240 <testCase>
241 <correct>
242 <schema xmlns="http://www.ascc.net/xml/schematron">
243 <pattern name="Test count">
244 <rule context="/*">
245 <report test="count(//BBB) = count(//AAA)">O.K.</report>
246 <assert test="count(//BBB) &lt;= count(//AAA)">Some AAA are missing</assert>
247 <report test="count(//BBB) &lt; count(//AAA)">Some BBB are missing</report>
248 </rule>
249 </pattern>
250 </schema></correct>
251 <invalid>
252
253 <XXX>
254 <BBB/>
255 <BBB/>
256 <AAA/>
257 <BBB/>
258 <AAA/>
259 <AAA/>
260 </XXX>
261 </invalid>
262 <invalid>
263
264 <XXX>
265 <BBB/>
266 <AAA/>
267 <BBB/>
268 <AAA/>
269 <AAA/>
270 </XXX>
271 </invalid>
272 <invalid>
273
274 <XXX>
275 <BBB/>
276 <BBB/>
277 <AAA/>
278 <BBB/>
279 <AAA/>
280 </XXX>
281 </invalid>
282 </testCase>
283 <testCase>
284 <correct>
285 <schema xmlns="http://www.ascc.net/xml/schematron">
286 <pattern name="Test attribute">
287 <rule context="CCC">
288 <report test="parent::BBB and not(@id)">Attribute id is missing</report>
289 <report test="not(parent::BBB) and @id">Attribute id is used in wrong context</report>
290 </rule>
291 </pattern>
292 </schema></correct>
293 <valid>
294
295 <AAA>
296 <CCC/>
297 <CCC/>
298 <BBB>
299 <CCC id="Q1"/>
300 </BBB>
301 </AAA>
302 </valid>
303 <invalid>
304
305 <AAA>
306 <CCC id="Q2"/>
307 <CCC/>
308 <BBB>
309 <CCC id="Q1"/>
310 </BBB>
311 </AAA>
312 </invalid>
313 <invalid>
314
315 <AAA>
316 <CCC/>
317 <CCC/>
318 <BBB>
319 <CCC/>
320 </BBB>
321 </AAA>
322 </invalid>
323 </testCase>
324 <testCase>
325 <correct>
326 <schema xmlns="http://www.ascc.net/xml/schematron">
327 <pattern name="Character @ forbidden">
328 <rule context="*">
329 <report test="contains(.,'@')">Text in element <name/> must not contain character @</report>
330 </rule>
331 </pattern>
332 </schema></correct>
333 <valid>
334
335 <AAA>
336 <BBB>bbbb</BBB>
337 <CCC>cccc</CCC>
338 </AAA>
339 </valid>
340 <invalid>
341
342 <AAA>
343 <BBB>[email protected]</BBB>
344 <CCC>[email protected]</CCC>
345 </AAA>
346 </invalid>
347 <invalid>
348
349 <AAA>
350 <BBB>bbbb</BBB>
351 <CCC>cccc</CCC>
352 [email protected]
353 </AAA>
354 </invalid>
355 </testCase>
356 <testCase>
357 <correct>
358 <schema xmlns="http://www.ascc.net/xml/schematron">
359 <pattern name="Attributes present">
360 <rule context="BBB">
361 <assert test="not(@aaa) or (@aaa and @bbb)">The element must not have an isolated aaa attribute</assert>
362 <assert test="not(@bbb) or (@aaa and @bbb)">The element must not have an isolated bbb attribute</assert>
363 </rule>
364 </pattern>
365 </schema></correct>
366 <valid>
367
368 <AAA>
369 <BBB aaa="A" bbb="B"/>
370 </AAA>
371 </valid>
372 <invalid>
373
374 <AAA>
375 <BBB bbb="B"/>
376 </AAA>
377 </invalid>
378 <invalid>
379
380 <AAA>
381 <BBB aaa="A"/>
382 </AAA>
383 </invalid>
384 <valid>
385
386 <AAA>
387 <BBB/>
388 </AAA>
389 </valid>
390 </testCase>
391 <testCase>
392 <correct>
393 <schema xmlns="http://www.ascc.net/xml/schematron">
394 <pattern name="Number of characters in an abbreviation">
395 <rule context="BBB">
396 <report test="string-length(@bbb) &lt; 2">There is not enough letters in the abbreviation</report>
397 <report test="string-length(@bbb) &gt; 3">There is too much letters in the abbreviation</report>
398 </rule>
399 </pattern>
400 </schema></correct>
401 <invalid>
402
403 <AAA>
404 <BBB bbb="C"/>
405 </AAA>
406 </invalid>
407 <valid>
408
409 <AAA>
410 <BBB bbb="CZ"/>
411 </AAA>
412 </valid>
413 <invalid>
414
415 <AAA>
416 <BBB bbb="CZCZ"/>
417 </AAA>
418 </invalid>
419 </testCase>
420 <testCase>
421 <correct>
422 <schema xmlns="http://www.ascc.net/xml/schematron">
423 <pattern name="Sum equals 100%.">
424 <rule context="Total">
425 <assert test="sum(//Percent) = 100">The values do not sum to 100%. </assert>
426 </rule>
427 </pattern>
428 </schema></correct>
429 <invalid>
430
431 <Total>
432 <Percent>20</Percent>
433 <Percent>30</Percent>
434 <Percent>10</Percent>
435 <Percent>50</Percent>
436 </Total>
437 </invalid>
438 <invalid>
439
440 <Total>
441 <Percent>20</Percent>
442 <Percent>10</Percent>
443 <Percent>50</Percent>
444 </Total>
445 </invalid>
446 <valid>
447
448 <Total>
449 <Percent>20</Percent>
450 <Percent>30</Percent>
451 <Percent>50</Percent>
452 </Total>
453 </valid>
454 </testCase>
455 <testCase>
456 <correct>
457 <schema xmlns="http://www.ascc.net/xml/schematron">
458 <pattern name="a child of selected elements">
459 <rule context="CCC">
460 <assert test="parent::*[name()='BBB' or name()='DDD']">Element CCC must not be a child of element <name path="parent::*"/> </assert>
461 </rule>
462 </pattern>
463 </schema></correct>
464 <invalid>
465
466 <AAA>
467 <BBB>
468 <CCC/>
469 </BBB>
470 <CCC/>
471 <DDD>
472 <CCC/>
473 <EEE>
474 <CCC/>
475 </EEE>
476 </DDD>
477 </AAA>
478 </invalid>
479 </testCase>
480 <testCase>
481 <correct>
482 <schema xmlns="http://www.ascc.net/xml/schematron">
483 <pattern name="id is the only permited attribute name">
484 <rule context="*">
485 <report test="@*[not(name()='id')]">Atrribute <name path="@*[not(name()='id')]"/> is forbidden in element <name/> </report>
486 </rule>
487 </pattern>
488 </schema></correct>
489 <invalid>
490
491 <AAA name="aaa">
492 <BBB id="bbb"/>
493 <CCC color="ccc"/>
494 </AAA>
495 </invalid>
496 </testCase>
497 <testCase>
498 <correct>
499 <schema xmlns="http://www.ascc.net/xml/schematron">
500 <pattern name="Required ID">
501 <rule context="cat | dog">
502 <assert test="@id">An element of type <name/> should have an id attribute that is a unique identifier for that animal.</assert>
503 </rule>
504 </pattern>
505
506 <pattern name="Required IDREF">
507 <rule context="catowner">
508 <assert test="@pet">An element of type <name/> should have a pet attribute.</assert>
509 </rule>
510 </pattern>
511
512 <pattern name="IDREF should reference an ID used in the same document">
513 <rule context="catowner[@pet]">
514 <assert test="id(@pet)">An element of type <name/> should have a pet attribute that should contain a unique identifier.</assert>
515 </rule>
516 </pattern>
517
518 <pattern name="IDREF should reference an ID of a certain element type only">
519 <rule context="catowner[@pet]">
520 <assert test="(name(id(@pet)) ='cat')">An element of type <name/> should have a pet attribute that should contain the unique identifier for a cat.</assert>
521 </rule>
522 </pattern>
523 </schema></correct>
524 <invalid dtd="
525 &lt;!DOCTYPE ideg
526 [
527 &lt;!ELEMENT ideg ( dog, cat, catowner+ )>
528 &lt;!ELEMENT dog ( #PCDATA )>
529 &lt;!ELEMENT cat ( #PCDATA )>
530 &lt;!ELEMENT catowner ( #PCDATA )>
531 &lt;!ATTLIST dog id ID #REQUIRED >
532 &lt;!ATTLIST cat id ID #REQUIRED >
533 &lt;!ATTLIST catowner pet IDREF #REQUIRED>
534 ]>">
535 <ideg>
536 <dog id="danny" >Danny</dog>
537 <cat id="bede" >Bede</cat>
538 <catowner >Harold</catowner>
539 <catowner pet="poochi" >Fumiaki</catowner>
540 <catowner pet="danny" >Jimmy</catowner>
541 <catowner pet="bede" >Rick</catowner>
542 </ideg>
543
544 </invalid>
545 </testCase>
546 <testCase>
547 <resource name="source1.xml">
548
549 <list>
550 <author id="a1">Alice</author>
551 <author id="p1">Paul</author>
552 <author id="p2">Peter</author>
553 </list>
554 </resource>
555 <correct>
556 <schema xmlns="http://www.ascc.net/xml/schematron">
557 <pattern name="Compare with the database">
558 <rule context="author">
559 <assert test="document('source1.xml')//author[@id=current()/@id]">The author is not in the database </assert>
560 </rule>
561 </pattern>
562
563 </schema></correct>
564 <invalid>
565
566 <list>
567 <author id="a1"/>
568 <author id="a2"/>
569 <author id="p1"/>
570 <author id="p2"/>
571 </list>
572 </invalid>
573 </testCase>
574 <testCase>
575 <resource name="source1.xml">
576 <list>
577 <Alice/>
578 <Peter/>
579 <Paul/>
580 </list>
581 </resource>
582 <correct>
583 <schema xmlns="http://www.ascc.net/xml/schematron">
584 <pattern name="Start of paragraph restriction.">
585 <rule context="p">
586 <assert test="document('source1.xml')//*[name()=substring-before(current(),' ')]">The word at the beginning of sentence is not listed in XML 1.</assert>
587 </rule>
588 </pattern>
589
590 </schema></correct>
591
592 <invalid>
593
594 <Document>
595 <p>Alice is a nice girl.</p>
596 <p>Where is Peter.</p>
597 <p>Paul was invited.</p>
598 <p>But Paul did not come.</p>
599 </Document>
600 </invalid>
601 </testCase>
602 <testCase>
603 <incorrect>
604 <schema xmlns="http://www.ascc.net/xml/schematron">
605 <pattern name="foo">
606 <rule context="foo bar">
607 <assert test="whatever">xxx</assert>
608 </rule>
609 </pattern>
610 </schema>
611 </incorrect>
612 </testCase>
613 <testCase>
614 <incorrect>
615 <schema xmlns="http://www.ascc.net/xml/schematron">
616 <!-- pattern is missing the name attribute: should just get validation messages -->
617 <pattern>
618 <rule context="foo bar">
619 <assert test="whatever">xxx</assert>
620 </rule>
621 </pattern>
622 </schema>
623 </incorrect>
624 </testCase>
625 </testSuite>