Can Schematron validate XML processing instructions?
Here is a rule for disallowing processing instructions from a document
There should be no processing instructions
Here is a pattern for validating that the only processing instruction allowed that starts with "xml" is "xml-stylesheet".
<sch:pattern> <sch:rule context="processing-instruction('xml-stylesheet')"> <sch:assert test="true()"> The xml-stylesheet PI is allowed <sch:assert> </sch:rule> <sch:rule context= "processing-instruction()[starts-with(name(), 'xml')]"> <sch:report test="true()"> There should be no processing instructions that starts with 'xml' (except for xml-stylesheet)<sch:report> </sch:rule> </sch:pattern>
In general, validating processing instructions is no more difficult than validating element or attribute content. (This assumes your processing instruction uses a target, as is good XML practice.) The gotcha is of course that sometimes PIs contain pseudo attributes which may then have to be parsed, which can be too hard for Schematron validation.