You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

588 lines
20 KiB

4 years ago
  1. <?xml version="1.0" ?>
  2. <!--
  3. ISO_SVRL.xsl
  4. Implementation of Schematron Validation Report Language from ISO Schematron
  5. ISO/IEC 19757 Document Schema Definition Languages (DSDL)
  6. Part 3: Rule-based validation Schematron
  7. Annex D: Schematron Validation Report Language
  8. This ISO Standard is available free as a Publicly Available Specification in PDF from ISO.
  9. Also see www.schematron.com for drafts and other information.
  10. This implementation of SVRL is designed to run with the "Skeleton" implementation
  11. of Schematron which Oliver Becker devised. The skeleton code provides a
  12. Schematron implementation but with named templates for handling all output;
  13. the skeleton provides basic templates for output using this API, but client
  14. validators can be written to import the skeleton and override the default output
  15. templates as required. (In order to understand this, you must understand that
  16. a named template such as "process-assert" in this XSLT stylesheet overrides and
  17. replaces any template with the same name in the imported skeleton XSLT file.)
  18. The other important thing to understand in this code is that there are different
  19. versions of the Schematron skeleton. These track the development of Schematron through
  20. Schematron 1.5, Schematron 1.6 and now ISO Schematron. One only skeleton must be
  21. imported. The code has templates for the different skeletons commented out for
  22. convenience. ISO Schematron has a different namespace than Schematron 1.5 and 1.6;
  23. so the ISO Schematron skeleton has been written itself with an optional import
  24. statement to in turn import the Schematron 1.6 skeleton. This will allow you to
  25. validate with schemas from either namespace.
  26. History:
  27. 2009-03-18
  28. * Fix atrribute with space "see " which generates wrong name in some processors
  29. 2008-08-11
  30. * RJ Fix attribute/@select which saxon allows in XSLT 1
  31. 2008-08-07
  32. * RJ Add output-encoding attribute to specify final encoding to use
  33. * Alter allow-foreign functionality so that Schematron span, emph and dir elements make
  34. it to the output, for better formatting and because span can be used to mark up
  35. semantically interesting information embedded in diagnostics, which reduces the
  36. need to extend SVRL itself
  37. * Diagnostic-reference had an invalid attribute @id that duplicated @diagnostic: removed
  38. 2008-08-06
  39. * RJ Fix invalid output: svrl:diagnostic-reference is not contained in an svrl:text
  40. * Output comment to SVRL file giving filename if available (from command-line parameter)
  41. 2008-08-04
  42. * RJ move sch: prefix to schold: prefix to prevent confusion (we want people to
  43. be able to switch from old namespace to new namespace without changing the
  44. sch: prefix, so it is better to keep that prefix completely out of the XSLT)
  45. * Extra signature fixes (PH)
  46. 2008-08-03
  47. * Repair missing class parameter on process-p
  48. 2008-07-31
  49. * Update skeleton names
  50. 2007-04-03
  51. * Add option generate-fired-rule (RG)
  52. 2007-02-07
  53. * Prefer true|false for parameters. But allow yes|no on some old for compatability
  54. * DP Diagnostics output to svrl:text. Diagnosis put out after assertion text.
  55. * Removed non-SVRL elements and attributes: better handled as an extra layer that invokes this one
  56. * Add more formal parameters
  57. * Correct confusion between $schemaVersion and $queryBinding
  58. * Indent
  59. * Validate against RNC schemas for XSLT 1 and 2 (with regex tests removed)
  60. * Validate output with UniversalTest.sch against RNC schema for ISO SVRL
  61. 2007-02-01
  62. * DP. Update formal parameters of overriding named templates to handle more attributes.
  63. * DP. Refactor handling of rich and linkable parameters to a named template.
  64. 2007-01-22
  65. * DP change svrl:ns to svrl:ns-in-attribute-value
  66. * Change default when no queryBinding from "unknown" to "xslt"
  67. 2007-01-18:
  68. * Improve documentation
  69. * KH Add command-line options to generate paths or not
  70. * Use axsl:attribute rather than xsl:attribute to shut XSLT2 up
  71. * Add extra command-line options to pass to the iso_schematron_skeleton
  72. 2006-12-01: iso_svrl.xsl Rick Jelliffe,
  73. * update namespace,
  74. * update phase handling,
  75. * add flag param to process-assert and process-report & @ flag on output
  76. 2001: Conformance1-5.xsl Rick Jelliffe,
  77. * Created, using the skeleton code contributed by Oliver Becker
  78. -->
  79. <!--
  80. Derived from Conformance1-5.xsl.
  81. Copyright (c) 2001, 2006 Rick Jelliffe and Academia Sinica Computing Center, Taiwan
  82. This software is provided 'as-is', without any express or implied warranty.
  83. In no event will the authors be held liable for any damages arising from
  84. the use of this software.
  85. Permission is granted to anyone to use this software for any purpose,
  86. including commercial applications, and to alter it and redistribute it freely,
  87. subject to the following restrictions:
  88. 1. The origin of this software must not be misrepresented; you must not claim
  89. that you wrote the original software. If you use this software in a product,
  90. an acknowledgment in the product documentation would be appreciated but is
  91. not required.
  92. 2. Altered source versions must be plainly marked as such, and must not be
  93. misrepresented as being the original software.
  94. 3. This notice may not be removed or altered from any source distribution.
  95. -->
  96. <!-- Ideas nabbed from schematrons by Francis N., Miloslav N. and David C. -->
  97. <!-- The command-line parameters are:
  98. phase NMTOKEN | "#ALL" (default) Select the phase for validation
  99. allow-foreign "true" | "false" (default) Pass non-Schematron elements and rich markup to the generated stylesheet
  100. diagnose= true | false|yes|no Add the diagnostics to the assertion test in reports (yes|no are obsolete)
  101. generate-paths=true|false|yes|no generate the @location attribute with XPaths (yes|no are obsolete)
  102. sch.exslt.imports semi-colon delimited string of filenames for some EXSLT implementations
  103. optimize "visit-no-attributes" Use only when the schema has no attributes as the context nodes
  104. generate-fired-rule "true"(default) | "false" Generate fired-rule elements
  105. -->
  106. <xsl:stylesheet
  107. version="1.0"
  108. xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
  109. xmlns:xs="http://www.w3.org/2001/XMLSchema"
  110. xmlns:axsl="http://www.w3.org/1999/XSL/TransformAlias"
  111. xmlns:schold="http://www.ascc.net/xml/schematron"
  112. xmlns:iso="http://purl.oclc.org/dsdl/schematron"
  113. xmlns:svrl="http://purl.oclc.org/dsdl/svrl"
  114. >
  115. <!-- Select the import statement and adjust the path as
  116. necessary for your system.
  117. If not XSLT2 then also remove svrl:active-pattern/@document="{document-uri()}" from process-pattern()
  118. -->
  119. <!--
  120. <xsl:import href="iso_schematron_skeleton_for_saxon.xsl"/>
  121. -->
  122. <xsl:import href="iso_schematron_skeleton_for_xslt1.xsl"/>
  123. <!--
  124. <xsl:import href="iso_schematron_skeleton.xsl"/>
  125. <xsl:import href="skeleton1-5.xsl"/>
  126. <xsl:import href="skeleton1-6.xsl"/>
  127. -->
  128. <xsl:param name="diagnose" >true</xsl:param>
  129. <xsl:param name="phase" >
  130. <xsl:choose>
  131. <!-- Handle Schematron 1.5 and 1.6 phases -->
  132. <xsl:when test="//schold:schema/@defaultPhase">
  133. <xsl:value-of select="//schold:schema/@defaultPhase"/>
  134. </xsl:when>
  135. <!-- Handle ISO Schematron phases -->
  136. <xsl:when test="//iso:schema/@defaultPhase">
  137. <xsl:value-of select="//iso:schema/@defaultPhase"/>
  138. </xsl:when>
  139. <xsl:otherwise>#ALL</xsl:otherwise>
  140. </xsl:choose>
  141. </xsl:param>
  142. <xsl:param name="allow-foreign" >false</xsl:param>
  143. <xsl:param name="generate-paths" >true</xsl:param>
  144. <xsl:param name="generate-fired-rule" >true</xsl:param>
  145. <xsl:param name="optimize"/>
  146. <xsl:param name="output-encoding" ></xsl:param>
  147. <!-- e.g. saxon file.xml file.xsl "sch.exslt.imports=.../string.xsl;.../math.xsl" -->
  148. <xsl:param name="sch.exslt.imports" />
  149. <!-- Experimental: If this file called, then must be generating svrl -->
  150. <xsl:variable name="svrlTest" select="true()" />
  151. <!-- ================================================================ -->
  152. <xsl:template name="process-prolog">
  153. <axsl:output method="xml" omit-xml-declaration="no" standalone="yes"
  154. indent="yes">
  155. <xsl:if test=" string-length($output-encoding) &gt; 0">
  156. <xsl:attribute name="encoding"><xsl:value-of select=" $output-encoding" /></xsl:attribute>
  157. </xsl:if>
  158. </axsl:output>
  159. </xsl:template>
  160. <!-- Overrides skeleton.xsl -->
  161. <xsl:template name="process-root">
  162. <xsl:param name="title"/>
  163. <xsl:param name="contents" />
  164. <xsl:param name="queryBinding" >xslt1</xsl:param>
  165. <xsl:param name="schemaVersion" />
  166. <xsl:param name="id" />
  167. <xsl:param name="version"/>
  168. <!-- "Rich" parameters -->
  169. <xsl:param name="fpi" />
  170. <xsl:param name="icon" />
  171. <xsl:param name="lang" />
  172. <xsl:param name="see" />
  173. <xsl:param name="space" />
  174. <svrl:schematron-output title="{$title}" schemaVersion="{$schemaVersion}" >
  175. <xsl:if test=" string-length( normalize-space( $phase )) &gt; 0 and
  176. not( normalize-space( $phase ) = '#ALL') ">
  177. <axsl:attribute name="phase">
  178. <xsl:value-of select=" $phase " />
  179. </axsl:attribute>
  180. </xsl:if>
  181. <xsl:if test=" $allow-foreign = 'true'">
  182. </xsl:if>
  183. <xsl:if test=" $allow-foreign = 'true'">
  184. <xsl:call-template name='richParms'>
  185. <xsl:with-param name="fpi" select="$fpi" />
  186. <xsl:with-param name="icon" select="$icon"/>
  187. <xsl:with-param name="lang" select="$lang"/>
  188. <xsl:with-param name="see" select="$see" />
  189. <xsl:with-param name="space" select="$space" />
  190. </xsl:call-template>
  191. </xsl:if>
  192. <axsl:comment><axsl:value-of select="$archiveDirParameter"/> &#xA0;
  193. <axsl:value-of select="$archiveNameParameter"/> &#xA0;
  194. <axsl:value-of select="$fileNameParameter"/> &#xA0;
  195. <axsl:value-of select="$fileDirParameter"/></axsl:comment>
  196. <xsl:apply-templates mode="do-schema-p" />
  197. <xsl:copy-of select="$contents" />
  198. </svrl:schematron-output>
  199. </xsl:template>
  200. <xsl:template name="process-assert">
  201. <xsl:param name="test"/>
  202. <xsl:param name="diagnostics" />
  203. <xsl:param name="id" />
  204. <xsl:param name="flag" />
  205. <!-- "Linkable" parameters -->
  206. <xsl:param name="role"/>
  207. <xsl:param name="subject"/>
  208. <!-- "Rich" parameters -->
  209. <xsl:param name="fpi" />
  210. <xsl:param name="icon" />
  211. <xsl:param name="lang" />
  212. <xsl:param name="see" />
  213. <xsl:param name="space" />
  214. <svrl:failed-assert test="{$test}" >
  215. <xsl:if test="string-length( $id ) &gt; 0">
  216. <axsl:attribute name="id">
  217. <xsl:value-of select=" $id " />
  218. </axsl:attribute>
  219. </xsl:if>
  220. <xsl:if test=" string-length( $flag ) &gt; 0">
  221. <axsl:attribute name="flag">
  222. <xsl:value-of select=" $flag " />
  223. </axsl:attribute>
  224. </xsl:if>
  225. <!-- Process rich attributes. -->
  226. <xsl:call-template name="richParms">
  227. <xsl:with-param name="fpi" select="$fpi"/>
  228. <xsl:with-param name="icon" select="$icon"/>
  229. <xsl:with-param name="lang" select="$lang"/>
  230. <xsl:with-param name="see" select="$see" />
  231. <xsl:with-param name="space" select="$space" />
  232. </xsl:call-template>
  233. <xsl:call-template name='linkableParms'>
  234. <xsl:with-param name="role" select="$role" />
  235. <xsl:with-param name="subject" select="$subject"/>
  236. </xsl:call-template>
  237. <xsl:if test=" $generate-paths = 'true' or $generate-paths= 'yes' ">
  238. <!-- true/false is the new way -->
  239. <axsl:attribute name="location">
  240. <axsl:apply-templates select="." mode="schematron-get-full-path"/>
  241. </axsl:attribute>
  242. </xsl:if>
  243. <svrl:text>
  244. <xsl:apply-templates mode="text" />
  245. </svrl:text>
  246. <xsl:if test="$diagnose = 'yes' or $diagnose= 'true' ">
  247. <!-- true/false is the new way -->
  248. <xsl:call-template name="diagnosticsSplit">
  249. <xsl:with-param name="str" select="$diagnostics"/>
  250. </xsl:call-template>
  251. </xsl:if>
  252. </svrl:failed-assert>
  253. </xsl:template>
  254. <xsl:template name="process-report">
  255. <xsl:param name="id"/>
  256. <xsl:param name="test"/>
  257. <xsl:param name="diagnostics"/>
  258. <xsl:param name="flag" />
  259. <!-- "Linkable" parameters -->
  260. <xsl:param name="role"/>
  261. <xsl:param name="subject"/>
  262. <!-- "Rich" parameters -->
  263. <xsl:param name="fpi" />
  264. <xsl:param name="icon" />
  265. <xsl:param name="lang" />
  266. <xsl:param name="see" />
  267. <xsl:param name="space" />
  268. <svrl:successful-report test="{$test}" >
  269. <xsl:if test=" string-length( $id ) &gt; 0">
  270. <axsl:attribute name="id">
  271. <xsl:value-of select=" $id " />
  272. </axsl:attribute>
  273. </xsl:if>
  274. <xsl:if test=" string-length( $flag ) &gt; 0">
  275. <axsl:attribute name="flag">
  276. <xsl:value-of select=" $flag " />
  277. </axsl:attribute>
  278. </xsl:if>
  279. <!-- Process rich attributes. -->
  280. <xsl:call-template name="richParms">
  281. <xsl:with-param name="fpi" select="$fpi"/>
  282. <xsl:with-param name="icon" select="$icon"/>
  283. <xsl:with-param name="lang" select="$lang"/>
  284. <xsl:with-param name="see" select="$see" />
  285. <xsl:with-param name="space" select="$space" />
  286. </xsl:call-template>
  287. <xsl:call-template name='linkableParms'>
  288. <xsl:with-param name="role" select="$role" />
  289. <xsl:with-param name="subject" select="$subject"/>
  290. </xsl:call-template>
  291. <xsl:if test=" $generate-paths = 'yes' or $generate-paths = 'true' ">
  292. <!-- true/false is the new way -->
  293. <axsl:attribute name="location">
  294. <axsl:apply-templates select="." mode="schematron-get-full-path"/>
  295. </axsl:attribute>
  296. </xsl:if>
  297. <svrl:text>
  298. <xsl:apply-templates mode="text" />
  299. </svrl:text>
  300. <xsl:if test="$diagnose = 'yes' or $diagnose='true' ">
  301. <!-- true/false is the new way -->
  302. <xsl:call-template name="diagnosticsSplit">
  303. <xsl:with-param name="str" select="$diagnostics"/>
  304. </xsl:call-template>
  305. </xsl:if>
  306. </svrl:successful-report>
  307. </xsl:template>
  308. <!-- Overrides skeleton -->
  309. <xsl:template name="process-dir" >
  310. <xsl:param name="value" />
  311. <xsl:choose>
  312. <xsl:when test=" $allow-foreign = 'true'">
  313. <xsl:copy-of select="."/>
  314. </xsl:when>
  315. <xsl:otherwise>
  316. <!-- We generate too much whitespace rather than risking concatenation -->
  317. <axsl:text> </axsl:text>
  318. <xsl:apply-templates mode="inline-text"/>
  319. <axsl:text> </axsl:text>
  320. </xsl:otherwise>
  321. </xsl:choose>
  322. </xsl:template>
  323. <xsl:template name="process-diagnostic">
  324. <xsl:param name="id"/>
  325. <!-- Rich parameters -->
  326. <xsl:param name="fpi" />
  327. <xsl:param name="icon" />
  328. <xsl:param name="lang" />
  329. <xsl:param name="see" />
  330. <xsl:param name="space" />
  331. <svrl:diagnostic-reference diagnostic="{$id}" >
  332. <xsl:call-template name="richParms">
  333. <xsl:with-param name="fpi" select="$fpi"/>
  334. <xsl:with-param name="icon" select="$icon"/>
  335. <xsl:with-param name="lang" select="$lang"/>
  336. <xsl:with-param name="see" select="$see" />
  337. <xsl:with-param name="space" select="$space" />
  338. </xsl:call-template>
  339. <xsl:text>
  340. </xsl:text>
  341. <xsl:apply-templates mode="text"/>
  342. </svrl:diagnostic-reference>
  343. </xsl:template>
  344. <!-- Overrides skeleton -->
  345. <xsl:template name="process-emph" >
  346. <xsl:param name="class" />
  347. <xsl:choose>
  348. <xsl:when test=" $allow-foreign = 'true'">
  349. <xsl:copy-of select="."/>
  350. </xsl:when>
  351. <xsl:otherwise>
  352. <!-- We generate too much whitespace rather than risking concatenation -->
  353. <axsl:text> </axsl:text>
  354. <xsl:apply-templates mode="inline-text"/>
  355. <axsl:text> </axsl:text>
  356. </xsl:otherwise>
  357. </xsl:choose>
  358. </xsl:template>
  359. <xsl:template name="process-rule">
  360. <xsl:param name="id"/>
  361. <xsl:param name="context"/>
  362. <xsl:param name="flag"/>
  363. <!-- "Linkable" parameters -->
  364. <xsl:param name="role"/>
  365. <xsl:param name="subject"/>
  366. <!-- "Rich" parameters -->
  367. <xsl:param name="fpi" />
  368. <xsl:param name="icon" />
  369. <xsl:param name="lang" />
  370. <xsl:param name="see" />
  371. <xsl:param name="space" />
  372. <xsl:if test=" $generate-fired-rule = 'true'">
  373. <svrl:fired-rule context="{$context}" >
  374. <!-- Process rich attributes. -->
  375. <xsl:call-template name="richParms">
  376. <xsl:with-param name="fpi" select="$fpi"/>
  377. <xsl:with-param name="icon" select="$icon"/>
  378. <xsl:with-param name="lang" select="$lang"/>
  379. <xsl:with-param name="see" select="$see" />
  380. <xsl:with-param name="space" select="$space" />
  381. </xsl:call-template>
  382. <xsl:if test=" string( $id )">
  383. <xsl:attribute name="id">
  384. <xsl:value-of select=" $id " />
  385. </xsl:attribute>
  386. </xsl:if>
  387. <xsl:if test=" string-length( $role ) &gt; 0">
  388. <xsl:attribute name="role">
  389. <xsl:value-of select=" $role " />
  390. </xsl:attribute>
  391. </xsl:if>
  392. </svrl:fired-rule>
  393. </xsl:if>
  394. </xsl:template>
  395. <xsl:template name="process-ns">
  396. <xsl:param name="prefix"/>
  397. <xsl:param name="uri"/>
  398. <svrl:ns-prefix-in-attribute-values uri="{$uri}" prefix="{$prefix}" />
  399. </xsl:template>
  400. <xsl:template name="process-p">
  401. <xsl:param name="icon"/>
  402. <xsl:param name="class"/>
  403. <xsl:param name="id"/>
  404. <xsl:param name="lang"/>
  405. <svrl:text>
  406. <xsl:apply-templates mode="text"/>
  407. </svrl:text>
  408. </xsl:template>
  409. <xsl:template name="process-pattern">
  410. <xsl:param name="name"/>
  411. <xsl:param name="id"/>
  412. <xsl:param name="is-a"/>
  413. <!-- "Rich" parameters -->
  414. <xsl:param name="fpi" />
  415. <xsl:param name="icon" />
  416. <xsl:param name="lang" />
  417. <xsl:param name="see" />
  418. <xsl:param name="space" />
  419. <svrl:active-pattern >
  420. <xsl:if test=" string( $id )">
  421. <axsl:attribute name="id">
  422. <xsl:value-of select=" $id " />
  423. </axsl:attribute>
  424. </xsl:if>
  425. <xsl:if test=" string( $name )">
  426. <axsl:attribute name="name">
  427. <xsl:value-of select=" $name " />
  428. </axsl:attribute>
  429. </xsl:if>
  430. <xsl:call-template name='richParms'>
  431. <xsl:with-param name="fpi" select="$fpi"/>
  432. <xsl:with-param name="icon" select="$icon"/>
  433. <xsl:with-param name="lang" select="$lang"/>
  434. <xsl:with-param name="see" select="$see" />
  435. <xsl:with-param name="space" select="$space" />
  436. </xsl:call-template>
  437. <!-- ?? report that this screws up iso:title processing -->
  438. <xsl:apply-templates mode="do-pattern-p"/>
  439. <!-- ?? Seems that this apply-templates is never triggered DP -->
  440. <axsl:apply-templates />
  441. </svrl:active-pattern>
  442. </xsl:template>
  443. <!-- Overrides skeleton -->
  444. <xsl:template name="process-message" >
  445. <xsl:param name="pattern"/>
  446. <xsl:param name="role"/>
  447. </xsl:template>
  448. <!-- Overrides skeleton -->
  449. <xsl:template name="process-span" >
  450. <xsl:param name="class" />
  451. <xsl:choose>
  452. <xsl:when test=" $allow-foreign = 'true'">
  453. <xsl:copy-of select="."/>
  454. </xsl:when>
  455. <xsl:otherwise>
  456. <!-- We generate too much whitespace rather than risking concatenation -->
  457. <axsl:text> </axsl:text>
  458. <xsl:apply-templates mode="inline-text"/>
  459. <axsl:text> </axsl:text>
  460. </xsl:otherwise>
  461. </xsl:choose>
  462. </xsl:template>
  463. <!-- =========================================================================== -->
  464. <!-- processing rich parameters. -->
  465. <xsl:template name='richParms'>
  466. <!-- "Rich" parameters -->
  467. <xsl:param name="fpi" />
  468. <xsl:param name="icon" />
  469. <xsl:param name="lang" />
  470. <xsl:param name="see" />
  471. <xsl:param name="space" />
  472. <!-- Process rich attributes. -->
  473. <xsl:if test=" $allow-foreign = 'true'">
  474. <xsl:if test="string($fpi)">
  475. <axsl:attribute name="fpi">
  476. <xsl:value-of select="$fpi"/>
  477. </axsl:attribute>
  478. </xsl:if>
  479. <xsl:if test="string($icon)">
  480. <axsl:attribute name="icon">
  481. <xsl:value-of select="$icon"/>
  482. </axsl:attribute>
  483. </xsl:if>
  484. <xsl:if test="string($see)">
  485. <axsl:attribute name="see">
  486. <xsl:value-of select="$see"/>
  487. </axsl:attribute>
  488. </xsl:if>
  489. </xsl:if>
  490. <xsl:if test="string($space)">
  491. <axsl:attribute name="xml:space">
  492. <xsl:value-of select="$space"/>
  493. </axsl:attribute>
  494. </xsl:if>
  495. <xsl:if test="string($lang)">
  496. <axsl:attribute name="xml:lang">
  497. <xsl:value-of select="$lang"/>
  498. </axsl:attribute>
  499. </xsl:if>
  500. </xsl:template>
  501. <!-- processing linkable parameters. -->
  502. <xsl:template name='linkableParms'>
  503. <xsl:param name="role"/>
  504. <xsl:param name="subject"/>
  505. <!-- ISO SVRL has a role attribute to match the Schematron role attribute -->
  506. <xsl:if test=" string($role )">
  507. <axsl:attribute name="role">
  508. <xsl:value-of select=" $role " />
  509. </axsl:attribute>
  510. </xsl:if>
  511. <!-- ISO SVRL does not have a subject attribute to match the Schematron subject attribute.
  512. Instead, the Schematron subject attribute is folded into the location attribute -->
  513. </xsl:template>
  514. </xsl:stylesheet>