A.8. SchematronSchematron is a XPath/XSLT-based language for defining context-dependent rules. Schematron doesn't directly support structure or datatype validation, but a schema author may write rules that implement these checks. To write a full schema with Schematron, the author needs to take care to include all the rules needed to qualify the structure of the document. Table A-4 provides the fact sheet for Schematron. Table A-4. Schematron fact sheet
A.8.1. Example<sch:schema xmlns:sch="http://www.ascc.net/xml/schematron"> <sch:title> Schematron Schema for library </sch:title> <sch:pattern> <sch:rule context="/"> <sch:assert test="library"> The document element should be "library". </sch:assert> </sch:rule> <sch:rule context="/library"> <sch:assert test="book"> There should be at least a book! </sch:assert> <sch:assert test="not(@*)"> No attribute for library, please! </sch:assert> </sch:rule> <sch:rule context="/library/book"> <sch:assert test="not(following-sibling::book/@id=@id)"> Duplicated ID for this book. </sch:assert> <sch:assert test="@id=concat('-', isbn)"> The id should be derived from the ISBN. </sch:assert> </sch:rule> <sch:rule context="/library/*"> <sch:assert test="name()='book' or name( )='author' or name( )='character'"> This element shouldn't be here... </sch:assert> </sch:rule> </sch:pattern> </sch:schema> Note that the previous Schematron is a partial schema meant as a supplement. Copyright © 2002 O'Reilly & Associates. All rights reserved. |
|