health-data-standards 3.5.3 → 3.6.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (140) hide show
  1. checksums.yaml +4 -4
  2. data/Gemfile +2 -3
  3. data/README.md +10 -2
  4. data/lib/health-data-standards.rb +5 -28
  5. data/lib/health-data-standards/export/cat_1.rb +3 -2
  6. data/lib/health-data-standards/export/cat_1_r2.rb +11 -0
  7. data/lib/health-data-standards/ext/node.rb +1 -2
  8. data/lib/health-data-standards/import/bulk_record_importer.rb +4 -4
  9. data/lib/health-data-standards/import/bundle/importer.rb +62 -0
  10. data/lib/health-data-standards/import/c32/insurance_provider_importer.rb +10 -8
  11. data/lib/health-data-standards/import/cat1/patient_importer.rb +3 -3
  12. data/lib/health-data-standards/import/cat1/procedure_importer.rb +42 -0
  13. data/lib/health-data-standards/import/cda/medication_importer.rb +11 -11
  14. data/lib/health-data-standards/import/cda/section_importer.rb +13 -7
  15. data/lib/health-data-standards/models/cqm/aggregate_objects.rb +5 -1
  16. data/lib/health-data-standards/models/cqm/bundle.rb +5 -3
  17. data/lib/health-data-standards/models/cqm/measure.rb +1 -1
  18. data/lib/health-data-standards/models/entry.rb +5 -1
  19. data/lib/health-data-standards/models/record.rb +10 -0
  20. data/lib/health-data-standards/models/reference.rb +23 -0
  21. data/lib/health-data-standards/models/svs/value_set.rb +4 -3
  22. data/lib/health-data-standards/railtie.rb +1 -1
  23. data/lib/health-data-standards/tasks.rb +1 -0
  24. data/lib/health-data-standards/tasks/bundle.rake +84 -2
  25. data/lib/health-data-standards/util/vs_api.rb +40 -7
  26. data/lib/health-data-standards/validate/base_validator.rb +23 -0
  27. data/lib/health-data-standards/validate/data_validator.rb +85 -0
  28. data/lib/health-data-standards/validate/measure_validator.rb +127 -0
  29. data/lib/health-data-standards/validate/performance_rate_validator.rb +94 -0
  30. data/lib/health-data-standards/validate/reported_result_extractor.rb +170 -0
  31. data/lib/health-data-standards/validate/schema_validator.rb +24 -0
  32. data/lib/health-data-standards/validate/schematron/c_processor.rb +28 -0
  33. data/lib/health-data-standards/validate/schematron/java_processor.rb +93 -0
  34. data/lib/health-data-standards/validate/schematron_validator.rb +34 -0
  35. data/lib/health-data-standards/validate/validation_error.rb +10 -0
  36. data/lib/health-data-standards/validate/validators.rb +80 -0
  37. data/lib/hqmf-generator/fulfills.xml.erb +7 -0
  38. data/lib/hqmf-generator/hqmf-generator.rb +8 -3
  39. data/lib/hqmf-model/data_criteria.rb +3 -0
  40. data/lib/hqmf-model/types.rb +29 -0
  41. data/lib/hqmf-parser/2.0/data_criteria.rb +7 -0
  42. data/lib/hqmf-parser/2.0/types.rb +24 -0
  43. data/resources/schema/infrastructure/cda/CDA_SDTC.xsd +44 -0
  44. data/resources/schema/infrastructure/cda/POCD_MT000040_SDTC.xsd +1500 -0
  45. data/resources/schema/infrastructure/cda/SDTC.xsd +210 -0
  46. data/resources/schema/processable/coreschemas/NarrativeBlock.xsd +557 -0
  47. data/resources/schema/processable/coreschemas/datatypes-base_SDTC.xsd +1850 -0
  48. data/resources/schema/processable/coreschemas/datatypes.xsd +1375 -0
  49. data/resources/schema/processable/coreschemas/infrastructureRoot.xsd +27 -0
  50. data/resources/schema/processable/coreschemas/voc.xsd +2124 -0
  51. data/resources/schematron/iso-schematron-xslt1/ExtractSchFromRNG.xsl +75 -0
  52. data/resources/schematron/iso-schematron-xslt1/ExtractSchFromXSD.xsl +77 -0
  53. data/resources/schematron/iso-schematron-xslt1/iso_abstract_expand.xsl +297 -0
  54. data/resources/schematron/iso-schematron-xslt1/iso_dsdl_include.xsl +1509 -0
  55. data/resources/schematron/iso-schematron-xslt1/iso_schematron_message.xsl +55 -0
  56. data/resources/schematron/iso-schematron-xslt1/iso_schematron_skeleton_for_xslt1.xsl +1844 -0
  57. data/resources/schematron/iso-schematron-xslt1/iso_svrl_for_xslt1.xsl +605 -0
  58. data/resources/schematron/iso-schematron-xslt1/readme.txt +101 -0
  59. data/resources/schematron/iso-schematron-xslt1/schematron-skeleton-api.htm +723 -0
  60. data/resources/schematron/iso-schematron-xslt2/ExtractSchFromRNG-2.xsl +75 -0
  61. data/resources/schematron/iso-schematron-xslt2/ExtractSchFromXSD-2.xsl +77 -0
  62. data/resources/schematron/iso-schematron-xslt2/iso_abstract_expand.xsl +297 -0
  63. data/resources/schematron/iso-schematron-xslt2/iso_dsdl_include.xsl +1508 -0
  64. data/resources/schematron/iso-schematron-xslt2/iso_schematron_message_xslt2.xsl +55 -0
  65. data/resources/schematron/iso-schematron-xslt2/iso_schematron_skeleton_for_saxon.xsl +2299 -0
  66. data/resources/schematron/iso-schematron-xslt2/iso_svrl_for_xslt2.xsl +684 -0
  67. data/resources/schematron/iso-schematron-xslt2/readme.txt +100 -0
  68. data/resources/schematron/iso-schematron-xslt2/sch-messages-cs.xhtml +56 -0
  69. data/resources/schematron/iso-schematron-xslt2/sch-messages-de.xhtml +57 -0
  70. data/resources/schematron/iso-schematron-xslt2/sch-messages-en.xhtml +57 -0
  71. data/resources/schematron/iso-schematron-xslt2/sch-messages-fr.xhtml +54 -0
  72. data/resources/schematron/iso-schematron-xslt2/sch-messages-nl.xhtml +58 -0
  73. data/resources/schematron/iso-schematron-xslt2/schematron-skeleton-api.htm +723 -0
  74. data/resources/schematron/qrda/cat_1/CDAR2_QRDA_I_R1_D3_2015MAY_Schematron.sch +4676 -0
  75. data/resources/schematron/qrda/cat_1/voc.xml +1177 -0
  76. data/resources/schematron/qrda/cat_1_r2/QRDA Category I Release 2.sch +4069 -0
  77. data/resources/schematron/qrda/cat_1_r2/voc.xml +1065 -0
  78. data/resources/schematron/qrda/cat_3/QRDA Category III.sch +675 -0
  79. data/resources/schematron/qrda/cat_3/voc.xml +21 -0
  80. data/templates/cat1/_2.16.840.1.113883.10.20.24.3.26.cat1.erb +18 -0
  81. data/templates/cat1/_2.16.840.1.113883.10.20.24.3.32.cat1.erb +4 -0
  82. data/templates/cat1/_2.16.840.1.113883.10.20.24.3.38.cat1.erb +5 -1
  83. data/templates/cat1/_2.16.840.1.113883.10.20.24.3.4.cat1.erb +1 -0
  84. data/templates/cat1/_2.16.840.1.113883.10.20.24.3.64.cat1.erb +20 -0
  85. data/templates/cat1/_fulfills.cat1.erb +14 -0
  86. data/templates/cat1/_organization.cat1.erb +2 -1
  87. data/templates/cat1/_patient_data.cat1.erb +1 -1
  88. data/templates/cat1/show.cat1.erb +5 -4
  89. data/templates/cat3/_performance_rate.cat3.erb +5 -1
  90. data/templates/cat3/show.cat3.erb +1 -1
  91. metadata +128 -109
  92. data/lib/health-data-standards/export/ccr.rb +0 -417
  93. data/lib/health-data-standards/export/green_c32/entry.rb +0 -18
  94. data/lib/health-data-standards/export/green_c32/export_generator.rb +0 -23
  95. data/lib/health-data-standards/export/green_c32/record.rb +0 -18
  96. data/lib/health-data-standards/export/helper/gc32_view_helper.rb +0 -39
  97. data/lib/health-data-standards/import/ccr/patient_importer.rb +0 -238
  98. data/lib/health-data-standards/import/ccr/product_importer.rb +0 -60
  99. data/lib/health-data-standards/import/ccr/provider_importer.rb +0 -49
  100. data/lib/health-data-standards/import/ccr/result_importer.rb +0 -49
  101. data/lib/health-data-standards/import/ccr/section_importer.rb +0 -135
  102. data/lib/health-data-standards/import/ccr/simple_importer.rb +0 -30
  103. data/lib/health-data-standards/import/green_c32/advance_directive_importer.rb +0 -14
  104. data/lib/health-data-standards/import/green_c32/allergy_importer.rb +0 -20
  105. data/lib/health-data-standards/import/green_c32/care_goal_importer.rb +0 -26
  106. data/lib/health-data-standards/import/green_c32/condition_importer.rb +0 -38
  107. data/lib/health-data-standards/import/green_c32/encounter_importer.rb +0 -33
  108. data/lib/health-data-standards/import/green_c32/immunization_importer.rb +0 -23
  109. data/lib/health-data-standards/import/green_c32/medical_equipment_importer.rb +0 -24
  110. data/lib/health-data-standards/import/green_c32/medication_importer.rb +0 -68
  111. data/lib/health-data-standards/import/green_c32/patient_importer.rb +0 -14
  112. data/lib/health-data-standards/import/green_c32/procedure_importer.rb +0 -27
  113. data/lib/health-data-standards/import/green_c32/result_importer.rb +0 -43
  114. data/lib/health-data-standards/import/green_c32/section_importer.rb +0 -186
  115. data/lib/health-data-standards/import/green_c32/social_history_importer.rb +0 -13
  116. data/lib/health-data-standards/import/green_c32/support_importer.rb +0 -22
  117. data/lib/health-data-standards/import/green_c32/vital_sign_importer.rb +0 -21
  118. data/templates/gc32/_address.gc32.erb +0 -9
  119. data/templates/gc32/_advance_directive.gc32.erb +0 -5
  120. data/templates/gc32/_allergy.gc32.erb +0 -12
  121. data/templates/gc32/_care_goal.gc32.erb +0 -8
  122. data/templates/gc32/_condition.gc32.erb +0 -10
  123. data/templates/gc32/_encounter.gc32.erb +0 -28
  124. data/templates/gc32/_entry.gc32.erb +0 -3
  125. data/templates/gc32/_entry_attributes.gc32.erb +0 -10
  126. data/templates/gc32/_immunization.gc32.erb +0 -9
  127. data/templates/gc32/_insurance_provider.gc32.erb +0 -28
  128. data/templates/gc32/_medical_equipment.gc32.erb +0 -6
  129. data/templates/gc32/_medication.gc32.erb +0 -91
  130. data/templates/gc32/_name.gc32.erb +0 -11
  131. data/templates/gc32/_organization.gc32.erb +0 -10
  132. data/templates/gc32/_person_attributes.gc32.erb +0 -7
  133. data/templates/gc32/_procedure.gc32.erb +0 -9
  134. data/templates/gc32/_provider.gc32.erb +0 -9
  135. data/templates/gc32/_result.gc32.erb +0 -12
  136. data/templates/gc32/_social_history.gc32.erb +0 -6
  137. data/templates/gc32/_support.gc32.erb +0 -15
  138. data/templates/gc32/_telecom.gc32.erb +0 -1
  139. data/templates/gc32/_vital_sign.gc32.erb +0 -4
  140. data/templates/gc32/record.gc32.erb +0 -97
