Can Schematron validate XML processing instructions?

By Rick Jelliffe
March 1, 2009 | Comments: 2

Can Schematron validate XML processing instructions?

Here is a rule for disallowing processing instructions from a document

<sch:rule context="processing-instruction()">
<sch:report test="true()">
There should be no processing instructions
<sch:report>
</sch:rule>

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.


You might also be interested in:

2 Comments

Sometimes PIs contain pseudo attributes which may then have to be parsed, which can be too hard for Schematron validation.

True, although if you allow yourself a processor-specific extension such as the one below, then
processing these pseudo attributes is a lot easier.

David

http://www.saxonica.com/documentation/extensions/functions/getpseudoattribute.html

How to open processing instrucion window in indesign cs3 using javascript.

News Topics

Recommended for You

Got a Question?