When you define an element with @contains, and the referred template is of type context ** and thus defines a templateId, the generated schematron will not check if the instance actually has that element including the defined templateId.
So when an instance has the element, but does not have the templateId none of the rules in the SCH file for that part of the instance will trigger since everything depends on the existence of the templateId element.
Example definition:
<!-- Element component3/OntvangenZorg -->
<element name="hl7:component3" contains="A_OntvangenZorg-universal" minimumMultiplicity="0" maximumMultiplicity="*">
<attribute typeCode="COMP" isOptional="true"/>
</element>
A_OntvangenZorg-universal is a template with context ** defining a top level element hl7:patientCareProvision and a child element templateId '2.16.840.1.113883.2.4.6.10.100.119'. Expecting schematron rule like this:
<rule context=".../hl7:component3>
<assert role="error" test="hl7:patientCareProvision[hl7:templateId/@root='2.16.840.1.113883.2.4.6.10.100.119']">(...): element hl7:patientCareProvision[hl7:templateId/@root='2.16.840.1.113883.2.4.6.10.100.119'] MUST occur min 1</assert>
</rule>
Alternatively if you decide to go with include instead of contains, this type of check actually is generated, but without the predicate containing the templateId:
<!-- Element component3/OntvangenZorg -->
<element name="hl7:component3" minimumMultiplicity="0" maximumMultiplicity="*">
<attribute typeCode="COMP" isOptional="true"/>
<include ref="A_OntvangenZorg-universal" minimumMultiplicity="1" maximumMultiplicity="1" conformance="R" isMandatory="true"/>
</element>
This leads to:
<rule context=".../hl7:component3>
<assert role="error" test="hl7:patientCareProvision">(...): element hl7:patientCareProvision MUST occur min 1</assert>
</rule>
It was designed as (but obviously to be checked again) the following: a @contains of a template id will create rules to check whether there is a templateId as "immediate" (or any subsequent) child under @contains context.
Will check and change.
Actually I tested it and it works as intended. A contains by name or OID leads to schematrons that test the existence of instance parts with that templateId. Are there situations (example template fragments) where it doesn't work?
Fixed