@@ -0,0 +1,75 @@
1
+ <?xml version="1.0" encoding="UTF-8"?>
2
+ <!--
3
+ Stylesheet for extracting Schematron information from a RELAX-NG schema.
4
+ Based on the stylesheet for extracting Schematron information from W3C XML Schema.
5
+ Created by Eddie Robertsson 2002/06/01
6
+ Update for ISO Schematron Rick Jelliffe 2010/04/14
7
+ -->
8
+ <xsl:transform version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
9
+ xmlns:sch="http://purl.oclc.org/dsdl/schematron" xmlns:rng="http://relaxng.org/ns/structure/1.0">
10
+ <!-- Set the output to be XML with an XML declaration and use indentation -->
11
+ <xsl:output method="xml" omit-xml-declaration="no" indent="yes" standalone="yes"/>
12
+ <!-- -->
13
+ <!-- match schema and call recursive template to extract included schemas -->
14
+ <!-- -->
15
+ <xsl:template match="/rng:grammar | /rng:element">
16
+ <!-- call the schema definition template ... -->
17
+ <xsl:call-template name="gatherSchema">
18
+ <!-- ... with current node as the $schemas parameter ... -->
19
+ <xsl:with-param name="schemas" select="."/>
20
+ <!-- ... and any includes in the $include parameter -->
21
+ <xsl:with-param name="includes" select="document(/rng:grammar/rng:include/@href
22
+ | //rng:externalRef/@href)"/>
23
+ </xsl:call-template>
24
+ </xsl:template>
25
+ <!-- -->
26
+ <!-- gather all included schemas into a single parameter variable -->
27
+ <!-- -->
28
+ <xsl:template name="gatherSchema">
29
+ <xsl:param name="schemas"/>
30
+ <xsl:param name="includes"/>
31
+ <xsl:choose>
32
+ <xsl:when test="count($schemas) &lt; count($schemas | $includes)">
33
+ <!-- when $includes includes something new, recurse ... -->
34
+ <xsl:call-template name="gatherSchema">
35
+ <!-- ... with current $includes added to the $schemas parameter ... -->
36
+ <xsl:with-param name="schemas" select="$schemas | $includes"/>
37
+ <!-- ... and any *new* includes in the $include parameter -->
38
+ <xsl:with-param name="includes" select="document($includes/rng:grammar/rng:include/@href
39
+ | $includes//rng:externalRef/@href)"/>
40
+ </xsl:call-template>
41
+ </xsl:when>
42
+ <xsl:otherwise>
43
+ <!-- we have the complete set of included schemas, so now let's output the embedded schematron -->
44
+ <xsl:call-template name="output">
45
+ <xsl:with-param name="schemas" select="$schemas"/>
46
+ </xsl:call-template>
47
+ </xsl:otherwise>
48
+ </xsl:choose>
49
+ </xsl:template>
50
+ <!-- -->
51
+ <!-- output the schematron information -->
52
+ <!-- -->
53
+ <xsl:template name="output">
54
+ <xsl:param name="schemas"/>
55
+ <!-- -->
56
+ <sch:schema>
57
+ <!-- get header-type elements - eg title and especially ns -->
58
+ <!-- title (just one) -->
59
+ <xsl:copy-of select="$schemas//sch:title[1]"/>
60
+ <!-- get remaining schematron schema children -->
61
+ <!-- get non-blank namespace elements, dropping duplicates -->
62
+ <xsl:for-each select="$schemas//sch:ns">
63
+ <xsl:if test="generate-id(.) = generate-id($schemas//sch:ns[@prefix = current()/@prefix][1])">
64
+ <xsl:copy-of select="."/>
65
+ </xsl:if>
66
+ </xsl:for-each>
67
+ <xsl:copy-of select="$schemas//sch:phase"/>
68
+ <xsl:copy-of select="$schemas//sch:pattern"/>
69
+ <sch:diagnostics>
70
+ <xsl:copy-of select="$schemas//sch:diagnostics/*"/>
71
+ </sch:diagnostics>
72
+ </sch:schema>
73
+ </xsl:template>
74
+ <!-- -->
75
+ </xsl:transform>
@@ -0,0 +1,77 @@
1
+ <?xml version="1.0" encoding="UTF-8"?>
2
+ <!--
3
+ based on an original transform by Eddie Robertsson
4
+ 2001/04/21 fn: added support for included schemas
5
+ 2001/06/27 er: changed XMl Schema prefix from xsd: to xs: and changed to the Rec namespace
6
+ 2010/04/14 rj: Update for ISO Schematron
7
+ -->
8
+ <xsl:transform version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
9
+ xmlns:sch="http://purl.oclc.org/dsdl/schematron" xmlns:xs="http://www.w3.org/2001/XMLSchema">
10
+ <!-- Set the output to be XML with an XML declaration and use indentation -->
11
+ <xsl:output method="xml" omit-xml-declaration="no" indent="yes" standalone="yes"/>
12
+ <!-- -->
13
+ <!-- match schema and call recursive template to extract included schemas -->
14
+ <!-- -->
15
+ <xsl:template match="xs:schema">
16
+ <!-- call the schema definition template ... -->
17
+ <xsl:call-template name="gatherSchema">
18
+ <!-- ... with current current root as the $schemas parameter ... -->
19
+ <xsl:with-param name="schemas" select="/"/>
20
+ <!-- ... and any includes in the $include parameter -->
21
+ <xsl:with-param name="includes"
22
+ select="document(/xs:schema/xs:*[self::xs:include or self::xs:import or self::xs:redefine]/@schemaLocation)"/>
23
+ </xsl:call-template>
24
+ </xsl:template>
25
+ <!-- -->
26
+ <!-- gather all included schemas into a single parameter variable -->
27
+ <!-- -->
28
+ <xsl:template name="gatherSchema">
29
+ <xsl:param name="schemas"/>
30
+ <xsl:param name="includes"/>
31
+ <xsl:choose>
32
+ <xsl:when test="count($schemas) &lt; count($schemas | $includes)">
33
+ <!-- when $includes includes something new, recurse ... -->
34
+ <xsl:call-template name="gatherSchema">
35
+ <!-- ... with current $includes added to the $schemas parameter ... -->
36
+ <xsl:with-param name="schemas" select="$schemas | $includes"/>
37
+ <!-- ... and any *new* includes in the $include parameter -->
38
+ <xsl:with-param name="includes"
39
+ select="document($includes/xs:schema/xs:*[self::xs:include or self::xs:import or self::xs:redefine]/@schemaLocation)"/>
40
+ </xsl:call-template>
41
+ </xsl:when>
42
+ <xsl:otherwise>
43
+ <!-- we have the complete set of included schemas,
44
+ so now let's output the embedded schematron -->
45
+ <xsl:call-template name="output">
46
+ <xsl:with-param name="schemas" select="$schemas"/>
47
+ </xsl:call-template>
48
+ </xsl:otherwise>
49
+ </xsl:choose>
50
+ </xsl:template>
51
+ <!-- -->
52
+ <!-- output the schematron information -->
53
+ <!-- -->
54
+ <xsl:template name="output">
55
+ <xsl:param name="schemas"/>
56
+ <!-- -->
57
+ <sch:schema>
58
+ <!-- get header-type elements - eg title and especially ns -->
59
+ <!-- title (just one) -->
60
+ <xsl:copy-of select="$schemas//xs:appinfo/sch:title[1]"/>
61
+ <!-- get remaining schematron schema children -->
62
+ <!-- get non-blank namespace elements, dropping duplicates -->
63
+ <xsl:for-each select="$schemas//xs:appinfo/sch:ns">
64
+ <xsl:if test="generate-id(.) =
65
+ generate-id($schemas//xs:appinfo/sch:ns[@prefix = current()/@prefix][1])">
66
+ <xsl:copy-of select="."/>
67
+ </xsl:if>
68
+ </xsl:for-each>
69
+ <xsl:copy-of select="$schemas//xs:appinfo/sch:phase"/>
70
+ <xsl:copy-of select="$schemas//xs:appinfo/sch:pattern"/>
71
+ <sch:diagnostics>
72
+ <xsl:copy-of select="$schemas//xs:appinfo/sch:diagnostics/*"/>
73
+ </sch:diagnostics>
74
+ </sch:schema>
75
+ </xsl:template>
76
+ <!-- -->
77
+ </xsl:transform>
@@ -0,0 +1,297 @@
1
+ <?xml version="1.0" encoding="UTF-8"?><?xar XSLT?>
2
+
3
+ <!--
4
+ OVERVIEW - iso_abstract_expand.xsl
5
+
6
+ This is a preprocessor for ISO Schematron, which implements abstract patterns.
7
+ It also
8
+ * extracts a particular schema using an ID, where there are multiple
9
+ schemas, such as when they are embedded in the same NVDL script
10
+ * experimentally, allows parameter recognition and substitution inside
11
+ text as well as @context, @test, & @select.
12
+
13
+
14
+ This should be used after iso-dsdl-include.xsl and before the skeleton or
15
+ meta-stylesheet (e.g. iso-svrl.xsl) . It only requires XSLT 1.
16
+
17
+ Each kind of inclusion can be turned off (or on) on the command line.
18
+
19
+ -->
20
+ <!--
21
+ VERSION INFORMATION
22
+ 2008-09-18 RJ
23
+ * move out param test from iso:schema template to work with XSLT 1. (Noah Fontes)
24
+
25
+ 2008-07-29 RJ
26
+ * Create. Pull out as distinct XSL in its own namespace from old iso_pre_pro.xsl
27
+ * Put everything in private namespace
28
+ * Rewrite replace_substring named template so that copyright is clear
29
+
30
+ 2008-07-24 RJ
31
+ * correct abstract patterns so for correct names: param/@name and
32
+ param/@value
33
+
34
+ 2007-01-12 RJ
35
+ * Use ISO namespace
36
+ * Use pattern/@id not pattern/@name
37
+ * Add Oliver Becker's suggests from old Schematron-love-in list for <copy>
38
+ * Add XT -ism?
39
+ 2003 RJ
40
+ * Original written for old namespace
41
+ * http://www.topologi.com/resources/iso-pre-pro.xsl
42
+ -->
43
+ <!--
44
+ LEGAL INFORMATION
45
+
46
+ Copyright (c) 2000-2008 Rick Jelliffe and Academia Sinica Computing Center, Taiwan
47
+
48
+ This software is provided 'as-is', without any express or implied warranty.
49
+ In no event will the authors be held liable for any damages arising from
50
+ the use of this software.
51
+
52
+ Permission is granted to anyone to use this software for any purpose,
53
+ including commercial applications, and to alter it and redistribute it freely,
54
+ subject to the following restrictions:
55
+
56
+ 1. The origin of this software must not be misrepresented; you must not claim
57
+ that you wrote the original software. If you use this software in a product,
58
+ an acknowledgment in the product documentation would be appreciated but is
59
+ not required.
60
+
61
+ 2. Altered source versions must be plainly marked as such, and must not be
62
+ misrepresented as being the original software.
63
+
64
+ 3. This notice may not be removed or altered from any source distribution.
65
+ -->
66
+ <xslt:stylesheet version="1.0" xmlns:xslt="http://www.w3.org/1999/XSL/Transform"
67
+ xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
68
+ xmlns:iso="http://purl.oclc.org/dsdl/schematron"
69
+ xmlns:nvdl="http://purl.oclc.org/dsdl/nvdl"
70
+
71
+ xmlns:iae="http://www.schematron.com/namespace/iae"
72
+
73
+ >
74
+
75
+ <xslt:param name="schema-id"></xslt:param>
76
+
77
+
78
+ <!-- Driver for the mode -->
79
+ <xsl:template match="/">
80
+ <xsl:apply-templates select="." mode="iae:go" />
81
+ </xsl:template>
82
+
83
+
84
+ <!-- ================================================================================== -->
85
+ <!-- Normal processing rules -->
86
+ <!-- ================================================================================== -->
87
+ <!-- Output only the selected schema -->
88
+ <xslt:template match="iso:schema" >
89
+ <xsl:if test="string-length($schema-id) =0 or @id= $schema-id ">
90
+ <xslt:copy>
91
+ <xslt:copy-of select="@*" />
92
+ <xslt:apply-templates mode="iae:go" />
93
+ </xslt:copy>
94
+ </xsl:if>
95
+ </xslt:template>
96
+
97
+
98
+ <!-- Strip out any foreign elements above the Schematron schema .
99
+ -->
100
+ <xslt:template match="*[not(ancestor-or-self::iso:*)]" mode="iae:go" >
101
+ <xslt:apply-templates mode="iae:go" />
102
+ </xslt:template>
103
+
104
+
105
+ <!-- ================================================================================== -->
106
+ <!-- Handle Schematron abstract pattern preprocessing -->
107
+ <!-- abstract-to-real calls
108
+ do-pattern calls
109
+ macro-expand calls
110
+ multi-macro-expand
111
+ replace-substring -->
112
+ <!-- ================================================================================== -->
113
+
114
+ <!--
115
+ Abstract patterns allow you to say, for example
116
+
117
+ <pattern name="htmlTable" is-a="table">
118
+ <param name="row" value="html:tr"/>
119
+ <param name="cell" value="html:td" />
120
+ <param name="table" value="html:table" />
121
+ </pattern>
122
+
123
+ For a good introduction, see Uche Ogbujii's article for IBM DeveloperWorks
124
+ "Discover the flexibility of Schematron abstract patterns"
125
+ http://www-128.ibm.com/developerworks/xml/library/x-stron.html
126
+ However, note that ISO Schematron uses @name and @value attributes on
127
+ the iso:param element, and @id not @name on the pattern element.
128
+
129
+ -->
130
+
131
+ <!-- Suppress declarations of abstract patterns -->
132
+ <xslt:template match="iso:pattern[@abstract='true']" mode="iae:go" >
133
+ <xslt:comment>Suppressed abstract pattern <xslt:value-of select="@id"/> was here</xslt:comment>
134
+ </xslt:template>
135
+
136
+
137
+ <!-- Suppress uses of abstract patterns -->
138
+ <xslt:template match="iso:pattern[@is-a]" mode="iae:go" >
139
+
140
+ <xslt:comment>Start pattern based on abstract <xslt:value-of select="@is-a"/></xslt:comment>
141
+
142
+ <xslt:call-template name="iae:abstract-to-real" >
143
+ <xslt:with-param name="caller" select="@id" />
144
+ <xslt:with-param name="is-a" select="@is-a" />
145
+ </xslt:call-template>
146
+
147
+ </xslt:template>
148
+
149
+
150
+
151
+ <!-- output everything else unchanged -->
152
+ <xslt:template match="*" priority="-1" mode="iae:go" >
153
+ <xslt:copy>
154
+ <xslt:copy-of select="@*" />
155
+ <xslt:apply-templates mode="iae:go"/>
156
+ </xslt:copy>
157
+ </xslt:template>
158
+
159
+ <!-- Templates for macro expansion of abstract patterns -->
160
+ <!-- Sets up the initial conditions for the recursive call -->
161
+ <xslt:template name="iae:macro-expand">
162
+ <xslt:param name="caller"/>
163
+ <xslt:param name="text" />
164
+ <xslt:call-template name="iae:multi-macro-expand">
165
+ <xslt:with-param name="caller" select="$caller"/>
166
+ <xslt:with-param name="text" select="$text"/>
167
+ <xslt:with-param name="paramNumber" select="1"/>
168
+ </xslt:call-template>
169
+
170
+ </xslt:template>
171
+
172
+ <!-- Template to replace the current parameter and then
173
+ recurse to replace subsequent parameters. -->
174
+
175
+ <xslt:template name="iae:multi-macro-expand">
176
+ <xslt:param name="caller"/>
177
+ <xslt:param name="text" />
178
+ <xslt:param name="paramNumber" />
179
+
180
+
181
+ <xslt:choose>
182
+ <xslt:when test="//iso:pattern[@id=$caller]/iso:param[ $paramNumber]">
183
+
184
+ <xslt:call-template name="iae:multi-macro-expand">
185
+ <xslt:with-param name="caller" select="$caller"/>
186
+ <xslt:with-param name="paramNumber" select="$paramNumber + 1"/>
187
+ <xslt:with-param name="text" >
188
+ <xslt:call-template name="iae:replace-substring">
189
+ <xslt:with-param name="original" select="$text"/>
190
+ <xslt:with-param name="substring"
191
+ select="concat('$', //iso:pattern[@id=$caller]/iso:param[ $paramNumber ]/@name)"/>
192
+ <xslt:with-param name="replacement"
193
+ select="//iso:pattern[@id=$caller]/iso:param[ $paramNumber ]/@value"/>
194
+ </xslt:call-template>
195
+ </xslt:with-param>
196
+ </xslt:call-template>
197
+ </xslt:when>
198
+ <xslt:otherwise><xslt:value-of select="$text" /></xslt:otherwise>
199
+
200
+ </xslt:choose>
201
+ </xslt:template>
202
+
203
+
204
+ <!-- generate the real pattern from an abstract pattern + parameters-->
205
+ <xslt:template name="iae:abstract-to-real" >
206
+ <xslt:param name="caller"/>
207
+ <xslt:param name="is-a" />
208
+ <xslt:for-each select="//iso:pattern[@id= $is-a]">
209
+ <xslt:copy>
210
+
211
+ <xslt:choose>
212
+ <xslt:when test=" string-length( $caller ) = 0">
213
+ <xslt:attribute name="id"><xslt:value-of select="concat( generate-id(.) , $is-a)" /></xslt:attribute>
214
+ </xslt:when>
215
+ <xslt:otherwise>
216
+ <xslt:attribute name="id"><xslt:value-of select="$caller" /></xslt:attribute>
217
+ </xslt:otherwise>
218
+ </xslt:choose>
219
+
220
+ <xslt:apply-templates select="*|text()" mode="iae:do-pattern" >
221
+ <xslt:with-param name="caller"><xslt:value-of select="$caller"/></xslt:with-param>
222
+ </xslt:apply-templates>
223
+
224
+ </xslt:copy>
225
+ </xslt:for-each>
226
+ </xslt:template>
227
+
228
+
229
+ <!-- Generate a non-abstract pattern -->
230
+ <xslt:template mode="iae:do-pattern" match="*">
231
+ <xslt:param name="caller"/>
232
+ <xslt:copy>
233
+ <xslt:for-each select="@*[name()='test' or name()='context' or name()='select']">
234
+ <xslt:attribute name="{name()}">
235
+ <xslt:call-template name="iae:macro-expand">
236
+ <xslt:with-param name="text"><xslt:value-of select="."/></xslt:with-param>
237
+ <xslt:with-param name="caller"><xslt:value-of select="$caller"/></xslt:with-param>
238
+ </xslt:call-template>
239
+ </xslt:attribute>
240
+ </xslt:for-each>
241
+ <xslt:copy-of select="@*[name()!='test'][name()!='context'][name()!='select']" />
242
+ <xsl:for-each select="node()">
243
+ <xsl:choose>
244
+ <!-- Experiment: replace macros in text as well, to allow parameterized assertions
245
+ and so on, without having to have spurious <iso:value-of> calls and multiple
246
+ delimiting -->
247
+ <xsl:when test="self::text()">
248
+ <xslt:call-template name="iae:macro-expand">
249
+ <xslt:with-param name="text"><xslt:value-of select="."/></xslt:with-param>
250
+ <xslt:with-param name="caller"><xslt:value-of select="$caller"/></xslt:with-param>
251
+ </xslt:call-template>
252
+ </xsl:when>
253
+ <xsl:otherwise>
254
+ <xslt:apply-templates select="." mode="iae:do-pattern">
255
+ <xslt:with-param name="caller"><xslt:value-of select="$caller"/></xslt:with-param>
256
+ </xslt:apply-templates>
257
+ </xsl:otherwise>
258
+ </xsl:choose>
259
+ </xsl:for-each>
260
+ </xslt:copy>
261
+ </xslt:template>
262
+
263
+ <!-- UTILITIES -->
264
+ <!-- Simple version of replace-substring function -->
265
+ <xslt:template name="iae:replace-substring">
266
+ <xslt:param name="original" />
267
+ <xslt:param name="substring" />
268
+ <xslt:param name="replacement" select="''"/>
269
+
270
+ <xsl:choose>
271
+ <xsl:when test="not($original)" />
272
+ <xsl:when test="not(string($substring))">
273
+ <xsl:value-of select="$original" />
274
+ </xsl:when>
275
+ <xsl:when test="contains($original, $substring)">
276
+ <xsl:variable name="before" select="substring-before($original, $substring)" />
277
+ <xsl:variable name="after" select="substring-after($original, $substring)" />
278
+
279
+ <xsl:value-of select="$before" />
280
+ <xsl:value-of select="$replacement" />
281
+ <!-- recursion -->
282
+ <xsl:call-template name="iae:replace-substring">
283
+ <xsl:with-param name="original" select="$after" />
284
+ <xsl:with-param name="substring" select="$substring" />
285
+ <xsl:with-param name="replacement" select="$replacement" />
286
+ </xsl:call-template>
287
+ </xsl:when>
288
+ <xsl:otherwise>
289
+ <!-- no substitution -->
290
+ <xsl:value-of select="$original" />
291
+ </xsl:otherwise>
292
+ </xsl:choose>
293
+ </xslt:template>
294
+
295
+
296
+
297
+ </xslt:stylesheet>