spec_0.xml 118 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205320632073208320932103211321232133214321532163217321832193220322132223223322432253226322732283229323032313232323332343235323632373238323932403241324232433244324532463247324832493250325132523253325432553256325732583259326032613262326332643265326632673268326932703271327232733274327532763277327832793280328132823283328432853286328732883289329032913292329332943295329632973298329933003301330233033304330533063307330833093310331133123313331433153316331733183319332033213322332333243325332633273328332933303331333233333334333533363337333833393340334133423343334433453346334733483349335033513352335333543355335633573358335933603361336233633364336533663367336833693370337133723373337433753376337733783379338033813382338333843385338633873388338933903391339233933394339533963397339833993400340134023403340434053406340734083409341034113412341334143415341634173418341934203421342234233424342534263427342834293430343134323433343434353436343734383439344034413442344334443445344634473448344934503451345234533454345534563457345834593460346134623463346434653466346734683469347034713472347334743475347634773478347934803481348234833484348534863487348834893490349134923493349434953496349734983499350035013502350335043505350635073508350935103511351235133514351535163517351835193520352135223523352435253526352735283529353035313532353335343535353635373538353935403541354235433544354535463547354835493550355135523553355435553556355735583559356035613562356335643565356635673568356935703571357235733574357535763577357835793580358135823583358435853586358735883589
  1. <?xml version="1.0" encoding="iso-8859-1"?>
  2. <!DOCTYPE article [
  3. <!-- ELEMENT declarations work around MSXML bug. -->
  4. <!ELEMENT section ANY>
  5. <!ATTLIST section id ID #IMPLIED>
  6. <!ELEMENT appendix ANY>
  7. <!ATTLIST appendix id ID #IMPLIED>
  8. <!ELEMENT bibliomixed ANY>
  9. <!ATTLIST bibliomixed id ID #IMPLIED>
  10. ]>
  11. <article status="Committee Specification" xmlns:p="http://relaxng.org/ns/proofsystem">
  12. <articleinfo>
  13. <releaseinfo>$Id: spec.xml,v 1.159 2001/12/02 12:12:12 jjc Exp $</releaseinfo>
  14. <title>RELAX NG Specification</title>
  15. <authorgroup>
  16. <editor>
  17. <firstname>James</firstname><surname>Clark</surname>
  18. <affiliation>
  19. <address><email>jjc@jclark.com</email></address>
  20. </affiliation>
  21. </editor>
  22. <editor>
  23. <surname>MURATA</surname><firstname>Makoto</firstname>
  24. <affiliation>
  25. <address><email>EB2M-MRT@asahi-net.or.jp</email></address>
  26. </affiliation>
  27. </editor>
  28. </authorgroup>
  29. <pubdate>3 December 2001</pubdate>
  30. <releaseinfo role="meta">
  31. $Id: spec.xml,v 1.159 2001/12/02 12:12:12 jjc Exp $
  32. </releaseinfo>
  33. <copyright><year>2001</year><holder>OASIS</holder></copyright>
  34. <legalnotice>
  35. <para>Copyright &#169; The Organization for the Advancement of
  36. Structured Information Standards [OASIS] 2001. All Rights
  37. Reserved.</para>
  38. <para>This document and translations of it may be copied and furnished
  39. to others, and derivative works that comment on or otherwise explain
  40. it or assist in its implementation may be prepared, copied, published
  41. and distributed, in whole or in part, without restriction of any kind,
  42. provided that the above copyright notice and this paragraph are
  43. included on all such copies and derivative works. However, this
  44. document itself may not be modified in any way, such as by removing
  45. the copyright notice or references to OASIS, except as needed for the
  46. purpose of developing OASIS specifications, in which case the
  47. procedures for copyrights defined in the OASIS Intellectual Property
  48. Rights document must be followed, or as required to translate it into
  49. languages other than English.</para>
  50. <para>The limited permissions granted above are perpetual and will not
  51. be revoked by OASIS or its successors or assigns.</para>
  52. <para>This document and the information contained herein is provided
  53. on an <quote>AS IS</quote> basis and OASIS DISCLAIMS ALL WARRANTIES,
  54. EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO ANY WARRANTY THAT THE
  55. USE OF THE INFORMATION HEREIN WILL NOT INFRINGE ANY RIGHTS OR ANY
  56. IMPLIED WARRANTIES OF MERCHANTABILITY OR FITNESS FOR A PARTICULAR
  57. PURPOSE.</para>
  58. </legalnotice>
  59. <legalnotice role="status"><title>Status of this Document</title>
  60. <para>This Committee Specification was approved for publication by the
  61. OASIS RELAX NG technical committee. It is a stable document which
  62. represents the consensus of the committee. Comments on this document
  63. may be sent to <ulink
  64. url="mailto:relax-ng-comment@lists.oasis-open.org"
  65. >relax-ng-comment@lists.oasis-open.org</ulink>.</para>
  66. <para>A list of known errors in this document is available at <ulink
  67. url="http://www.oasis-open.org/committees/relax-ng/spec-20011203-errata.html"
  68. >http://www.oasis-open.org/committees/relax-ng/spec-20011203-errata.html</ulink
  69. >.</para>
  70. </legalnotice>
  71. <abstract>
  72. <para>This is the definitive specification of RELAX NG, a simple
  73. schema language for XML, based on <xref linkend="relax"/> and <xref
  74. linkend="trex"/>. A RELAX NG schema specifies a pattern for the
  75. structure and content of an XML document. A RELAX NG schema is itself
  76. an XML document.</para>
  77. </abstract>
  78. <revhistory>
  79. <revision>
  80. <revnumber>Committee Specification</revnumber>
  81. <date>3 December 2001</date>
  82. </revision>
  83. <revision>
  84. <revnumber>Committee Specification</revnumber>
  85. <date>11 August 2001</date>
  86. </revision>
  87. </revhistory>
  88. </articleinfo>
  89. <section>
  90. <title>Introduction</title>
  91. <para>This document specifies</para>
  92. <itemizedlist>
  93. <listitem><para>when an XML document is a correct RELAX NG
  94. schema</para></listitem>
  95. <listitem><para>when an XML document is valid with respect to a
  96. correct RELAX NG schema</para></listitem>
  97. </itemizedlist>
  98. <para>An XML document that is being validated with respect to a RELAX NG
  99. schema is referred to as an instance.</para>
  100. <para>The structure of this document is as follows. <xref
  101. linkend="data-model"/> describes the data model, which is the
  102. abstraction of an XML document used throughout the rest of the
  103. document. <xref linkend="full-syntax"/> describes the syntax of a
  104. RELAX NG schema; any correct RELAX NG schema must conform to this
  105. syntax. <xref linkend="simplification"/> describes a sequence of
  106. transformations that are applied to simplify a RELAX NG schema;
  107. applying the transformations also involves checking certain
  108. restrictions that must be satisfied by a correct RELAX NG
  109. schema. <xref linkend="simple-syntax"/> describes the syntax that
  110. results from applying the transformations; this simple syntax is a
  111. subset of the full syntax. <xref linkend="semantics"/> describes the
  112. semantics of a correct RELAX NG schema that uses the simple syntax;
  113. the semantics specify when an element is valid with respect to a RELAX
  114. NG schema. <xref linkend="restriction"/> describes restrictions in
  115. terms of the simple syntax; a correct RELAX NG schema must be such
  116. that, after transformation into the simple form, it satisfies these
  117. restrictions. Finally, <xref linkend="conformance"/> describes
  118. conformance requirements for RELAX NG validators.</para>
  119. <para>A tutorial is available separately (see <xref
  120. linkend="tutorial"/>).</para>
  121. </section>
  122. <section id="data-model">
  123. <title>Data model</title>
  124. <para>RELAX NG deals with XML documents representing both schemas and
  125. instances through an abstract data model. XML documents representing
  126. schemas and instances must be well-formed in conformance with <xref
  127. linkend="xml-rec"/> and must conform to the constraints of <xref
  128. linkend="xml-names"/>.</para>
  129. <para>An XML document is represented by an element. An element consists
  130. of</para>
  131. <itemizedlist>
  132. <listitem><para>a name</para></listitem>
  133. <listitem><para>a context</para></listitem>
  134. <listitem><para>a set of attributes</para></listitem>
  135. <listitem><para>an ordered sequence of zero or more children; each
  136. child is either an element or a non-empty string; the sequence never contains
  137. two consecutive strings</para></listitem>
  138. </itemizedlist>
  139. <para>A name consists of</para>
  140. <itemizedlist>
  141. <listitem><para>a string representing the namespace URI; the empty
  142. string has special significance, representing the absence of any
  143. namespace</para></listitem>
  144. <listitem><para>a string representing the local name; this string matches the NCName
  145. production of <xref linkend="xml-names"/></para></listitem>
  146. </itemizedlist>
  147. <para>A context consists of</para>
  148. <itemizedlist>
  149. <listitem><para>a base URI</para></listitem>
  150. <listitem><para>a namespace map; this maps prefixes to namespace URIs,
  151. and also may specify a default namespace URI (as declared
  152. by the <literal>xmlns</literal> attribute)</para></listitem>
  153. </itemizedlist>
  154. <para>An attribute consists of</para>
  155. <itemizedlist>
  156. <listitem><para>a name</para></listitem>
  157. <listitem><para>a string representing the value</para></listitem>
  158. </itemizedlist>
  159. <para>A string consists of a sequence of zero or more characters,
  160. where a character is as defined in <xref linkend="xml-rec"/>.</para>
  161. <para>The element for an XML document is constructed from an instance
  162. of the <xref linkend="infoset"/> as follows. We use the notation
  163. [<replaceable>x</replaceable>] to refer to the value of the
  164. <replaceable>x</replaceable> property of an information item. An
  165. element is constructed from a document information item by
  166. constructing an element from the [document element]. An element is
  167. constructed from an element information item by constructing the name
  168. from the [namespace name] and [local name], the context from the [base
  169. URI] and [in-scope namespaces], the attributes from the [attributes],
  170. and the children from the [children]. The attributes of an element
  171. are constructed from the unordered set of attribute information items
  172. by constructing an attribute for each attribute information item. The
  173. children of an element are constructed from the list of child
  174. information items first by removing information items other than
  175. element information items and character information items, and then by
  176. constructing an element for each element information item in the list
  177. and a string for each maximal sequence of character information items.
  178. An attribute is constructed from an attribute information item by
  179. constructing the name from the [namespace name] and [local name], and
  180. the value from the [normalized value]. When constructing the name of
  181. an element or attribute from the [namespace name] and [local name], if
  182. the [namespace name] property is not present, then the name is
  183. constructed from an empty string and the [local name]. A string is
  184. constructed from a sequence of character information items by
  185. constructing a character from the [character code] of each character
  186. information item.</para>
  187. <para>It is possible for there to be multiple distinct infosets for a
  188. single XML document. This is because XML parsers are not required to
  189. process all DTD declarations or expand all external parsed general
  190. entities. Amongst these multiple infosets, there is exactly one
  191. infoset for which [all declarations processed] is true and which does
  192. not contain any unexpanded entity reference information items. This
  193. is the infoset that is the basis for defining the RELAX NG data
  194. model.</para>
  195. <section id="data-model-example">
  196. <title>Example</title>
  197. <para>Suppose the document
  198. <literal>http://www.example.com/doc.xml</literal> is as
  199. follows:</para>
  200. <programlisting><![CDATA[<?xml version="1.0"?>
  201. <foo><pre1:bar1 xmlns:pre1="http://www.example.com/n1"/><pre2:bar2
  202. xmlns:pre2="http://www.example.com/n2"/></foo>
  203. ]]></programlisting>
  204. <para>The element representing this document has</para>
  205. <itemizedlist>
  206. <listitem><para>a name which has</para>
  207. <itemizedlist>
  208. <listitem><para>the empty string as the namespace URI, representing
  209. the absence of any namespace</para></listitem>
  210. <listitem><para><literal>foo</literal> as the local
  211. name</para></listitem>
  212. </itemizedlist>
  213. </listitem>
  214. <listitem><para>a context which has</para>
  215. <itemizedlist>
  216. <listitem><para><literal>http://www.example.com/doc.xml</literal> as the base
  217. URI</para></listitem>
  218. <listitem><para>a namespace map which</para>
  219. <itemizedlist>
  220. <listitem><para>maps the prefix <literal>xml</literal> to the
  221. namespace URI
  222. <literal>http://www.w3.org/XML/1998/namespace</literal>
  223. (the <literal>xml</literal> prefix is implicitly declared
  224. by every XML document)</para></listitem>
  225. <listitem><para>specifies the empty string as the default namespace
  226. URI</para></listitem>
  227. </itemizedlist>
  228. </listitem>
  229. </itemizedlist>
  230. </listitem>
  231. <listitem><para>an empty set of attributes</para></listitem>
  232. <listitem><para>a sequence of children consisting
  233. of an element which has</para>
  234. <itemizedlist>
  235. <listitem><para>a name which has</para>
  236. <itemizedlist>
  237. <listitem><para><literal>http://www.example.com/n1</literal> as the
  238. namespace URI</para></listitem>
  239. <listitem><para><literal>bar1</literal> as the local
  240. name</para></listitem>
  241. </itemizedlist>
  242. </listitem>
  243. <listitem><para>a context which has</para>
  244. <itemizedlist>
  245. <listitem><para><literal>http://www.example.com/doc.xml</literal> as the base
  246. URI</para></listitem>
  247. <listitem><para>a namespace map which</para>
  248. <itemizedlist>
  249. <listitem><para>maps the prefix <literal>pre1</literal> to the
  250. namespace URI
  251. <literal>http://www.example.com/n1</literal></para></listitem>
  252. <listitem><para>maps the prefix <literal>xml</literal> to the
  253. namespace URI
  254. <literal>http://www.w3.org/XML/1998/namespace</literal></para></listitem>
  255. <listitem><para>specifies the empty string as the default namespace
  256. URI</para></listitem>
  257. </itemizedlist>
  258. </listitem>
  259. </itemizedlist>
  260. </listitem>
  261. <listitem><para>an empty set of attributes</para></listitem>
  262. <listitem><para>an empty sequence of children</para></listitem>
  263. </itemizedlist>
  264. <para>followed by an element which has</para>
  265. <itemizedlist>
  266. <listitem><para>a name which has</para>
  267. <itemizedlist>
  268. <listitem><para><literal>http://www.example.com/n2</literal> as the
  269. namespace URI</para></listitem>
  270. <listitem><para><literal>bar2</literal> as the local
  271. name</para></listitem>
  272. </itemizedlist>
  273. </listitem>
  274. <listitem><para>a context which has</para>
  275. <itemizedlist>
  276. <listitem><para><literal>http://www.example.com/doc.xml</literal> as the base
  277. URI</para></listitem>
  278. <listitem><para>a namespace map which</para>
  279. <itemizedlist>
  280. <listitem><para>maps the prefix <literal>pre2</literal> to the
  281. namespace URI
  282. <literal>http://www.example.com/n2</literal></para></listitem>
  283. <listitem><para>maps the prefix <literal>xml</literal> to the
  284. namespace URI
  285. <literal>http://www.w3.org/XML/1998/namespace</literal></para></listitem>
  286. <listitem><para>specifies the empty string as the default namespace
  287. URI</para></listitem>
  288. </itemizedlist>
  289. </listitem>
  290. </itemizedlist>
  291. </listitem>
  292. <listitem><para>an empty set of attributes</para></listitem>
  293. <listitem><para>an empty sequence of children</para></listitem>
  294. </itemizedlist>
  295. </listitem>
  296. </itemizedlist>
  297. </section>
  298. </section>
  299. <section id="full-syntax">
  300. <title>Full syntax</title>
  301. <para>The following grammar summarizes the syntax of RELAX NG.
  302. Although we use a notation based on the XML representation of an RELAX
  303. NG schema as a sequence of characters, the grammar must be understood
  304. as operating at the data model level. For example, although the
  305. syntax uses <literal><![CDATA[<text/>]]></literal>, an instance or
  306. schema can use <literal><![CDATA[<text></text>]]></literal> instead,
  307. because they both represent the same element at the data model level.
  308. All elements shown in the grammar are qualified with the namespace
  309. URI:</para>
  310. <programlisting>http://relaxng.org/ns/structure/1.0</programlisting>
  311. <para>The symbols QName and NCName are defined in <xref
  312. linkend="xml-names"/>. The anyURI symbol has the same meaning as the
  313. anyURI datatype of <xref linkend="xmlschema-2"/>: it indicates a
  314. string that, after escaping of disallowed values as described in
  315. Section 5.4 of <xref linkend="xlink"/>, is a URI reference as defined
  316. in <xref linkend="rfc2396"/> (as modified by <xref
  317. linkend="rfc2732"/>). The symbol string matches any string.</para>
  318. <para>In addition to the attributes shown explicitly, any element can
  319. have an <literal>ns</literal> attribute and any element can have a
  320. <literal>datatypeLibrary</literal> attribute. The
  321. <literal>ns</literal> attribute can have any value. The value of the
  322. <literal>datatypeLibrary</literal> attribute must match the anyURI
  323. symbol as described in the previous paragraph; in addition, it must
  324. not use the relative form of URI reference and must not have a
  325. fragment identifier; as an exception to this, the value may be the
  326. empty string.</para>
  327. <para>Any element can also have foreign attributes in addition to the
  328. attributes shown in the grammar. A foreign attribute is an attribute
  329. with a name whose namespace URI is neither the empty string nor the
  330. RELAX NG namespace URI. Any element that cannot have string children
  331. (that is, any element other than <literal>value</literal>, <literal>param</literal>
  332. and <literal>name</literal>) may have foreign child elements in addition
  333. to the child elements shown in the grammar. A foreign element is an
  334. element with a name whose namespace URI is not the RELAX NG namespace
  335. URI. There are no constraints on the relative position of foreign
  336. child elements with respect to other child elements.</para>
  337. <para>Any element can also have as children strings that consist
  338. entirely of whitespace characters, where a whitespace character is one
  339. of #x20, #x9, #xD or #xA. There are no constraints on the relative
  340. position of whitespace string children with respect to child
  341. elements.</para>
  342. <para>Leading and trailing whitespace is allowed for value of each
  343. <literal>name</literal>, <literal>type</literal> and
  344. <literal>combine</literal> attribute and for the content of each
  345. <literal>name</literal> element.</para>
  346. <grammarref src="full.rng"/>
  347. <section id="full-syntax-example">
  348. <title>Example</title>
  349. <para>Here is an example of a schema in the full syntax for the
  350. document in <xref linkend="data-model-example"/>.</para>
  351. <programlisting><![CDATA[<?xml version="1.0"?>
  352. <element name="foo"
  353. xmlns="http://relaxng.org/ns/structure/1.0"
  354. xmlns:a="http://relaxng.org/ns/annotation/1.0"
  355. xmlns:ex1="http://www.example.com/n1"
  356. xmlns:ex2="http://www.example.com/n2">
  357. <a:documentation>A foo element.</a:document>
  358. <element name="ex1:bar1">
  359. <empty/>
  360. </element>
  361. <element name="ex2:bar2">
  362. <empty/>
  363. </element>
  364. </element>]]></programlisting>
  365. </section>
  366. </section>
  367. <section id="simplification">
  368. <title>Simplification</title>
  369. <para>The full syntax given in the previous section is transformed
  370. into a simpler syntax by applying the following transformation rules
  371. in order. The effect must be as if each rule was applied to all
  372. elements in the schema before the next rule is applied. A
  373. transformation rule may also specify constraints that must be
  374. satisfied by a correct schema. The transformation rules are applied
  375. at the data model level. Before the transformations are applied, the
  376. schema is parsed into an instance of the data model.</para>
  377. <section>
  378. <title>Annotations</title>
  379. <para>Foreign attributes and elements are removed.</para>
  380. <note><para>It is safe to remove <literal>xml:base</literal>
  381. attributes at this stage because <literal>xml:base</literal>
  382. attributes are used in determining the [base URI] of an element
  383. information item, which is in turn used to construct the base URI of
  384. the context of an element. Thus, after a document has been parsed
  385. into an instance of the data model, <literal>xml:base</literal>
  386. attributes can be discarded.</para></note>
  387. </section>
  388. <section>
  389. <title>Whitespace</title>
  390. <para>For each element other than <literal>value</literal> and
  391. <literal>param</literal>, each child that is a string containing only
  392. whitespace characters is removed.</para>
  393. <para>Leading and trailing whitespace characters are removed from the
  394. value of each <literal>name</literal>, <literal>type</literal> and
  395. <literal>combine</literal> attribute and from the content of each
  396. <literal>name</literal> element.</para>
  397. </section>
  398. <section>
  399. <title><literal>datatypeLibrary</literal> attribute</title>
  400. <para>The value of each <literal>datatypeLibary</literal> attribute is
  401. transformed by escaping disallowed characters as specified in Section
  402. 5.4 of <xref linkend="xlink"/>.</para>
  403. <para>For any <literal>data</literal> or <literal>value</literal>
  404. element that does not have a <literal>datatypeLibrary</literal>
  405. attribute, a <literal>datatypeLibrary</literal> attribute is
  406. added. The value of the added <literal>datatypeLibrary</literal>
  407. attribute is the value of the <literal>datatypeLibrary</literal>
  408. attribute of the nearest ancestor element that has a
  409. <literal>datatypeLibrary</literal> attribute, or the empty string if
  410. there is no such ancestor. Then, any <literal>datatypeLibrary</literal>
  411. attribute that is on an element other than <literal>data</literal> or
  412. <literal>value</literal> is removed.</para>
  413. </section>
  414. <section>
  415. <title><literal>type</literal> attribute of <literal>value</literal> element</title>
  416. <para>For any <literal>value</literal> element that does not have a
  417. <literal>type</literal> attribute, a <literal>type</literal> attribute
  418. is added with value <literal>token</literal> and the value of the
  419. <literal>datatypeLibrary</literal> attribute is changed to the empty
  420. string.</para>
  421. </section>
  422. <section id="href">
  423. <title><literal>href</literal> attribute</title>
  424. <para>The value of the <literal>href</literal> attribute on an
  425. <literal>externalRef</literal> or <literal>include</literal> element
  426. is first transformed by escaping disallowed characters as specified in
  427. Section 5.4 of <xref linkend="xlink"/>. The URI reference is then
  428. resolved into an absolute form as described in section 5.2 of <xref
  429. linkend="rfc2396"/> using the base URI from the context of the element
  430. that bears the <literal>href</literal> attribute.</para>
  431. <para>The value of the <literal>href</literal> attribute will be used
  432. to construct an element (as specified in <xref
  433. linkend="data-model"/>). This must be done as follows. The URI
  434. reference consists of the URI itself and an optional fragment
  435. identifier. The resource identified by the URI is retrieved. The
  436. result is a MIME entity: a sequence of bytes labeled with a MIME
  437. media type. The media type determines how an element is constructed
  438. from the MIME entity and optional fragment identifier. When the media
  439. type is <literal>application/xml</literal> or
  440. <literal>text/xml</literal>, the MIME entity must be parsed as an XML
  441. document in accordance with the applicable RFC (at the term of writing
  442. <xref linkend="rfc3023"/>) and an element constructed from the result
  443. of the parse as specified in <xref linkend="data-model"/>. In
  444. particular, the <literal>charset</literal> parameter must be handled
  445. as specified by the RFC. This specification does not define the
  446. handling of media types other than <literal>application/xml</literal>
  447. and <literal>text/xml</literal>. The <literal>href</literal> attribute
  448. must not include a fragment identifier unless the registration of the
  449. media type of the resource identified by the attribute defines the
  450. interpretation of fragment identifiers for that media type.</para>
  451. <note><para><xref linkend="rfc3023"/> does not define the
  452. interpretation of fragment identifiers for
  453. <literal>application/xml</literal> or
  454. <literal>text/xml</literal>.</para></note>
  455. </section>
  456. <section>
  457. <title><literal>externalRef</literal> element</title>
  458. <para>An <literal>externalRef</literal> element is transformed as
  459. follows. An element is constructed using the URI reference that is
  460. the value of <literal>href</literal> attribute as specified in <xref
  461. linkend="href"/>. This element must match the syntax for pattern. The
  462. element is transformed by recursively applying the rules from this
  463. subsection and from previous subsections of this section. This must
  464. not result in a loop. In other words, the transformation of the
  465. referenced element must not require the dereferencing of an
  466. <literal>externalRef</literal> attribute with an
  467. <literal>href</literal> attribute with the same value.</para>
  468. <para>Any <literal>ns</literal> attribute on the
  469. <literal>externalRef</literal> element is transferred to the
  470. referenced element if the referenced element does not already have an
  471. <literal>ns</literal> attribute. The <literal>externalRef</literal>
  472. element is then replaced by the referenced element.</para>
  473. </section>
  474. <section>
  475. <title><literal>include</literal> element</title>
  476. <para>An <literal>include</literal> element is transformed as follows.
  477. An element is constructed using the URI reference that is the value of
  478. <literal>href</literal> attribute as specified in <xref
  479. linkend="href"/>. This element must be a <literal>grammar</literal>
  480. element, matching the syntax for grammar.</para>
  481. <para>This <literal>grammar</literal> element is transformed by
  482. recursively applying the rules from this subsection and from previous
  483. subsections of this section. This must not result in a loop. In other
  484. words, the transformation of the <literal>grammar</literal> element
  485. must not require the dereferencing of an <literal>include</literal>
  486. attribute with an <literal>href</literal> attribute with the same
  487. value.</para>
  488. <para>Define the <firstterm>components</firstterm> of an element to
  489. be the children of the element together with the components of any
  490. <literal>div</literal> child elements. If the
  491. <literal>include</literal> element has a <literal>start</literal>
  492. component, then the <literal>grammar</literal> element must have a
  493. <literal>start</literal> component. If the <literal>include</literal>
  494. element has a <literal>start</literal> component, then all
  495. <literal>start</literal> components are removed from the
  496. <literal>grammar</literal> element. If the <literal>include</literal>
  497. element has a <literal>define</literal> component, then the
  498. <literal>grammar</literal> element must have a
  499. <literal>define</literal> component with the same name. For every
  500. <literal>define</literal> component of the <literal>include</literal>
  501. element, all <literal>define</literal> components with the same name
  502. are removed from the <literal>grammar</literal> element.</para>
  503. <para>The <literal>include</literal> element is transformed into a
  504. <literal>div</literal> element. The attributes of the
  505. <literal>div</literal> element are the attributes of the
  506. <literal>include</literal> element other than the
  507. <literal>href</literal> attribute. The children of the
  508. <literal>div</literal> element are the <literal>grammar</literal>
  509. element (after the removal of the <literal>start</literal> and
  510. <literal>define</literal> components described by the preceding
  511. paragraph) followed by the children of the <literal>include</literal>
  512. element. The <literal>grammar</literal> element is then renamed to
  513. <literal>div</literal>.</para>
  514. </section>
  515. <section>
  516. <title><literal>name</literal> attribute of <literal>element</literal>
  517. and <literal>attribute</literal> elements</title>
  518. <para>The <literal>name</literal> attribute on an
  519. <literal>element</literal> or <literal>attribute</literal> element is
  520. transformed into a <literal>name</literal> child element.</para>
  521. <para>If an <literal>attribute</literal> element has a
  522. <literal>name</literal> attribute but no <literal>ns</literal>
  523. attribute, then an <literal>ns=""</literal> attribute is added to the
  524. <literal>name</literal> child element.</para>
  525. </section>
  526. <section>
  527. <title><literal>ns</literal> attribute</title>
  528. <para>For any <literal>name</literal>, <literal>nsName</literal> or
  529. <literal>value</literal> element that does not have an
  530. <literal>ns</literal> attribute, an <literal>ns</literal> attribute is
  531. added. The value of the added <literal>ns</literal> attribute is the
  532. value of the <literal>ns</literal> attribute of the nearest ancestor
  533. element that has an <literal>ns</literal> attribute, or the empty
  534. string if there is no such ancestor. Then, any <literal>ns</literal>
  535. attribute that is on an element other than <literal>name</literal>,
  536. <literal>nsName</literal> or <literal>value</literal> is
  537. removed.</para>
  538. <note><para>The value of the <literal>ns</literal> attribute is
  539. <emphasis role="strong">not</emphasis> transformed either by escaping
  540. disallowed characters, or in any other way, because the value of the
  541. <literal>ns</literal> attribute is compared against namespace URIs in
  542. the instance, which are not subject to any
  543. transformation.</para></note>
  544. <note><para>Since <literal>include</literal> and
  545. <literal>externalRef</literal> elements are resolved after
  546. <literal>datatypeLibrary</literal> attributes are added but before
  547. <literal>ns</literal> attributes are added, <literal>ns</literal>
  548. attributes are inherited into external schemas but
  549. <literal>datatypeLibrary</literal> attributes are not.</para></note>
  550. </section>
  551. <section>
  552. <title>QNames</title>
  553. <para>For any <literal>name</literal> element containing a prefix, the
  554. prefix is removed and an <literal>ns</literal> attribute is added
  555. replacing any existing <literal>ns</literal> attribute. The value of
  556. the added <literal>ns</literal> attribute is the value to which the
  557. namespace map of the context of the <literal>name</literal> element
  558. maps the prefix. The context must have a mapping for the
  559. prefix.</para>
  560. </section>
  561. <section>
  562. <title><literal>div</literal> element</title>
  563. <para>Each <literal>div</literal> element is replaced by its
  564. children.</para>
  565. </section>
  566. <section id="number-child-elements">
  567. <title>Number of child elements</title>
  568. <para>A <literal>define</literal>, <literal>oneOrMore</literal>,
  569. <literal>zeroOrMore</literal>, <literal>optional</literal>, <literal>list</literal> or
  570. <literal>mixed</literal> element is transformed so that it has exactly
  571. one child element. If it has more than one child element, then its
  572. child elements are wrapped in a <literal>group</literal>
  573. element. Similarly, an <literal>element</literal> element is transformed so
  574. that it has exactly two child elements, the first being a name class
  575. and the second being a pattern. If it has more than two child elements,
  576. then the child elements other than the first are wrapped in a
  577. <literal>group</literal> element.</para>
  578. <para>A <literal>except</literal> element is transformed
  579. so that it has exactly one child element. If it has more
  580. than one child element, then its child elements are wrapped
  581. in a <literal>choice</literal> element.</para>
  582. <para>If an <literal>attribute</literal> element has only one child
  583. element (a name class), then a <literal>text</literal> element is
  584. added.</para>
  585. <para>A <literal>choice</literal>, <literal>group</literal> or
  586. <literal>interleave</literal> element is transformed so that it has
  587. exactly two child elements. If it has one child element, then it is
  588. replaced by its child element. If it has more than two child
  589. elements, then the first two child elements are combined into a new
  590. element with the same name as the parent element and with the first
  591. two child elements as its children. For example,</para>
  592. <programlisting>&lt;choice&gt; <replaceable>p1</replaceable> <replaceable>p2</replaceable> <replaceable>p3</replaceable> &lt;/choice&gt;</programlisting>
  593. <para>is transformed to</para>
  594. <programlisting>&lt;choice&gt; &lt;choice&gt; <replaceable>p1</replaceable> <replaceable>p2</replaceable> &lt;/choice&gt; <replaceable>p3</replaceable> &lt;/choice&gt;</programlisting>
  595. <para>This reduces the number of child elements by one. The
  596. transformation is applied repeatedly until there are exactly two child
  597. elements.</para>
  598. </section>
  599. <section>
  600. <title><literal>mixed</literal> element</title>
  601. <para>A <literal>mixed</literal> element is transformed into an
  602. interleaving with a <literal>text</literal> element:</para>
  603. <programlisting>&lt;mixed> <replaceable>p</replaceable> &lt;/mixed></programlisting>
  604. <para>is transformed into</para>
  605. <programlisting>&lt;interleave> <replaceable>p</replaceable> &lt;text/> &lt;/interleave></programlisting>
  606. </section>
  607. <section>
  608. <title><literal>optional</literal> element</title>
  609. <para>An <literal>optional</literal> element is transformed into
  610. a choice with <literal>empty</literal>:</para>
  611. <programlisting>&lt;optional> <replaceable>p</replaceable> &lt;/optional></programlisting>
  612. <para>is transformed into</para>
  613. <programlisting>&lt;choice> <replaceable>p</replaceable> &lt;empty/> &lt;/choice></programlisting>
  614. </section>
  615. <section>
  616. <title><literal>zeroOrMore</literal> element</title>
  617. <para>A <literal>zeroOrMore</literal> element is transformed into a choice
  618. between <literal>oneOrMore</literal> and
  619. <literal>empty</literal>:</para>
  620. <programlisting>&lt;zeroOrMore> <replaceable>p</replaceable> &lt;/zeroOrMore></programlisting>
  621. <para>is transformed into</para>
  622. <programlisting>&lt;choice> &lt;oneOrMore> <replaceable>p</replaceable> &lt;/oneOrMore> &lt;empty/> &lt;/choice></programlisting>
  623. </section>
  624. <section id="constraints">
  625. <title>Constraints</title>
  626. <para>In this rule, no transformation is performed, but various
  627. constraints are checked.</para>
  628. <note><para>The constraints in this section, unlike the constraints
  629. specified in <xref linkend="restriction"/>, can be checked without
  630. resolving any <literal>ref</literal> elements, and are accordingly
  631. applied even to patterns that will disappear during later stages of
  632. simplification because they are not reachable (see <xref
  633. linkend="define-ref"/>) or because of <literal>notAllowed</literal>
  634. (see <xref linkend="notAllowed"/>).</para></note>
  635. <para>An <literal>except</literal> element that is a child of an
  636. <literal>anyName</literal> element must not have any
  637. <literal>anyName</literal> descendant elements. An
  638. <literal>except</literal> element that is a child of an
  639. <literal>nsName</literal> element must not have any
  640. <literal>nsName</literal> or <literal>anyName</literal> descendant
  641. elements.</para>
  642. <para>A <literal>name</literal> element that occurs as the first child
  643. of an <literal>attribute</literal> element or as the descendant of the
  644. first child of an <literal>attribute</literal> element and that has an
  645. <literal>ns</literal> attribute with value equal to the empty string
  646. must not have content equal to <literal>xmlns</literal>.</para>
  647. <para>A <literal>name</literal> or <literal>nsName</literal> element
  648. that occurs as the first child of an <literal>attribute</literal>
  649. element or as the descendant of the first child of an
  650. <literal>attribute</literal> element must not have an
  651. <literal>ns</literal> attribute with value
  652. <literal>http://www.w3.org/2000/xmlns</literal>.</para>
  653. <note><para>The <xref linkend="infoset"/> defines the namespace URI of
  654. namespace declaration attributes to be
  655. <literal>http://www.w3.org/2000/xmlns</literal>.</para></note>
  656. <para>A <literal>data</literal> or <literal>value</literal> element
  657. must be correct in its use of datatypes. Specifically, the
  658. <literal>type</literal> attribute must identify a datatype within the
  659. datatype library identified by the value of the
  660. <literal>datatypeLibrary</literal> attribute. For a
  661. <literal>data</literal> element, the parameter list must be one that
  662. is allowed by the datatype (see <xref
  663. linkend="data-pattern"/>).</para>
  664. </section>
  665. <section>
  666. <title><literal>combine</literal> attribute</title>
  667. <para>For each <literal>grammar</literal> element, all
  668. <literal>define</literal> elements with the same name are combined
  669. together. For any name, there must not be more than one
  670. <literal>define</literal> element with that name that does not have a
  671. <literal>combine</literal> attribute. For any name, if there is a
  672. <literal>define</literal> element with that name that has a
  673. <literal>combine</literal> attribute with the value
  674. <literal>choice</literal>, then there must not also be a
  675. <literal>define</literal> element with that name that has a
  676. <literal>combine</literal> attribute with the value
  677. <literal>interleave</literal>. Thus, for any name, if there is more
  678. than one <literal>define</literal> element with that name, then there
  679. is a unique value for the <literal>combine</literal> attribute for
  680. that name. After determining this unique value, the
  681. <literal>combine</literal> attributes are removed. A pair of
  682. definitions</para>
  683. <programlisting>&lt;define name="<replaceable>n</replaceable>"&gt;
  684. <replaceable>p1</replaceable>
  685. &lt;/define>
  686. &lt;define name="<replaceable>n</replaceable>"&gt;
  687. <replaceable>p2</replaceable>
  688. &lt;/define></programlisting>
  689. <para>is combined into</para>
  690. <programlisting>&lt;define name="<replaceable>n</replaceable>">
  691. &lt;<replaceable>c</replaceable>&gt;
  692. <replaceable>p1</replaceable>
  693. <replaceable>p2</replaceable>
  694. &lt;/<replaceable>c</replaceable>&gt;
  695. &lt;/define></programlisting>
  696. <para>where <replaceable>c</replaceable> is the value of the
  697. <literal>combine</literal> attribute. Pairs of definitions are
  698. combined until there is exactly one <literal>define</literal> element
  699. for each name.</para>
  700. <para>Similarly, for each <literal>grammar</literal> element all
  701. <literal>start</literal> elements are combined together. There must
  702. not be more than one <literal>start</literal> element that does not
  703. have a <literal>combine</literal> attribute. If there is a
  704. <literal>start</literal> element that has a <literal>combine</literal>
  705. attribute with the value <literal>choice</literal>, there must not
  706. also be a <literal>start</literal> element that has a
  707. <literal>combine</literal> attribute with the value
  708. <literal>interleave</literal>.</para>
  709. </section>
  710. <section>
  711. <title><literal>grammar</literal> element</title>
  712. <para>In this rule, the schema is transformed so that its top-level
  713. element is <literal>grammar</literal> and so that it has no other
  714. <literal>grammar</literal> elements.</para>
  715. <para>Define the <firstterm>in-scope grammar</firstterm> for an
  716. element to be the nearest ancestor <literal>grammar</literal> element. A
  717. <literal>ref</literal> element <firstterm>refers to</firstterm> a
  718. <literal>define</literal> element if the value of their
  719. <literal>name</literal> attributes is the same and their in-scope
  720. grammars are the same. A <literal>parentRef</literal> element
  721. <firstterm>refers to</firstterm> a <literal>define</literal> element
  722. if the value of their <literal>name</literal> attributes is the same
  723. and the in-scope grammar of the in-scope grammar of the
  724. <literal>parentRef</literal> element is the same as the in-scope
  725. grammar of the <literal>define</literal> element. Every
  726. <literal>ref</literal> or <literal>parentRef</literal> element must
  727. refer to a <literal>define</literal> element. A
  728. <literal>grammar</literal> must have a <literal>start</literal> child
  729. element.</para>
  730. <para>First, transform the top-level pattern
  731. <replaceable>p</replaceable> into
  732. <literal>&lt;grammar>&lt;start><replaceable>p</replaceable>&lt;/start>&lt;/grammar></literal>.
  733. Next, rename <literal>define</literal> elements so that no two
  734. <literal>define</literal> elements anywhere in the schema have the
  735. same name. To rename a <literal>define</literal> element, change the
  736. value of its <literal>name</literal> attribute and change the value of
  737. the <literal>name</literal> attribute of all <literal>ref</literal>
  738. and <literal>parentRef</literal> elements that refer to that
  739. <literal>define</literal> element. Next, move all
  740. <literal>define</literal> elements to be children of the top-level
  741. <literal>grammar</literal> element, replace each nested
  742. <literal>grammar</literal> element by the child of its
  743. <literal>start</literal> element and rename each
  744. <literal>parentRef</literal> element to <literal>ref</literal>.</para>
  745. </section>
  746. <section id="define-ref">
  747. <title><literal>define</literal> and <literal>ref</literal> elements</title>
  748. <para>In this rule, the grammar is transformed so that every
  749. <literal>element</literal> element is the child of a
  750. <literal>define</literal> element, and the child of every
  751. <literal>define</literal> element is an <literal>element</literal>
  752. element.</para>
  753. <para>First, remove any <literal>define</literal> element that is not
  754. <firstterm>reachable</firstterm>. A <literal>define</literal> element
  755. is reachable if there is reachable <literal>ref</literal> element
  756. referring to it. A <literal>ref</literal> element is reachable if it
  757. is the descendant of the <literal>start</literal> element or of a
  758. reachable <literal>define</literal> element. Now, for
  759. each <literal>element</literal> element that is not the child of a
  760. <literal>define</literal> element, add a <literal>define</literal>
  761. element to the <literal>grammar</literal> element, and replace the
  762. <literal>element</literal> element by a <literal>ref</literal> element
  763. referring to the added <literal>define</literal> element. The value of
  764. the <literal>name</literal> attribute of the added
  765. <literal>define</literal> element must be different from value of the
  766. <literal>name</literal> attribute of all other
  767. <literal>define</literal> elements. The child of the added
  768. <literal>define</literal> element is the <literal>element</literal>
  769. element.</para>
  770. <para>Define a <literal>ref</literal> element to be
  771. <firstterm>expandable</firstterm> if it refers to a
  772. <literal>define</literal> element whose child is not an
  773. <literal>element</literal> element. For each <literal>ref</literal>
  774. element that is expandable and is a descendant of a
  775. <literal>start</literal> element or an <literal>element</literal>
  776. element, expand it by replacing the <literal>ref</literal> element by
  777. the child of the <literal>define</literal> element to which it refers and
  778. then recursively expanding any expandable <literal>ref</literal>
  779. elements in this replacement. This must not result in a loop.
  780. In other words expanding the replacement of a
  781. <literal>ref</literal> element having a <literal>name</literal> with
  782. value <replaceable>n</replaceable> must not require the expansion of
  783. <literal>ref</literal> element also having a <literal>name</literal>
  784. with value <replaceable>n</replaceable>. Finally, remove any
  785. <literal>define</literal> element whose child is not an
  786. <literal>element</literal> element.</para>
  787. </section>
  788. <section id="notAllowed">
  789. <title><literal>notAllowed</literal> element</title>
  790. <para>In this rule, the grammar is transformed so that a
  791. <literal>notAllowed</literal> element occurs only as the child of
  792. a <literal>start</literal> or <literal>element</literal> element. An
  793. <literal>attribute</literal>, <literal>list</literal>,
  794. <literal>group</literal>, <literal>interleave</literal>,
  795. or <literal>oneOrMore</literal> element that has a
  796. <literal>notAllowed</literal> child element is transformed into a
  797. <literal>notAllowed</literal> element. A <literal>choice</literal>
  798. element that has two <literal>notAllowed</literal> child elements is
  799. transformed into a <literal>notAllowed</literal> element. A
  800. <literal>choice</literal> element that has one
  801. <literal>notAllowed</literal> child element is transformed into its
  802. other child element. An <literal>except</literal> element that has a
  803. <literal>notAllowed</literal> child element is removed.
  804. The preceding transformations are applied
  805. repeatedly until none of them is applicable any more.
  806. Any <literal>define</literal> element that is no longer reachable
  807. is removed.</para>
  808. </section>
  809. <section>
  810. <title><literal>empty</literal> element</title>
  811. <para>In this rule, the grammar is transformed so that an
  812. <literal>empty</literal> element does not occur as a child of a
  813. <literal>group</literal>, <literal>interleave</literal>, or
  814. <literal>oneOrMore</literal> element or as the second child of
  815. a <literal>choice</literal> element. A <literal>group</literal>,
  816. <literal>interleave</literal> or <literal>choice</literal> element
  817. that has two <literal>empty</literal> child elements is transformed
  818. into an <literal>empty</literal> element. A <literal>group</literal>
  819. or <literal>interleave</literal> element that has one
  820. <literal>empty</literal> child element is transformed into its other
  821. child element. A <literal>choice</literal> element whose
  822. second child element is an <literal>empty</literal> element is
  823. transformed by interchanging its two child elements. A
  824. <literal>oneOrMore</literal> element that has an
  825. <literal>empty</literal> child element is transformed into an
  826. <literal>empty</literal> element. The preceding transformations are applied
  827. repeatedly until none of them is applicable any more.</para>
  828. </section>
  829. </section>
  830. <section id="simple-syntax">
  831. <title>Simple syntax</title>
  832. <para>After applying all the rules in <xref
  833. linkend="simplification"/>, the schema will match the following
  834. grammar:</para>
  835. <grammarref src="simple.rng"/>
  836. <para>With this grammar, no elements or attributes are allowed other
  837. than those explicitly shown.</para>
  838. <section id="simple-syntax-example">
  839. <title>Example</title>
  840. <para>The following is an example of how the schema in <xref
  841. linkend="full-syntax-example"/> can be transformed into the simple
  842. syntax:</para>
  843. <programlisting><![CDATA[<?xml version="1.0"?>
  844. <grammar xmlns="http://relaxng.org/ns/structure/1.0">
  845. <start>
  846. <ref name="foo.element"/>
  847. </start>
  848. <define name="foo.element">
  849. <element>
  850. <name ns="">foo</name>
  851. <group>
  852. <ref name="bar1.element"/>
  853. <ref name="bar2.element"/>
  854. </group>
  855. </element>
  856. </define>
  857. <define name="bar1.element">
  858. <element>
  859. <name ns="http://www.example.com/n1">bar1</name>
  860. <empty/>
  861. </element>
  862. </define>
  863. <define name="bar2.element">
  864. <element>
  865. <name ns="http://www.example.com/n2">bar2</name>
  866. <empty/>
  867. </element>
  868. </define>
  869. </grammar>]]></programlisting>
  870. <note><para>Strictly speaking, the result of simplification is an
  871. instance of the data model rather than an XML document. For
  872. convenience, we use an XML document to represent an instance of the
  873. data model.</para></note>
  874. </section>
  875. </section>
  876. <section id="semantics">
  877. <title>Semantics</title>
  878. <para>In this section, we define the semantics of a correct RELAX NG
  879. schema that has been transformed into the simple syntax. The
  880. semantics of a RELAX NG schema consist of a specification of what XML
  881. documents are valid with respect to that schema. The semantics are
  882. described formally. The formalism uses axioms and inference rules.
  883. Axioms are propositions that are provable unconditionally. An
  884. inference rule consists of one or more antecedents and exactly one
  885. consequent. An antecedent is either positive or negative. If all the
  886. positive antecedents of an inference rule are provable and none of the
  887. negative antecedents are provable, then the consequent of the
  888. inference rule is provable. An XML document is valid with respect to a
  889. RELAX NG schema if and only if the proposition that it is valid is
  890. provable in the formalism specified in this section.</para>
  891. <note><para>This kind of formalism is similar to a proof system.
  892. However, a traditional proof system only has positive
  893. antecedents.</para></note>
  894. <para>The notation for inference rules separates the antecedents from
  895. the consequent by a horizontal line: the antecedents are above the
  896. line; the consequent is below the line. If an antecedent is of the
  897. form not(<replaceable>p</replaceable>), then it is a negative
  898. antecedent; otherwise, it is a positive antecedent. Both axioms and
  899. inferences
  900. rules may use variables. A variable has a name and optionally a
  901. subscript. The name of a variable is italicized. Each variable has a
  902. range that is determined by its name. Axioms and inference rules are
  903. implicitly universally quantified over the variables they contain. We
  904. explain this further below.</para>
  905. <para>The possibility that an inference rule or axiom may contain more
  906. than one occurrence of a particular variable requires that an identity
  907. relation be defined on each kind of object over which a variable can
  908. range. The identity relation for all kinds of object is value-based.
  909. Two objects of a particular kind are identical if the constituents of
  910. the objects are identical. For example, two attributes are considered
  911. the same if they have the same name and the same value. Two characters
  912. are identical if their Unicode character codes are the same.</para>
  913. <section id="name-classes">
  914. <title>Name classes</title>
  915. <para>The main semantic concept for name classes is that of a name
  916. belonging to a name class. A name class is an element that matches the
  917. production nameClass. A name is as defined in <xref
  918. linkend="data-model"/>: it consists of a namespace URI and a local
  919. name.</para>
  920. <para>We use the following notation:</para>
  921. <variablelist>
  922. <varlistentry><term><p:var range="name"/></term><listitem><para>is a variable
  923. that ranges over names</para></listitem></varlistentry>
  924. <varlistentry><term><p:var range="nameClass"/></term><listitem><para>ranges over name classes</para></listitem></varlistentry>
  925. <varlistentry><term><p:judgement name="belongs">
  926. <p:var range="name"/>
  927. <p:var range="nameClass"/>
  928. </p:judgement></term><listitem><para>
  929. asserts that name <p:var range="name"/> is a member of name class <p:var range="nameClass"/>
  930. </para></listitem></varlistentry>
  931. </variablelist>
  932. <para>We are now ready for our first axiom, which is called "anyName
  933. 1":</para>
  934. <p:proofSystem>
  935. <p:rule name="anyName 1">
  936. <p:judgement name="belongs">
  937. <p:var range="name"/>
  938. <p:element name="anyName"/>
  939. </p:judgement>
  940. </p:rule>
  941. </p:proofSystem>
  942. <para>This says for any name <p:var range="name"/>, <p:var
  943. range="name"/> belongs to the name class <p:element name="anyName"/>,
  944. in other words <p:element name="anyName"/> matches any name. Note the
  945. effect of the implicit universal quantification over the variables in
  946. the axiom: this is what makes the axiom apply for any name <p:var
  947. range="name"/>.</para>
  948. <para>Our first inference rule is almost as simple:</para>
  949. <p:proofSystem>
  950. <p:rule name="anyName 2">
  951. <p:not>
  952. <p:judgement name="belongs">
  953. <p:var range="name"/>
  954. <p:var range="nameClass"/>
  955. </p:judgement>
  956. </p:not>
  957. <p:judgement name="belongs">
  958. <p:var range="name"/>
  959. <p:element name="anyName">
  960. <p:element name="except">
  961. <p:var range="nameClass"/>
  962. </p:element>
  963. </p:element>
  964. </p:judgement>
  965. </p:rule>
  966. </p:proofSystem>
  967. <para>This says that for any name <p:var range="name"/>
  968. and for any name class <p:var range="nameClass"/>,
  969. if <p:var range="name"/> does not belong to <p:var range="nameClass"/>,
  970. then <p:var range="name"/> belongs to
  971. <p:element name="anyName">
  972. <p:element name="except">
  973. <p:var range="nameClass"/>
  974. </p:element>
  975. </p:element>. In other words, <p:element name="anyName">
  976. <p:element name="except">
  977. <p:var range="nameClass"/>
  978. </p:element>
  979. </p:element> matches any name that does not match <p:var range="nameClass"/>.</para>
  980. <para>We now need the following additional notation:</para>
  981. <variablelist>
  982. <varlistentry><term><p:var range="ncname"/></term>
  983. <listitem><para>ranges over local names; a local name is a string that
  984. matches the NCName production of <xref linkend="xml-names"/>, that is,
  985. a name with no colons</para></listitem>
  986. </varlistentry>
  987. <varlistentry><term><p:var range="uri"/></term><listitem><para>ranges over URIs</para></listitem></varlistentry>
  988. <varlistentry>
  989. <term>
  990. <p:function name="name">
  991. <p:var range="uri"/>
  992. <p:var range="ncname"/>
  993. </p:function>
  994. </term>
  995. <listitem><para>constructs a name with URI <p:var range="uri"/> and local
  996. name <p:var range="ncname"/></para></listitem>
  997. </varlistentry>
  998. </variablelist>
  999. <para>The remaining axioms and inference rules for name classes are as
  1000. follows:</para>
  1001. <p:proofSystem>
  1002. <p:rule name="nsName 1">
  1003. <p:judgement name="belongs">
  1004. <p:function name="name">
  1005. <p:var range="uri"/>
  1006. <p:var range="ncname"/>
  1007. </p:function>
  1008. <p:element name="nsName">
  1009. <p:attribute name="ns">
  1010. <p:var range="uri"/>
  1011. </p:attribute>
  1012. </p:element>
  1013. </p:judgement>
  1014. </p:rule>
  1015. <p:rule name="nsName 2">
  1016. <p:not>
  1017. <p:judgement name="belongs">
  1018. <p:function name="name">
  1019. <p:var range="uri"/>
  1020. <p:var range="ncname"/>
  1021. </p:function>
  1022. <p:var range="nameClass"/>
  1023. </p:judgement>
  1024. </p:not>
  1025. <p:judgement name="belongs">
  1026. <p:function name="name">
  1027. <p:var range="uri"/>
  1028. <p:var range="ncname"/>
  1029. </p:function>
  1030. <p:element name="nsName">
  1031. <p:attribute name="ns">
  1032. <p:var range="uri"/>
  1033. </p:attribute>
  1034. <p:element name="except">
  1035. <p:var range="nameClass"/>
  1036. </p:element>
  1037. </p:element>
  1038. </p:judgement>
  1039. </p:rule>
  1040. <p:rule name="name">
  1041. <p:judgement name="belongs">
  1042. <p:function name="name">
  1043. <p:var range="uri"/>
  1044. <p:var range="ncname"/>
  1045. </p:function>
  1046. <p:element name="name">
  1047. <p:attribute name="ns">
  1048. <p:var range="uri"/>
  1049. </p:attribute>
  1050. <p:var range="ncname"/>
  1051. </p:element>
  1052. </p:judgement>
  1053. </p:rule>
  1054. <p:rule name="name choice 1">
  1055. <p:judgement name="belongs">
  1056. <p:var range="name"/>
  1057. <p:var range="nameClass" sub="1"/>
  1058. </p:judgement>
  1059. <p:judgement name="belongs">
  1060. <p:var range="name"/>
  1061. <p:element name="choice">
  1062. <p:var range="nameClass" sub="1"/>
  1063. <p:var range="nameClass" sub="2"/>
  1064. </p:element>
  1065. </p:judgement>
  1066. </p:rule>
  1067. <p:rule name="name choice 2">
  1068. <p:judgement name="belongs">
  1069. <p:var range="name"/>
  1070. <p:var range="nameClass" sub="2"/>
  1071. </p:judgement>
  1072. <p:judgement name="belongs">
  1073. <p:var range="name"/>
  1074. <p:element name="choice">
  1075. <p:var range="nameClass" sub="1"/>
  1076. <p:var range="nameClass" sub="2"/>
  1077. </p:element>
  1078. </p:judgement>
  1079. </p:rule>
  1080. </p:proofSystem>
  1081. </section>
  1082. <section>
  1083. <title>Patterns</title>
  1084. <para>The axioms and inference rules for patterns use the following
  1085. notation:</para>
  1086. <variablelist>
  1087. <varlistentry><term><p:var range="context"/></term><listitem><para>ranges
  1088. over contexts (as defined in <xref
  1089. linkend="data-model"/>)</para></listitem></varlistentry>
  1090. <varlistentry><term><p:var range="att"/></term><listitem><para>ranges over
  1091. sets of attributes; a set with a single member
  1092. is considered the same as that member</para></listitem></varlistentry>
  1093. <varlistentry><term><p:var
  1094. range="mixed"/></term><listitem><para>ranges over sequences of
  1095. elements and strings; a sequence with a single member is considered
  1096. the same as that member; the sequences ranged over by <p:var
  1097. range="mixed"/> may contain consecutive strings and may contain strings
  1098. that are empty; thus, there are sequences ranged over by <p:var
  1099. range="mixed"/> that cannot occur as the children of an
  1100. element</para></listitem></varlistentry>
  1101. <varlistentry><term><p:var range="pattern"/></term><listitem><para>ranges
  1102. over patterns (elements matching the pattern
  1103. production)</para></listitem></varlistentry>
  1104. <varlistentry><term><p:judgement name="match">
  1105. <p:var range="context"/>
  1106. <p:var range="att"/>
  1107. <p:var range="mixed"/>
  1108. <p:var range="pattern"/>
  1109. </p:judgement></term><listitem><para>
  1110. asserts that with respect to context <p:var range="context"/>, the
  1111. attributes <p:var range="att"/> and the sequence of elements and
  1112. strings <p:var range="mixed"/> matches the pattern <p:var
  1113. range="pattern"/></para></listitem></varlistentry>
  1114. </variablelist>
  1115. <section id="choice-pattern">
  1116. <title><literal>choice</literal> pattern</title>
  1117. <para>The semantics of the <literal>choice</literal> pattern are as follows:</para>
  1118. <p:proofSystem>
  1119. <p:rule name="choice 1">
  1120. <p:judgement name="match">
  1121. <p:var range="context"/>
  1122. <p:var range="att"/>
  1123. <p:var range="mixed"/>
  1124. <p:var range="pattern" sub="1"/>
  1125. </p:judgement>
  1126. <p:judgement name="match">
  1127. <p:var range="context"/>
  1128. <p:var range="att"/>
  1129. <p:var range="mixed"/>
  1130. <p:element name="choice">
  1131. <p:var range="pattern" sub="1"/>
  1132. <p:var range="pattern" sub="2"/>
  1133. </p:element>
  1134. </p:judgement>
  1135. </p:rule>
  1136. <p:rule name="choice 2">
  1137. <p:judgement name="match">
  1138. <p:var range="context"/>
  1139. <p:var range="att"/>
  1140. <p:var range="mixed"/>
  1141. <p:var range="pattern" sub="2"/>
  1142. </p:judgement>
  1143. <p:judgement name="match">
  1144. <p:var range="context"/>
  1145. <p:var range="att"/>
  1146. <p:var range="mixed"/>
  1147. <p:element name="choice">
  1148. <p:var range="pattern" sub="1"/>
  1149. <p:var range="pattern" sub="2"/>
  1150. </p:element>
  1151. </p:judgement>
  1152. </p:rule>
  1153. </p:proofSystem>
  1154. </section>
  1155. <section>
  1156. <title><literal>group</literal> pattern</title>
  1157. <para>We use the following additional notation:</para>
  1158. <variablelist>
  1159. <varlistentry><term><p:function name="append">
  1160. <p:var range="mixed" sub="1"/>
  1161. <p:var range="mixed" sub="2"/>
  1162. </p:function></term><listitem>
  1163. <para>represents the concatenation of the sequences <p:var range="mixed" sub="1"/> and <p:var range="mixed" sub="2"/>
  1164. </para></listitem></varlistentry>
  1165. <varlistentry><term><p:function name="union">
  1166. <p:var range="att" sub="1"/>
  1167. <p:var range="att" sub="2"/>
  1168. </p:function></term><listitem>
  1169. <para>represents the union of <p:var range="att" sub="1"/>
  1170. and <p:var range="att" sub="2"/></para>
  1171. </listitem>
  1172. </varlistentry>
  1173. </variablelist>
  1174. <para>The semantics of the <literal>group</literal> pattern are as follows:</para>
  1175. <p:proofSystem>
  1176. <p:rule name="group">
  1177. <p:judgement name="match">
  1178. <p:var range="context"/>
  1179. <p:var range="att" sub="1"/>
  1180. <p:var range="mixed" sub="1"/>
  1181. <p:var range="pattern" sub="1"/>
  1182. </p:judgement>
  1183. <p:judgement name="match">
  1184. <p:var range="context"/>
  1185. <p:var range="att" sub="2"/>
  1186. <p:var range="mixed" sub="2"/>
  1187. <p:var range="pattern" sub="2"/>
  1188. </p:judgement>
  1189. <p:judgement name="match">
  1190. <p:var range="context"/>
  1191. <p:function name="union">
  1192. <p:var range="att" sub="1"/>
  1193. <p:var range="att" sub="2"/>
  1194. </p:function>
  1195. <p:function name="append">
  1196. <p:var range="mixed" sub="1"/>
  1197. <p:var range="mixed" sub="2"/>
  1198. </p:function>
  1199. <p:element name="group">
  1200. <p:var range="pattern" sub="1"/>
  1201. <p:var range="pattern" sub="2"/>
  1202. </p:element>
  1203. </p:judgement>
  1204. </p:rule>
  1205. </p:proofSystem>
  1206. <note><para>The restriction in <xref linkend="attribute-restrictions"/>
  1207. ensures that the set of attributes constructed in the consequent will
  1208. not have multiple attributes with the same name.</para></note>
  1209. </section>
  1210. <section id="empty-pattern">
  1211. <title><literal>empty</literal> pattern</title>
  1212. <para>We use the following additional notation:</para>
  1213. <variablelist>
  1214. <varlistentry><term><p:function name="emptySequence"/></term><listitem><para>represents an empty sequence</para></listitem></varlistentry>
  1215. <varlistentry><term><p:function name="emptySet"/></term><listitem><para>represents an empty set</para></listitem></varlistentry>
  1216. </variablelist>
  1217. <para>The semantics of the <literal>empty</literal> pattern are as follows:</para>
  1218. <p:proofSystem>
  1219. <p:rule name="empty">
  1220. <p:judgement name="match">
  1221. <p:var range="context"/>
  1222. <p:function name="emptySet"/>
  1223. <p:function name="emptySequence"/>
  1224. <p:element name="empty"></p:element>
  1225. <p:function name="emptySet"/>
  1226. <p:function name="emptySet"/>
  1227. </p:judgement>
  1228. </p:rule>
  1229. </p:proofSystem>
  1230. </section>
  1231. <section id="text-pattern">
  1232. <title><literal>text</literal> pattern</title>
  1233. <para>We use the following additional notation:</para>
  1234. <variablelist>
  1235. <varlistentry><term><p:var range="string"/></term><listitem><para>ranges
  1236. over strings</para></listitem></varlistentry>
  1237. </variablelist>
  1238. <para>The semantics of the <literal>text</literal> pattern are as follows:</para>
  1239. <p:proofSystem>
  1240. <p:rule name="text 1">
  1241. <p:judgement name="match">
  1242. <p:var range="context"/>
  1243. <p:function name="emptySet"/>
  1244. <p:function name="emptySequence"/>
  1245. <p:element name="text"></p:element>
  1246. <p:function name="emptySet"/>
  1247. <p:function name="emptySet"/>
  1248. </p:judgement>
  1249. </p:rule>
  1250. <p:rule name="text 2">
  1251. <p:judgement name="match">
  1252. <p:var range="context"/>
  1253. <p:function name="emptySet"/>
  1254. <p:var range="mixed"/>
  1255. <p:element name="text"></p:element>
  1256. <p:function name="emptySet"/>
  1257. <p:function name="emptySet"/>
  1258. </p:judgement>
  1259. <p:judgement name="match">
  1260. <p:var range="context"/>
  1261. <p:function name="emptySet"/>
  1262. <p:function name="append">
  1263. <p:var range="mixed"/>
  1264. <p:var range="string"/>
  1265. </p:function>
  1266. <p:element name="text"></p:element>
  1267. <p:function name="emptySet"/>
  1268. <p:function name="emptySet"/>
  1269. </p:judgement>
  1270. </p:rule>
  1271. </p:proofSystem>
  1272. <para>The effect of the above rule is that a <literal>text</literal>
  1273. element matches zero or more strings.</para>
  1274. </section>
  1275. <section>
  1276. <title><literal>oneOrMore</literal> pattern</title>
  1277. <para>We use the following additional notation:</para>
  1278. <variablelist>
  1279. <varlistentry><term><p:judgement name="disjoint">
  1280. <p:var range="att" sub="1"/>
  1281. <p:var range="att" sub="2"/>
  1282. </p:judgement></term><listitem><para>
  1283. asserts that there is no name that is
  1284. the name of both an attribute in <p:var range="att" sub="1"/>
  1285. and of an attribute in <p:var range="att" sub="2"/>
  1286. </para></listitem></varlistentry>
  1287. </variablelist>
  1288. <para>The semantics of the <literal>oneOrMore</literal> pattern are as follows:</para>
  1289. <p:proofSystem>
  1290. <p:rule name="oneOrMore 1">
  1291. <p:judgement name="match">
  1292. <p:var range="context"/>
  1293. <p:var range="att"/>
  1294. <p:var range="mixed"/>
  1295. <p:var range="pattern"/>
  1296. </p:judgement>
  1297. <p:judgement name="match">
  1298. <p:var range="context"/>
  1299. <p:var range="att"/>
  1300. <p:var range="mixed"/>
  1301. <p:element name="oneOrMore">
  1302. <p:var range="pattern"/>
  1303. </p:element>
  1304. </p:judgement>
  1305. </p:rule>
  1306. <p:rule name="oneOrMore 2">
  1307. <p:judgement name="match">
  1308. <p:var range="context"/>
  1309. <p:var range="att" sub="1"/>
  1310. <p:var range="mixed" sub="1"/>
  1311. <p:var range="pattern"/>
  1312. </p:judgement>
  1313. <p:judgement name="match">
  1314. <p:var range="context"/>
  1315. <p:var range="att" sub="2"/>
  1316. <p:var range="mixed" sub="2"/>
  1317. <p:element name="oneOrMore">
  1318. <p:var range="pattern"/>
  1319. </p:element>
  1320. </p:judgement>
  1321. <p:judgement name="disjoint">
  1322. <p:var range="att" sub="1"/>
  1323. <p:var range="att" sub="2"/>
  1324. </p:judgement>
  1325. <p:judgement name="match">
  1326. <p:var range="context"/>
  1327. <p:function name="union">
  1328. <p:var range="att" sub="1"/>
  1329. <p:var range="att" sub="2"/>
  1330. </p:function>
  1331. <p:function name="append">
  1332. <p:var range="mixed" sub="1"/>
  1333. <p:var range="mixed" sub="2"/>
  1334. </p:function>
  1335. <p:element name="oneOrMore">
  1336. <p:var range="pattern"/>
  1337. </p:element>
  1338. </p:judgement>
  1339. </p:rule>
  1340. </p:proofSystem>
  1341. </section>
  1342. <section>
  1343. <title><literal>interleave</literal> pattern</title>
  1344. <para>We use the following additional notation:</para>
  1345. <variablelist>
  1346. <varlistentry><term><p:judgement name="interleave">
  1347. <p:var range="mixed" sub="1"/>
  1348. <p:var range="mixed" sub="2"/>
  1349. <p:var range="mixed" sub="3"/>
  1350. </p:judgement></term><listitem><para>
  1351. asserts that <p:var range="mixed" sub="1"/>
  1352. is an interleaving of <p:var range="mixed" sub="2"/>
  1353. and <p:var range="mixed" sub="3"/>
  1354. </para></listitem></varlistentry>
  1355. </variablelist>
  1356. <para>The semantics of interleaving are defined by the following rules.</para>
  1357. <p:proofSystem>
  1358. <p:rule name="interleaves 1">
  1359. <p:judgement name="interleave">
  1360. <p:function name="emptySequence"/>
  1361. <p:function name="emptySequence"/>
  1362. <p:function name="emptySequence"/>
  1363. </p:judgement>
  1364. </p:rule>
  1365. <p:rule name="interleaves 2">
  1366. <p:judgement name="interleave">
  1367. <p:var range="mixed" sub="1"/>
  1368. <p:var range="mixed" sub="2"/>
  1369. <p:var range="mixed" sub="3"/>
  1370. </p:judgement>
  1371. <p:judgement name="interleave">
  1372. <p:function name="append">
  1373. <p:var range="mixed" sub="4"/>
  1374. <p:var range="mixed" sub="1"/>
  1375. </p:function>
  1376. <p:function name="append">
  1377. <p:var range="mixed" sub="4"/>
  1378. <p:var range="mixed" sub="2"/>
  1379. </p:function>
  1380. <p:var range="mixed" sub="3"/>
  1381. </p:judgement>
  1382. </p:rule>
  1383. <p:rule name="interleaves 3">
  1384. <p:judgement name="interleave">
  1385. <p:var range="mixed" sub="1"/>
  1386. <p:var range="mixed" sub="2"/>
  1387. <p:var range="mixed" sub="3"/>
  1388. </p:judgement>
  1389. <p:judgement name="interleave">
  1390. <p:function name="append">
  1391. <p:var range="mixed" sub="4"/>
  1392. <p:var range="mixed" sub="1"/>
  1393. </p:function>
  1394. <p:var range="mixed" sub="2"/>
  1395. <p:function name="append">
  1396. <p:var range="mixed" sub="4"/>
  1397. <p:var range="mixed" sub="3"/>
  1398. </p:function>
  1399. </p:judgement>
  1400. </p:rule>
  1401. </p:proofSystem>
  1402. <para>For example, the interleavings of
  1403. <literal><![CDATA[<a/><a/>]]></literal> and
  1404. <literal><![CDATA[<b/>]]></literal> are
  1405. <literal><![CDATA[<a/><a/><b/>]]></literal>,
  1406. <literal><![CDATA[<a/><b/><a/>]]></literal>, and
  1407. <literal><![CDATA[<b/><a/><a/>]]></literal>.</para>
  1408. <para>The semantics of the <literal>interleave</literal> pattern are
  1409. as follows:</para>
  1410. <p:proofSystem>
  1411. <p:rule name="interleave">
  1412. <p:judgement name="match">
  1413. <p:var range="context"/>
  1414. <p:var range="att" sub="1"/>
  1415. <p:var range="mixed" sub="1"/>
  1416. <p:var range="pattern" sub="1"/>
  1417. </p:judgement>
  1418. <p:judgement name="match">
  1419. <p:var range="context"/>
  1420. <p:var range="att" sub="2"/>
  1421. <p:var range="mixed" sub="2"/>
  1422. <p:var range="pattern" sub="2"/>
  1423. </p:judgement>
  1424. <p:judgement name="interleave">
  1425. <p:var range="mixed" sub="3"/>
  1426. <p:var range="mixed" sub="1"/>
  1427. <p:var range="mixed" sub="2"/>
  1428. </p:judgement>
  1429. <p:judgement name="match">
  1430. <p:var range="context"/>
  1431. <p:function name="union">
  1432. <p:var range="att" sub="1"/>
  1433. <p:var range="att" sub="2"/>
  1434. </p:function>
  1435. <p:var range="mixed" sub="3"/>
  1436. <p:element name="interleave">
  1437. <p:var range="pattern" sub="1"/>
  1438. <p:var range="pattern" sub="2"/>
  1439. </p:element>
  1440. </p:judgement>
  1441. </p:rule>
  1442. </p:proofSystem>
  1443. <note><para>The restriction in <xref linkend="attribute-restrictions"/>
  1444. ensures that the set of attributes constructed in the consequent will
  1445. not have multiple attributes with the same name.</para></note>
  1446. </section>
  1447. <section id="element-pattern">
  1448. <title><literal>element</literal> and <literal>attribute</literal> pattern</title>
  1449. <para>The value of an attribute is always a single string, which may
  1450. be empty. Thus, the empty sequence is not a possible attribute value.
  1451. On the hand, the children of an element can be an empty sequence and
  1452. cannot consist of an empty string. In order to ensure that validation
  1453. handles attributes and elements consistently, we introduce a variant
  1454. of matching called <firstterm>weak matching</firstterm>. Weak
  1455. matching is used when matching the pattern for the value of an
  1456. attribute or for the attributes and children of an element. We use
  1457. the following notation to define weak matching.</para>
  1458. <variablelist>
  1459. <varlistentry><term><p:function
  1460. name="emptyString"/></term><listitem><para>represents an empty
  1461. string</para></listitem></varlistentry>
  1462. <varlistentry><term><p:var
  1463. range="whiteSpace"/></term><listitem><para>ranges over the empty
  1464. sequence and strings that consist entirely of
  1465. whitespace</para></listitem></varlistentry>
  1466. <varlistentry><term><p:judgement name="weakMatch">
  1467. <p:var range="context"/>
  1468. <p:var range="att"/>
  1469. <p:var range="mixed"/>
  1470. <p:var range="pattern"/>
  1471. </p:judgement></term><listitem><para>
  1472. asserts that with respect to context <p:var range="context"/>, the
  1473. attributes <p:var range="att"/> and the sequence of elements and
  1474. strings <p:var range="mixed"/> weakly matches the pattern <p:var
  1475. range="pattern"/></para></listitem></varlistentry>
  1476. </variablelist>
  1477. <para>The semantics of weak matching are as follows:</para>
  1478. <p:proofSystem>
  1479. <p:rule name="weak match 1">
  1480. <p:judgement name="match">
  1481. <p:var range="context"/>
  1482. <p:var range="att"/>
  1483. <p:var range="mixed"/>
  1484. <p:var range="pattern"/>
  1485. </p:judgement>
  1486. <p:judgement name="weakMatch">
  1487. <p:var range="context"/>
  1488. <p:var range="att"/>
  1489. <p:var range="mixed"/>
  1490. <p:var range="pattern"/>
  1491. </p:judgement>
  1492. </p:rule>
  1493. <p:rule name="weak match 2">
  1494. <p:judgement name="match">
  1495. <p:var range="context"/>
  1496. <p:var range="att"/>
  1497. <p:function name="emptySequence"/>
  1498. <p:var range="pattern"/>
  1499. </p:judgement>
  1500. <p:judgement name="weakMatch">
  1501. <p:var range="context"/>
  1502. <p:var range="att"/>
  1503. <p:var range="whiteSpace"/>
  1504. <p:var range="pattern"/>
  1505. </p:judgement>
  1506. </p:rule>
  1507. <p:rule name="weak match 3">
  1508. <p:judgement name="match">
  1509. <p:var range="context"/>
  1510. <p:var range="att"/>
  1511. <p:function name="emptyString"/>
  1512. <p:var range="pattern"/>
  1513. </p:judgement>
  1514. <p:judgement name="weakMatch">
  1515. <p:var range="context"/>
  1516. <p:var range="att"/>
  1517. <p:function name="emptySequence"/>
  1518. <p:var range="pattern"/>
  1519. </p:judgement>
  1520. </p:rule>
  1521. </p:proofSystem>
  1522. <para>We use the following additional notation:</para>
  1523. <variablelist>
  1524. <varlistentry><term><p:function name="attribute">
  1525. <p:var range="name"/>
  1526. <p:var range="string"/>
  1527. </p:function></term><listitem><para>
  1528. constructs an attribute with name <p:var range="name"/>
  1529. and value <p:var range="string"/>
  1530. </para></listitem></varlistentry>
  1531. <varlistentry><term><p:function name="element">
  1532. <p:var range="name"/>
  1533. <p:var range="context"/>
  1534. <p:var range="att"/>
  1535. <p:var range="mixed"/>
  1536. </p:function></term><listitem><para>
  1537. constructs an element with name <p:var range="name"/>,
  1538. context <p:var range="context"/>,
  1539. attributes <p:var range="att"/>
  1540. and mixed sequence <p:var range="mixed"/> as children
  1541. </para></listitem></varlistentry>
  1542. <varlistentry><term><p:judgement name="okAsChildren">
  1543. <p:var range="mixed"/>
  1544. </p:judgement></term><listitem><para>
  1545. asserts that the mixed sequence <p:var range="mixed"/> can occur as
  1546. the children of an element: it does not contain any member that is an
  1547. empty string, nor does it contain two consecutive members that are
  1548. both strings</para></listitem></varlistentry>
  1549. <varlistentry><term><p:judgement name="bind">
  1550. <p:var range="ncname"/>
  1551. <p:var range="nameClass"/>
  1552. <p:var range="pattern"/>
  1553. </p:judgement></term><listitem><para>
  1554. asserts that the grammar contains
  1555. <p:element name="define">
  1556. <p:attribute name="name">
  1557. <p:var range="ncname"/>
  1558. </p:attribute>
  1559. <p:element name="element">
  1560. <p:var range="nameClass"/>
  1561. <p:var range="pattern"/>
  1562. </p:element>
  1563. </p:element>
  1564. </para></listitem></varlistentry>
  1565. </variablelist>
  1566. <para>The semantics of the <literal>attribute</literal> pattern are as follows:</para>
  1567. <p:proofSystem>
  1568. <p:rule name="attribute">
  1569. <p:judgement name="weakMatch">
  1570. <p:var range="context"/>
  1571. <p:function name="emptySet"/>
  1572. <p:var range="string"/>
  1573. <p:var range="pattern"/>
  1574. </p:judgement>
  1575. <p:judgement name="belongs">
  1576. <p:var range="name"/>
  1577. <p:var range="nameClass"/>
  1578. </p:judgement>
  1579. <p:judgement name="match">
  1580. <p:var range="context"/>
  1581. <p:function name="attribute">
  1582. <p:var range="name"/>
  1583. <p:var range="string"/>
  1584. </p:function>
  1585. <p:function name="emptySequence"/>
  1586. <p:element name="attribute">
  1587. <p:var range="nameClass"/>
  1588. <p:var range="pattern"/>
  1589. </p:element>
  1590. </p:judgement>
  1591. </p:rule>
  1592. </p:proofSystem>
  1593. <para>The semantics of the <literal>element</literal> pattern are as follows:</para>
  1594. <p:proofSystem>
  1595. <p:rule name="element">
  1596. <p:judgement name="weakMatch">
  1597. <p:var range="context" sub="1"/>
  1598. <p:var range="att"/>
  1599. <p:var range="mixed"/>
  1600. <p:var range="pattern"/>
  1601. </p:judgement>
  1602. <p:judgement name="belongs">
  1603. <p:var range="name"/>
  1604. <p:var range="nameClass"/>
  1605. </p:judgement>
  1606. <p:judgement name="okAsChildren">
  1607. <p:var range="mixed"/>
  1608. </p:judgement>
  1609. <p:judgement name="bind">
  1610. <p:var range="ncname"/>
  1611. <p:var range="nameClass"/>
  1612. <p:var range="pattern"/>
  1613. </p:judgement>
  1614. <p:judgement name="match">
  1615. <p:var range="context" sub="2"/>
  1616. <p:function name="emptySet"/>
  1617. <p:function name="append">
  1618. <p:var range="whiteSpace" sub="1"/>
  1619. <p:function name="element">
  1620. <p:var range="name"/>
  1621. <p:var range="context" sub="1"/>
  1622. <p:var range="att"/>
  1623. <p:var range="mixed"/>
  1624. </p:function>
  1625. <p:var range="whiteSpace" sub="2"/>
  1626. </p:function>
  1627. <p:element name="ref">
  1628. <p:attribute name="name">
  1629. <p:var range="ncname"/>
  1630. </p:attribute>
  1631. </p:element>
  1632. </p:judgement>
  1633. </p:rule>
  1634. </p:proofSystem>
  1635. </section>
  1636. <section id="data-pattern">
  1637. <title><literal>data</literal> and <literal>value</literal> pattern</title>
  1638. <para>RELAX NG relies on datatype libraries to perform datatyping.
  1639. A datatype library is identified by a URI. A datatype within a
  1640. datatype library is identified by an NCName. A datatype library
  1641. provides two services.</para>
  1642. <itemizedlist>
  1643. <listitem><para>It can determine whether a string is a legal
  1644. representation of a datatype. This service accepts a list of zero or
  1645. more parameters. For example, a string datatype might have a parameter
  1646. specifying the length of a string. The datatype library determines
  1647. what parameters are applicable for each datatype.</para></listitem>
  1648. <listitem><para>It can determine whether two strings represent the
  1649. same value of a datatype. This service does not have any
  1650. parameters.</para></listitem>
  1651. </itemizedlist>
  1652. <para>Both services may make use of the context of a string. For
  1653. example, a datatype representing a QName would use the namespace
  1654. map.</para>
  1655. <para>We use the following additional notation:</para>
  1656. <variablelist>
  1657. <varlistentry><term><p:judgement name="datatypeAllows">
  1658. <p:var range="uri"/>
  1659. <p:var range="ncname"/>
  1660. <p:var range="params"/>
  1661. <p:var range="string"/>
  1662. <p:var range="context"/>
  1663. </p:judgement></term><listitem><para>
  1664. asserts that in the datatype library identified by URI <p:var range="uri"/>, the string <p:var range="string"/> interpreted with
  1665. context <p:var range="context"/> is a legal
  1666. value of datatype <p:var range="ncname"/> with parameters <p:var range="params"/></para></listitem></varlistentry>
  1667. <varlistentry><term><p:judgement name="datatypeEqual">
  1668. <p:var range="uri"/>
  1669. <p:var range="ncname"/>
  1670. <p:var range="string" sub="1"/>
  1671. <p:var range="context" sub="1"/>
  1672. <p:var range="string" sub="2"/>
  1673. <p:var range="context" sub="2"/>
  1674. </p:judgement></term><listitem><para>
  1675. asserts that in the datatype library identified by URI <p:var range="uri"/>, string <p:var range="string" sub="1"/> interpreted with
  1676. context <p:var range="context" sub="1"/> represents the same value of
  1677. the datatype <p:var range="ncname"/> as the string <p:var range="string" sub="2"/> interpreted in the context of <p:var range="context" sub="2"/>
  1678. </para></listitem></varlistentry>
  1679. <varlistentry><term><p:var range="params"/></term><listitem><para>ranges over sequences of parameters</para></listitem></varlistentry>
  1680. <varlistentry><term><p:context>
  1681. <p:var range="context"/>
  1682. </p:context></term><listitem><para>
  1683. within the start-tag of a pattern refers to the context
  1684. of the pattern element
  1685. </para></listitem></varlistentry>
  1686. <varlistentry>
  1687. <term>
  1688. <p:function name="context">
  1689. <p:var range="uri"/>
  1690. <p:var range="context"/>
  1691. </p:function>
  1692. </term>
  1693. <listitem><para>constructs a context which is the same as <p:var range="context"/>
  1694. except that the default namespace is <p:var range="uri"/>; if <p:var
  1695. range="uri"/> is the empty string, then there is no default namespace
  1696. in the constructed context</para></listitem></varlistentry>
  1697. </variablelist>
  1698. <para>The datatypeEqual function must be reflexive, transitive
  1699. and symmetric, that is, the following inference rules must hold:</para>
  1700. <p:proofSystem>
  1701. <p:rule name="datatypeEqual reflexive">
  1702. <p:judgement name="datatypeAllows">
  1703. <p:var range="uri"/>
  1704. <p:var range="ncname"/>
  1705. <p:var range="params"/>
  1706. <p:var range="string"/>
  1707. <p:var range="context"/>
  1708. </p:judgement>
  1709. <p:judgement name="datatypeEqual">
  1710. <p:var range="uri"/>
  1711. <p:var range="ncname"/>
  1712. <p:var range="string"/>
  1713. <p:var range="context"/>
  1714. <p:var range="string"/>
  1715. <p:var range="context"/>
  1716. </p:judgement>
  1717. </p:rule>
  1718. <p:rule name="datatypeEqual transitive">
  1719. <p:judgement name="datatypeEqual">
  1720. <p:var range="uri"/>
  1721. <p:var range="ncname"/>
  1722. <p:var range="string" sub="1"/>
  1723. <p:var range="context" sub="1"/>
  1724. <p:var range="string" sub="2"/>
  1725. <p:var range="context" sub="2"/>
  1726. </p:judgement>
  1727. <p:judgement name="datatypeEqual">
  1728. <p:var range="uri"/>
  1729. <p:var range="ncname"/>
  1730. <p:var range="string" sub="2"/>
  1731. <p:var range="context" sub="3"/>
  1732. <p:var range="string" sub="3"/>
  1733. <p:var range="context" sub="3"/>
  1734. </p:judgement>
  1735. <p:judgement name="datatypeEqual">
  1736. <p:var range="uri"/>
  1737. <p:var range="ncname"/>
  1738. <p:var range="string" sub="1"/>
  1739. <p:var range="context" sub="1"/>
  1740. <p:var range="string" sub="3"/>
  1741. <p:var range="context" sub="3"/>
  1742. </p:judgement>
  1743. </p:rule>
  1744. <p:rule name="datatypeEqual symmetric">
  1745. <p:judgement name="datatypeEqual">
  1746. <p:var range="uri"/>
  1747. <p:var range="ncname"/>
  1748. <p:var range="string" sub="1"/>
  1749. <p:var range="context" sub="1"/>
  1750. <p:var range="string" sub="2"/>
  1751. <p:var range="context" sub="2"/>
  1752. </p:judgement>
  1753. <p:judgement name="datatypeEqual">
  1754. <p:var range="uri"/>
  1755. <p:var range="ncname"/>
  1756. <p:var range="string" sub="2"/>
  1757. <p:var range="context" sub="2"/>
  1758. <p:var range="string" sub="1"/>
  1759. <p:var range="context" sub="1"/>
  1760. </p:judgement>
  1761. </p:rule>
  1762. </p:proofSystem>
  1763. <para>The semantics of the <literal>data</literal> and
  1764. <literal>value</literal> patterns are as follows:</para>
  1765. <p:proofSystem>
  1766. <p:rule name="value">
  1767. <p:judgement name="datatypeEqual">
  1768. <p:var range="uri" sub="1"/>
  1769. <p:var range="ncname"/>
  1770. <p:var range="string" sub="1"/>
  1771. <p:var range="context" sub="1"/>
  1772. <p:var range="string" sub="2"/>
  1773. <p:function name="context">
  1774. <p:var range="uri" sub="2"/>
  1775. <p:var range="context" sub="2"/>
  1776. </p:function>
  1777. </p:judgement>
  1778. <p:judgement name="match">
  1779. <p:var range="context" sub="1"/>
  1780. <p:function name="emptySet"/>
  1781. <p:var range="string" sub="1"/>
  1782. <p:element name="value">
  1783. <p:attribute name="datatypeLibrary">
  1784. <p:var range="uri" sub="1"/>
  1785. </p:attribute>
  1786. <p:attribute name="type">
  1787. <p:var range="ncname"/>
  1788. </p:attribute>
  1789. <p:attribute name="ns">
  1790. <p:var range="uri" sub="2"/>
  1791. </p:attribute>
  1792. <p:context>
  1793. <p:var range="context" sub="2"/>
  1794. </p:context>
  1795. <p:var range="string" sub="2"/>
  1796. </p:element>
  1797. <p:function name="emptySet"/>
  1798. <p:function name="emptySet"/>
  1799. </p:judgement>
  1800. </p:rule>
  1801. <p:rule name="data 1">
  1802. <p:judgement name="datatypeAllows">
  1803. <p:var range="uri"/>
  1804. <p:var range="ncname"/>
  1805. <p:var range="params"/>
  1806. <p:var range="string"/>
  1807. <p:var range="context"/>
  1808. </p:judgement>
  1809. <p:judgement name="match">
  1810. <p:var range="context"/>
  1811. <p:function name="emptySet"/>
  1812. <p:var range="string"/>
  1813. <p:element name="data">
  1814. <p:attribute name="datatypeLibrary">
  1815. <p:var range="uri"/>
  1816. </p:attribute>
  1817. <p:attribute name="type">
  1818. <p:var range="ncname"/>
  1819. </p:attribute>
  1820. <p:var range="params"/>
  1821. </p:element>
  1822. <p:function name="emptySet"/>
  1823. <p:function name="emptySet"/>
  1824. </p:judgement>
  1825. </p:rule>
  1826. <p:rule name="data 2">
  1827. <p:judgement name="datatypeAllows">
  1828. <p:var range="uri"/>
  1829. <p:var range="ncname"/>
  1830. <p:var range="params"/>
  1831. <p:var range="string"/>
  1832. <p:var range="context"/>
  1833. </p:judgement>
  1834. <p:not>
  1835. <p:judgement name="match">
  1836. <p:var range="context"/>
  1837. <p:var range="att"/>
  1838. <p:var range="string"/>
  1839. <p:var range="pattern"/>
  1840. </p:judgement>
  1841. </p:not>
  1842. <p:judgement name="match">
  1843. <p:var range="context"/>
  1844. <p:function name="emptySet"/>
  1845. <p:var range="string"/>
  1846. <p:element name="data">
  1847. <p:attribute name="datatypeLibrary">
  1848. <p:var range="uri"/>
  1849. </p:attribute>
  1850. <p:attribute name="type">
  1851. <p:var range="ncname"/>
  1852. </p:attribute>
  1853. <p:var range="params"/>
  1854. <p:element name="except">
  1855. <p:var range="pattern"/>
  1856. </p:element>
  1857. </p:element>
  1858. <p:function name="emptySet"/>
  1859. <p:function name="emptySet"/>
  1860. </p:judgement>
  1861. </p:rule>
  1862. </p:proofSystem>
  1863. </section>
  1864. <section id="built-in-datatype">
  1865. <title>Built-in datatype library</title>
  1866. <para>The empty URI identifies a special built-in datatype library.
  1867. This provides two datatypes, <literal>string</literal> and
  1868. <literal>token</literal>. No parameters are allowed for either of
  1869. these datatypes.</para>
  1870. <variablelist>
  1871. <varlistentry><term>
  1872. <p:judgement name="equal">
  1873. <p:var range="string" sub="1"/>
  1874. <p:var range="string" sub="2"/>
  1875. </p:judgement></term>
  1876. <listitem><para>asserts that <p:var range="string" sub="1"/>
  1877. and <p:var range="string" sub="2"/> are identical</para></listitem>
  1878. </varlistentry>
  1879. <varlistentry><term>
  1880. <p:function name="normalizeWhiteSpace">
  1881. <p:var range="string"/>
  1882. </p:function>
  1883. </term>
  1884. <listitem><para>returns the string <p:var range="string"/>,
  1885. with leading and trailing whitespace characters removed,
  1886. and with each other maximal sequence of whitespace characters
  1887. replaced by a single space character </para></listitem>
  1888. </varlistentry>
  1889. </variablelist>
  1890. <para>The semantics of the two built-in datatypes are as
  1891. follows:</para>
  1892. <p:proofSystem>
  1893. <p:rule name="string allows">
  1894. <p:judgement name="datatypeAllows">
  1895. <p:function name="emptyString"/>
  1896. <p:string>string</p:string>
  1897. <p:function name="emptySequence"/>
  1898. <p:var range="string"/>
  1899. <p:var range="context"/>
  1900. </p:judgement>
  1901. </p:rule>
  1902. <p:rule name="string equal">
  1903. <p:judgement name="datatypeEqual">
  1904. <p:function name="emptyString"/>
  1905. <p:string>string</p:string>
  1906. <p:var range="string"/>
  1907. <p:var range="context" sub="1"/>
  1908. <p:var range="string"/>
  1909. <p:var range="context" sub="2"/>
  1910. </p:judgement>
  1911. </p:rule>
  1912. <p:rule name="token allows">
  1913. <p:judgement name="datatypeAllows">
  1914. <p:function name="emptyString"/>
  1915. <p:string>token</p:string>
  1916. <p:function name="emptySequence"/>
  1917. <p:var range="string"/>
  1918. <p:var range="context"/>
  1919. </p:judgement>
  1920. </p:rule>
  1921. <p:rule name="token equal">
  1922. <p:judgement name="equal">
  1923. <p:function name="normalizeWhiteSpace">
  1924. <p:var range="string" sub="1"/>
  1925. </p:function>
  1926. <p:function name="normalizeWhiteSpace">
  1927. <p:var range="string" sub="2"/>
  1928. </p:function>
  1929. </p:judgement>
  1930. <p:judgement name="datatypeEqual">
  1931. <p:function name="emptyString"/>
  1932. <p:string>token</p:string>
  1933. <p:var range="string" sub="1"/>
  1934. <p:var range="context" sub="1"/>
  1935. <p:var range="string" sub="2"/>
  1936. <p:var range="context" sub="2"/>
  1937. </p:judgement>
  1938. </p:rule>
  1939. </p:proofSystem>
  1940. </section>
  1941. <section>
  1942. <title><literal>list</literal> pattern</title>
  1943. <para>We use the following additional notation:</para>
  1944. <variablelist>
  1945. <varlistentry><term><p:function name="split">
  1946. <p:var range="string"/>
  1947. </p:function></term><listitem><para>
  1948. returns a sequence of strings one for each whitespace delimited token
  1949. of <p:var range="string"/>; each string in the returned sequence will
  1950. be non-empty and will not contain any
  1951. whitespace</para></listitem></varlistentry>
  1952. </variablelist>
  1953. <para>The semantics of the <literal>list</literal> pattern are as follows:</para>
  1954. <p:proofSystem>
  1955. <p:rule name="list">
  1956. <p:judgement name="match">
  1957. <p:var range="context"/>
  1958. <p:function name="emptySet"/>
  1959. <p:function name="split">
  1960. <p:var range="string"/>
  1961. </p:function>
  1962. <p:var range="pattern"/>
  1963. </p:judgement>
  1964. <p:judgement name="match">
  1965. <p:var range="context"/>
  1966. <p:function name="emptySet"/>
  1967. <p:var range="string"/>
  1968. <p:element name="list">
  1969. <p:var range="pattern"/>
  1970. </p:element>
  1971. </p:judgement>
  1972. </p:rule>
  1973. </p:proofSystem>
  1974. <note><para>It is crucial in the above inference rule that the
  1975. sequence that is matched against a pattern can contain consecutive
  1976. strings.</para></note>
  1977. </section>
  1978. </section>
  1979. <section id="validity">
  1980. <title>Validity</title>
  1981. <para>Now we can define when an element is valid with respect to a
  1982. schema. We use the following additional notation:</para>
  1983. <variablelist>
  1984. <varlistentry><term><p:var range="element"/></term><listitem><para>ranges over elements</para></listitem></varlistentry>
  1985. <varlistentry><term><p:judgement name="valid">
  1986. <p:var range="element"/>
  1987. </p:judgement></term><listitem><para>
  1988. asserts that the element <p:var range="element"/> is valid with
  1989. respect to the grammar</para></listitem></varlistentry>
  1990. <varlistentry><term><p:judgement name="start">
  1991. <p:var range="pattern"/>
  1992. </p:judgement></term><listitem><para>
  1993. asserts that the grammar contains
  1994. <p:element name="start"><p:var range="pattern"/> </p:element></para></listitem></varlistentry>
  1995. </variablelist>
  1996. <para>An element is valid if together with an empty set of attributes
  1997. it matches the <literal>start</literal> pattern of the grammar.</para>
  1998. <p:proofSystem>
  1999. <p:rule name="valid">
  2000. <p:judgement name="start">
  2001. <p:var range="pattern"/>
  2002. </p:judgement>
  2003. <p:judgement name="match">
  2004. <p:var range="context"/>
  2005. <p:function name="emptySet"/>
  2006. <p:var range="element"/>
  2007. <p:var range="pattern"/>
  2008. </p:judgement>
  2009. <p:judgement name="valid">
  2010. <p:var range="element"/>
  2011. </p:judgement>
  2012. </p:rule>
  2013. </p:proofSystem>
  2014. </section>
  2015. <section>
  2016. <title>Example</title>
  2017. <para>Let <p:var range="element" sub="0"/> be</para>
  2018. <p:formula>
  2019. <p:function name="element">
  2020. <p:function name="name">
  2021. <p:function name="emptyString"/>
  2022. <p:string>foo</p:string>
  2023. </p:function>
  2024. <p:var range="context" sub="0"/>
  2025. <p:function name="emptySet"/>
  2026. <p:var range="mixed"/>
  2027. </p:function>
  2028. </p:formula>
  2029. <para>where <p:var range="mixed"/> is</para>
  2030. <p:formula>
  2031. <p:function name="append">
  2032. <p:var range="element" sub="1"/>
  2033. <p:var range="element" sub="2"/>
  2034. </p:function>
  2035. </p:formula>
  2036. <para>and <p:var range="element" sub="1"/> is</para>
  2037. <p:formula>
  2038. <p:function name="element">
  2039. <p:function name="name">
  2040. <p:string>http://www.example.com/n1</p:string>
  2041. <p:string>bar1</p:string>
  2042. </p:function>
  2043. <p:var range="context" sub="1"/>
  2044. <p:function name="emptySet"/>
  2045. <p:function name="emptySequence"/>
  2046. </p:function>
  2047. </p:formula>
  2048. <para>and <p:var range="element" sub="2"/> is</para>
  2049. <p:formula>
  2050. <p:function name="element">
  2051. <p:function name="name">
  2052. <p:string>http://www.example.com/n2</p:string>
  2053. <p:string>bar2</p:string>
  2054. </p:function>
  2055. <p:var range="context" sub="2"/>
  2056. <p:function name="emptySet"/>
  2057. <p:function name="emptySequence"/>
  2058. </p:function>
  2059. </p:formula>
  2060. <para>Assuming appropriate definitions of <p:var range="context"
  2061. sub="0"/>, <p:var range="context" sub="1"/> and <p:var range="context"
  2062. sub="2"/>, this represents the document in <xref
  2063. linkend="data-model-example"/>.</para>
  2064. <para>We now show how <p:var range="element" sub="0"/> can be shown to
  2065. be valid with respect to the schema in <xref
  2066. linkend="simple-syntax-example"/>. The schema is equivalent to the
  2067. following propositions:</para>
  2068. <p:formula>
  2069. <p:judgement name="start">
  2070. <p:element name="ref">
  2071. <p:attribute name="name"><p:string>foo</p:string></p:attribute>
  2072. </p:element>
  2073. </p:judgement>
  2074. </p:formula>
  2075. <p:formula>
  2076. <p:judgement name="bind">
  2077. <p:string>foo.element</p:string>
  2078. <p:element name="name">
  2079. <p:attribute name="ns"><p:function name="emptyString"/></p:attribute>
  2080. <p:string>foo</p:string>
  2081. </p:element>
  2082. <p:element name="group">
  2083. <p:element name="ref">
  2084. <p:attribute name="name">
  2085. <p:string>bar1</p:string>
  2086. </p:attribute>
  2087. </p:element>
  2088. <p:element name="ref">
  2089. <p:attribute name="name">
  2090. <p:string>bar2</p:string>
  2091. </p:attribute>
  2092. </p:element>
  2093. </p:element>
  2094. </p:judgement>
  2095. </p:formula>
  2096. <p:formula>
  2097. <p:judgement name="bind">
  2098. <p:string>bar1.element</p:string>
  2099. <p:element name="name">
  2100. <p:attribute name="ns">
  2101. <p:string>http://www.example.com/n1</p:string>
  2102. </p:attribute>
  2103. <p:string>bar1</p:string>
  2104. </p:element>
  2105. <p:element name="empty"/>
  2106. </p:judgement>
  2107. </p:formula>
  2108. <p:formula>
  2109. <p:judgement name="bind">
  2110. <p:string>bar2.element</p:string>
  2111. <p:element name="name">
  2112. <p:attribute name="ns">
  2113. <p:string>http://www.example.com/n2</p:string>
  2114. </p:attribute>
  2115. <p:string>bar2</p:string>
  2116. </p:element>
  2117. <p:element name="empty"/>
  2118. </p:judgement>
  2119. </p:formula>
  2120. <para>Let name class <p:var range="nameClass" sub="1"/> be</para>
  2121. <p:formula>
  2122. <p:element name="name">
  2123. <p:attribute name="ns">
  2124. <p:string>http://www.example.com/n1</p:string>
  2125. </p:attribute>
  2126. <p:string>bar1</p:string>
  2127. </p:element>
  2128. </p:formula>
  2129. <para>and let <p:var range="nameClass" sub="2"/> be</para>
  2130. <p:formula>
  2131. <p:element name="name">
  2132. <p:attribute name="ns">
  2133. <p:string>http://www.example.com/n2</p:string>
  2134. </p:attribute>
  2135. <p:string>bar2</p:string>
  2136. </p:element>
  2137. </p:formula>
  2138. <para>Then, by the inference rule (name) in <xref
  2139. linkend="name-classes"/>, we have</para>
  2140. <p:formula>
  2141. <p:judgement name="belongs">
  2142. <p:function name="name">
  2143. <p:string>http://www.example.com/n1</p:string>
  2144. <p:string>bar1</p:string>
  2145. </p:function>
  2146. <p:var range="nameClass" sub="1"/>
  2147. </p:judgement>
  2148. </p:formula>
  2149. <para>and</para>
  2150. <p:formula>
  2151. <p:judgement name="belongs">
  2152. <p:function name="name">
  2153. <p:string>http://www.example.com/n2</p:string>
  2154. <p:string>bar2</p:string>
  2155. </p:function>
  2156. <p:var range="nameClass" sub="2"/>
  2157. </p:judgement>
  2158. </p:formula>
  2159. <para>By the inference rule (empty) in <xref linkend="empty-pattern"/>,
  2160. we have</para>
  2161. <p:formula>
  2162. <p:judgement name="match">
  2163. <p:var range="context" sub="1"/>
  2164. <p:function name="emptySet"/>
  2165. <p:function name="emptySequence"/>
  2166. <p:element name="empty"></p:element>
  2167. </p:judgement>
  2168. </p:formula>
  2169. <para>and</para>
  2170. <p:formula>
  2171. <p:judgement name="match">
  2172. <p:var range="context" sub="2"/>
  2173. <p:function name="emptySet"/>
  2174. <p:function name="emptySequence"/>
  2175. <p:element name="empty"></p:element>
  2176. </p:judgement>
  2177. </p:formula>
  2178. <para>Thus by the inference rule (element) in <xref
  2179. linkend="element-pattern"/>, we have</para>
  2180. <p:formula>
  2181. <p:judgement name="match">
  2182. <p:var range="context" sub="0"/>
  2183. <p:function name="emptySet"/>
  2184. <p:var range="element" sub="1"/>
  2185. <p:element name="ref">
  2186. <p:attribute name="name">
  2187. <p:string>bar1</p:string>
  2188. </p:attribute>
  2189. </p:element>
  2190. </p:judgement>
  2191. </p:formula>
  2192. <para>Note that we have chosen <p:var
  2193. range="context" sub="0"/>, since any context is allowed.</para>
  2194. <para>Likewise, we have</para>
  2195. <p:formula>
  2196. <p:judgement name="match">
  2197. <p:var range="context" sub="0"/>
  2198. <p:function name="emptySet"/>
  2199. <p:var range="element" sub="2"/>
  2200. <p:element name="ref">
  2201. <p:attribute name="name">
  2202. <p:string>bar2</p:string>
  2203. </p:attribute>
  2204. </p:element>
  2205. </p:judgement>
  2206. </p:formula>
  2207. <para>By the inference rule (group) in <xref
  2208. linkend="choice-pattern"/>, we have</para>
  2209. <p:formula>
  2210. <p:judgement name="match">
  2211. <p:var range="context" sub="0"/>
  2212. <p:function name="emptySet"/>
  2213. <p:function name="append">
  2214. <p:var range="element" sub="1"/>
  2215. <p:var range="element" sub="2"/>
  2216. </p:function>
  2217. <p:element name="group">
  2218. <p:element name="ref">
  2219. <p:attribute name="name">
  2220. <p:string>bar1</p:string>
  2221. </p:attribute>
  2222. </p:element>
  2223. <p:element name="ref">
  2224. <p:attribute name="name">
  2225. <p:string>bar2</p:string>
  2226. </p:attribute>
  2227. </p:element>
  2228. </p:element>
  2229. </p:judgement>
  2230. </p:formula>
  2231. <para>By the inference rule (element) in <xref
  2232. linkend="element-pattern"/>, we have</para>
  2233. <p:formula>
  2234. <p:judgement name="match">
  2235. <p:var range="context" sub="3"/>
  2236. <p:function name="emptySet"/>
  2237. <p:function name="element">
  2238. <p:function name="name">
  2239. <p:function name="emptyString"/>
  2240. <p:string>foo</p:string>
  2241. </p:function>
  2242. <p:var range="context" sub="0"/>
  2243. <p:function name="emptySet"/>
  2244. <p:var range="mixed"/>
  2245. </p:function>
  2246. <p:element name="ref">
  2247. <p:attribute name="name">
  2248. <p:string>foo</p:string>
  2249. </p:attribute>
  2250. </p:element>
  2251. </p:judgement>
  2252. </p:formula>
  2253. <para>Here <p:var range="context" sub="3"/> is an arbitrary
  2254. context.</para>
  2255. <para>Thus we can apply the inference rule (valid) in <xref
  2256. linkend="validity"/> and obtain</para>
  2257. <p:formula>
  2258. <p:judgement name="valid">
  2259. <p:var range="element" sub="0"/>
  2260. </p:judgement>
  2261. </p:formula>
  2262. </section>
  2263. </section>
  2264. <section id="restriction">
  2265. <title>Restrictions</title>
  2266. <para>The following constraints are all checked after the grammar has
  2267. been transformed to the simple form described in <xref
  2268. linkend="simple-syntax"/>. The purpose of these restrictions is to
  2269. catch user errors and to facilitate implementation.</para>
  2270. <section id="contextual-restriction">
  2271. <title>Contextual restrictions</title>
  2272. <para>In this section we describe restrictions on where elements are
  2273. allowed in the schema based on the names of the ancestor elements. We
  2274. use the concept of a <firstterm>prohibited path</firstterm> to
  2275. describe these restrictions. A path is a sequence of NCNames separated
  2276. by <literal>/</literal> or <literal>//</literal>.</para>
  2277. <itemizedlist>
  2278. <listitem><para>An element matches a path
  2279. <replaceable>x</replaceable>, where <replaceable>x</replaceable> is an
  2280. NCName, if and only if the local name of the element is
  2281. <replaceable>x</replaceable></para></listitem>
  2282. <listitem><para>An element matches a path
  2283. <replaceable>x</replaceable><literal>/</literal><replaceable>p</replaceable>,
  2284. where <replaceable>x</replaceable> is an NCName and
  2285. <replaceable>p</replaceable> is a path, if and only if the local name
  2286. of the element is <replaceable>x</replaceable> and the element has a
  2287. child that matches <replaceable>p</replaceable></para></listitem>
  2288. <listitem><para>An element matches a path
  2289. <replaceable>x</replaceable><literal>//</literal><replaceable>p</replaceable>,
  2290. where <replaceable>x</replaceable> is an NCName and
  2291. <replaceable>p</replaceable> is a path, if and only if the local name
  2292. of the element is <replaceable>x</replaceable> and the element has a
  2293. descendant that matches <replaceable>p</replaceable></para></listitem>
  2294. </itemizedlist>
  2295. <para>For example, the element</para>
  2296. <programlisting><![CDATA[<foo>
  2297. <bar>
  2298. <baz/>
  2299. </bar>
  2300. </foo>]]></programlisting>
  2301. <para>matches the paths <literal>foo</literal>,
  2302. <literal>foo/bar</literal>, <literal>foo//bar</literal>,
  2303. <literal>foo//baz</literal>, <literal>foo/bar/baz</literal>,
  2304. <literal>foo/bar//baz</literal> and <literal>foo//bar/baz</literal>,
  2305. but not <literal>foo/baz</literal> or
  2306. <literal>foobar</literal>.</para>
  2307. <para>A correct RELAX NG schema must be such that, after
  2308. transformation to the simple form, it does not contain any element
  2309. that matches a prohibited path.</para>
  2310. <section>
  2311. <title><literal>attribute</literal> pattern</title>
  2312. <para>The following paths are prohibited:</para>
  2313. <itemizedlist>
  2314. <listitem><para><literal>attribute//ref</literal></para></listitem>
  2315. <listitem><para><literal>attribute//attribute</literal></para></listitem>
  2316. </itemizedlist>
  2317. </section>
  2318. <section>
  2319. <title><literal>oneOrMore</literal> pattern</title>
  2320. <para>The following paths are prohibited:</para>
  2321. <itemizedlist>
  2322. <listitem><para><literal>oneOrMore//group//attribute</literal></para></listitem>
  2323. <listitem><para><literal>oneOrMore//interleave//attribute</literal></para></listitem>
  2324. </itemizedlist>
  2325. </section>
  2326. <section id="list-restrictions">
  2327. <title><literal>list</literal> pattern</title>
  2328. <para>The following paths are prohibited:</para>
  2329. <itemizedlist>
  2330. <listitem><para><literal>list//list</literal></para></listitem>
  2331. <listitem><para><literal>list//ref</literal></para></listitem>
  2332. <listitem><para><literal>list//attribute</literal></para></listitem>
  2333. <listitem><para><literal>list//text</literal></para></listitem>
  2334. <listitem><para><literal>list//interleave</literal></para></listitem>
  2335. </itemizedlist>
  2336. </section>
  2337. <section id="context-data-except">
  2338. <title><literal>except</literal> in <literal>data</literal> pattern</title>
  2339. <para>The following paths are prohibited:</para>
  2340. <itemizedlist>
  2341. <listitem><para><literal>data/except//attribute</literal></para></listitem>
  2342. <listitem><para><literal>data/except//ref</literal></para></listitem>
  2343. <listitem><para><literal>data/except//text</literal></para></listitem>
  2344. <listitem><para><literal>data/except//list</literal></para></listitem>
  2345. <listitem><para><literal>data/except//group</literal></para></listitem>
  2346. <listitem><para><literal>data/except//interleave</literal></para></listitem>
  2347. <listitem><para><literal>data/except//oneOrMore</literal></para></listitem>
  2348. <listitem><para><literal>data/except//empty</literal></para></listitem>
  2349. </itemizedlist>
  2350. <note><para>This implies that an <literal>except</literal> element
  2351. with a <literal>data</literal> parent can contain only
  2352. <literal>data</literal>, <literal>value</literal> and
  2353. <literal>choice</literal> elements.</para></note>
  2354. </section>
  2355. <section id="context-start">
  2356. <title><literal>start</literal> element</title>
  2357. <para>The following paths are prohibited:</para>
  2358. <itemizedlist>
  2359. <listitem><para><literal>start//attribute</literal></para></listitem>
  2360. <listitem><para><literal>start//data</literal></para></listitem>
  2361. <listitem><para><literal>start//value</literal></para></listitem>
  2362. <listitem><para><literal>start//text</literal></para></listitem>
  2363. <listitem><para><literal>start//list</literal></para></listitem>
  2364. <listitem><para><literal>start//group</literal></para></listitem>
  2365. <listitem><para><literal>start//interleave</literal></para></listitem>
  2366. <listitem><para><literal>start//oneOrMore</literal></para></listitem>
  2367. <listitem><para><literal>start//empty</literal></para></listitem>
  2368. </itemizedlist>
  2369. </section>
  2370. </section>
  2371. <section id="string-sequences">
  2372. <title>String sequences</title>
  2373. <para>RELAX NG does not allow a pattern such as:</para>
  2374. <programlisting><![CDATA[<element name="foo">
  2375. <group>
  2376. <data type="int"/>
  2377. <element name="bar">
  2378. <empty/>
  2379. </element>
  2380. </group>
  2381. </element>]]></programlisting>
  2382. <para>Nor does it allow a pattern such as:</para>
  2383. <programlisting><![CDATA[<element name="foo">
  2384. <group>
  2385. <data type="int"/>
  2386. <text/>
  2387. </group>
  2388. </element>]]></programlisting>
  2389. <para>More generally, if the pattern for the content of an element or
  2390. attribute contains</para>
  2391. <itemizedlist>
  2392. <listitem><para>a pattern that can match a child
  2393. (that is, an <literal>element</literal>, <literal>data</literal>,
  2394. <literal>value</literal>, <literal>list</literal> or
  2395. <literal>text</literal> pattern), and</para></listitem>
  2396. <listitem><para>a pattern that matches a single string (that is, a
  2397. <literal>data</literal>, <literal>value</literal> or
  2398. <literal>list</literal> pattern),</para></listitem>
  2399. </itemizedlist>
  2400. <para>then the two patterns must be alternatives to each other.</para>
  2401. <para>This rule does not apply to patterns occurring within a
  2402. <literal>list</literal> pattern.</para>
  2403. <para>To formalize this, we use the concept of a content-type. A
  2404. pattern that is allowable as the content of an element has one of
  2405. three content-types: empty, complex and simple. We use the following
  2406. notation.</para>
  2407. <variablelist>
  2408. <varlistentry>
  2409. <term><p:function name="empty"/></term>
  2410. <listitem><para>returns the empty content-type</para></listitem>
  2411. </varlistentry>
  2412. <varlistentry>
  2413. <term><p:function name="complex"/></term>
  2414. <listitem><para>returns the complex content-type</para></listitem>
  2415. </varlistentry>
  2416. <varlistentry>
  2417. <term><p:function name="simple"/></term>
  2418. <listitem><para>returns the simple content-type</para></listitem>
  2419. </varlistentry>
  2420. <varlistentry><term><p:var range="contentType"/></term>
  2421. <listitem><para>ranges over content-types</para></listitem>
  2422. </varlistentry>
  2423. <varlistentry><term>
  2424. <p:judgement name="groupable">
  2425. <p:var range="contentType" sub="1"/>
  2426. <p:var range="contentType" sub="2"/>
  2427. </p:judgement>
  2428. </term>
  2429. <listitem><para>asserts that the content-types <p:var
  2430. range="contentType" sub="1"/> and <p:var range="contentType" sub="2"/>
  2431. are groupable</para></listitem>
  2432. </varlistentry>
  2433. </variablelist>
  2434. <para>The empty content-type is groupable with anything. In addition,
  2435. the complex content-type is groupable with the complex content-type. The
  2436. following rules formalize this.</para>
  2437. <p:proofSystem>
  2438. <p:rule name="group empty 1">
  2439. <p:judgement name="groupable">
  2440. <p:function name="empty"/>
  2441. <p:var range="contentType"/>
  2442. </p:judgement>
  2443. </p:rule>
  2444. <p:rule name="group empty 2">
  2445. <p:judgement name="groupable">
  2446. <p:var range="contentType"/>
  2447. <p:function name="empty"/>
  2448. </p:judgement>
  2449. </p:rule>
  2450. <p:rule name="group complex">
  2451. <p:judgement name="groupable">
  2452. <p:function name="complex"/>
  2453. <p:function name="complex"/>
  2454. </p:judgement>
  2455. </p:rule>
  2456. </p:proofSystem>
  2457. <para>Some patterns have a content-type. We use the following
  2458. additional notation.</para>
  2459. <variablelist>
  2460. <varlistentry><term>
  2461. <p:judgement name="contentType">
  2462. <p:var range="pattern"/>
  2463. <p:var range="contentType"/>
  2464. </p:judgement>
  2465. </term>
  2466. <listitem><para>asserts that pattern <p:var range="pattern"/> has
  2467. content-type <p:var range="contentType"/></para></listitem>
  2468. </varlistentry>
  2469. <varlistentry><term>
  2470. <p:function name="max">
  2471. <p:var range="contentType" sub="1"/>
  2472. <p:var range="contentType" sub="2"/>
  2473. </p:function>
  2474. </term>
  2475. <listitem><para>returns the maximum of <p:var range="contentType"
  2476. sub="1"/> and <p:var range="contentType" sub="2"/> where the
  2477. content-types in increasing order are <p:function name="empty"/>,
  2478. <p:function name="complex"/>, <p:function
  2479. name="simple"/></para></listitem>
  2480. </varlistentry>
  2481. </variablelist>
  2482. <para>The following rules define when a pattern has a content-type and,
  2483. if so, what it is.</para>
  2484. <p:proofSystem>
  2485. <p:rule name="value">
  2486. <p:judgement name="contentType">
  2487. <p:element name="value">
  2488. <p:attribute name="datatypeLibrary">
  2489. <p:var range="uri" sub="1"/>
  2490. </p:attribute>
  2491. <p:attribute name="type">
  2492. <p:var range="ncname"/>
  2493. </p:attribute>
  2494. <p:attribute name="ns">
  2495. <p:var range="uri" sub="2"/>
  2496. </p:attribute>
  2497. <p:var range="string"/>
  2498. </p:element>
  2499. <p:function name="simple"/>
  2500. </p:judgement>
  2501. </p:rule>
  2502. <p:rule name="data 1">
  2503. <p:judgement name="contentType">
  2504. <p:element name="data">
  2505. <p:attribute name="datatypeLibrary">
  2506. <p:var range="uri"/>
  2507. </p:attribute>
  2508. <p:attribute name="type">
  2509. <p:var range="ncname"/>
  2510. </p:attribute>
  2511. <p:var range="params"/>
  2512. </p:element>
  2513. <p:function name="simple"/>
  2514. </p:judgement>
  2515. </p:rule>
  2516. <p:rule name="data 2">
  2517. <p:judgement name="contentType">
  2518. <p:var range="pattern"/>
  2519. <p:var range="contentType"/>
  2520. </p:judgement>
  2521. <p:judgement name="contentType">
  2522. <p:element name="data">
  2523. <p:attribute name="datatypeLibrary">
  2524. <p:var range="uri"/>
  2525. </p:attribute>
  2526. <p:attribute name="type">
  2527. <p:var range="ncname"/>
  2528. </p:attribute>
  2529. <p:var range="params"/>
  2530. <p:element name="except">
  2531. <p:var range="pattern"/>
  2532. </p:element>
  2533. </p:element>
  2534. <p:function name="simple"/>
  2535. </p:judgement>
  2536. </p:rule>
  2537. <p:rule name="list">
  2538. <p:judgement name="contentType">
  2539. <p:element name="list">
  2540. <p:var range="pattern"/>
  2541. </p:element>
  2542. <p:function name="simple"/>
  2543. </p:judgement>
  2544. </p:rule>
  2545. <p:rule name="text">
  2546. <p:judgement name="contentType">
  2547. <p:element name="text"/>
  2548. <p:function name="complex"/>
  2549. </p:judgement>
  2550. </p:rule>
  2551. <p:rule name="ref">
  2552. <p:judgement name="contentType">
  2553. <p:element name="ref">
  2554. <p:attribute name="name">
  2555. <p:var range="ncname"/>
  2556. </p:attribute>
  2557. </p:element>
  2558. <p:function name="complex"/>
  2559. </p:judgement>
  2560. </p:rule>
  2561. <p:rule name="empty">
  2562. <p:judgement name="contentType">
  2563. <p:element name="empty"/>
  2564. <p:function name="empty"/>
  2565. </p:judgement>
  2566. </p:rule>
  2567. <p:rule name="attribute">
  2568. <p:judgement name="contentType">
  2569. <p:var range="pattern"/>
  2570. <p:var range="contentType"/>
  2571. </p:judgement>
  2572. <p:judgement name="contentType">
  2573. <p:element name="attribute">
  2574. <p:var range="nameClass"/>
  2575. <p:var range="pattern"/>
  2576. </p:element>
  2577. <p:function name="empty"/>
  2578. </p:judgement>
  2579. </p:rule>
  2580. <p:rule name="group">
  2581. <p:judgement name="contentType">
  2582. <p:var range="pattern" sub="1"/>
  2583. <p:var range="contentType" sub="1"/>
  2584. </p:judgement>
  2585. <p:judgement name="contentType">
  2586. <p:var range="pattern" sub="2"/>
  2587. <p:var range="contentType" sub="2"/>
  2588. </p:judgement>
  2589. <p:judgement name="groupable">
  2590. <p:var range="contentType" sub="1"/>
  2591. <p:var range="contentType" sub="2"/>
  2592. </p:judgement>
  2593. <p:judgement name="contentType">
  2594. <p:element name="group">
  2595. <p:var range="pattern" sub="1"/>
  2596. <p:var range="pattern" sub="2"/>
  2597. </p:element>
  2598. <p:function name="max">
  2599. <p:var range="contentType" sub="1"/>
  2600. <p:var range="contentType" sub="2"/>
  2601. </p:function>
  2602. </p:judgement>
  2603. </p:rule>
  2604. <p:rule name="interleave">
  2605. <p:judgement name="contentType">
  2606. <p:var range="pattern" sub="1"/>
  2607. <p:var range="contentType" sub="1"/>
  2608. </p:judgement>
  2609. <p:judgement name="contentType">
  2610. <p:var range="pattern" sub="2"/>
  2611. <p:var range="contentType" sub="2"/>
  2612. </p:judgement>
  2613. <p:judgement name="groupable">
  2614. <p:var range="contentType" sub="1"/>
  2615. <p:var range="contentType" sub="2"/>
  2616. </p:judgement>
  2617. <p:judgement name="contentType">
  2618. <p:element name="interleave">
  2619. <p:var range="pattern" sub="1"/>
  2620. <p:var range="pattern" sub="2"/>
  2621. </p:element>
  2622. <p:function name="max">
  2623. <p:var range="contentType" sub="1"/>
  2624. <p:var range="contentType" sub="2"/>
  2625. </p:function>
  2626. </p:judgement>
  2627. </p:rule>
  2628. <p:rule name="oneOrMore">
  2629. <p:judgement name="contentType">
  2630. <p:var range="pattern"/>
  2631. <p:var range="contentType"/>
  2632. </p:judgement>
  2633. <p:judgement name="groupable">
  2634. <p:var range="contentType"/>
  2635. <p:var range="contentType"/>
  2636. </p:judgement>
  2637. <p:judgement name="contentType">
  2638. <p:element name="oneOrMore">
  2639. <p:var range="pattern"/>
  2640. </p:element>
  2641. <p:var range="contentType"/>
  2642. </p:judgement>
  2643. </p:rule>
  2644. <p:rule name="choice">
  2645. <p:judgement name="contentType">
  2646. <p:var range="pattern" sub="1"/>
  2647. <p:var range="contentType" sub="1"/>
  2648. </p:judgement>
  2649. <p:judgement name="contentType">
  2650. <p:var range="pattern" sub="2"/>
  2651. <p:var range="contentType" sub="2"/>
  2652. </p:judgement>
  2653. <p:judgement name="contentType">
  2654. <p:element name="choice">
  2655. <p:var range="pattern" sub="1"/>
  2656. <p:var range="pattern" sub="2"/>
  2657. </p:element>
  2658. <p:function name="max">
  2659. <p:var range="contentType" sub="1"/>
  2660. <p:var range="contentType" sub="2"/>
  2661. </p:function>
  2662. </p:judgement>
  2663. </p:rule>
  2664. </p:proofSystem>
  2665. <note><para>The antecedent in the (data 2) rule above is in fact
  2666. redundant because of the prohibited paths in <xref
  2667. linkend="context-data-except"/>.</para></note>
  2668. <para>Now we can describe the restriction. We use the following
  2669. notation.</para>
  2670. <variablelist>
  2671. <varlistentry><term>
  2672. <p:judgement name="incorrectSchema"/>
  2673. </term>
  2674. <listitem><para>asserts that the schema is incorrect</para></listitem>
  2675. </varlistentry>
  2676. </variablelist>
  2677. <para>All patterns occurring as the content of an element pattern must
  2678. have a content-type.</para>
  2679. <p:proofSystem>
  2680. <p:rule name="element">
  2681. <p:judgement name="bind">
  2682. <p:var range="ncname"/>
  2683. <p:var range="nameClass"/>
  2684. <p:var range="pattern"/>
  2685. </p:judgement>
  2686. <p:not>
  2687. <p:judgement name="contentType">
  2688. <p:var range="pattern"/>
  2689. <p:var range="contentType"/>
  2690. </p:judgement>
  2691. </p:not>
  2692. <p:judgement name="incorrectSchema"/>
  2693. </p:rule>
  2694. </p:proofSystem>
  2695. </section>
  2696. <section id="attribute-restrictions">
  2697. <title>Restrictions on attributes</title>
  2698. <para>Duplicate attributes are not allowed. More precisely, for a
  2699. pattern <literal>&lt;group> <replaceable>p1</replaceable>
  2700. <replaceable>p2</replaceable> &lt;/group></literal> or
  2701. <literal>&lt;interleave> <replaceable>p1</replaceable>
  2702. <replaceable>p2</replaceable> &lt;/interleave></literal>, there must
  2703. not be a name that belongs to both the name class of an
  2704. <literal>attribute</literal> pattern occurring in
  2705. <replaceable>p1</replaceable> and the name class of an
  2706. <literal>attribute</literal> pattern occurring in
  2707. <replaceable>p2</replaceable>. A pattern <replaceable>p1</replaceable>
  2708. is defined to <firstterm>occur in</firstterm> a pattern
  2709. <replaceable>p2</replaceable> if</para>
  2710. <itemizedlist>
  2711. <listitem><para><replaceable>p1</replaceable> is
  2712. <replaceable>p2</replaceable>, or</para></listitem>
  2713. <listitem><para><replaceable>p2</replaceable> is a
  2714. <literal>choice</literal>, <literal>interleave</literal>,
  2715. <literal>group</literal> or <literal>oneOrMore</literal> element and
  2716. <replaceable>p1</replaceable> occurs in one or more children of
  2717. <replaceable>p2</replaceable>.</para></listitem>
  2718. </itemizedlist>
  2719. <para>Attributes using infinite name classes must be repeated. More
  2720. precisely, an <literal>attribute</literal> element that has an
  2721. <literal>anyName</literal> or <literal>nsName</literal> descendant
  2722. element must have a <literal>oneOrMore</literal> ancestor
  2723. element.</para>
  2724. <note><para>This restriction is necessary for closure under
  2725. negation.</para></note>
  2726. </section>
  2727. <section id="interleave-restrictions">
  2728. <title>Restrictions on <literal>interleave</literal></title>
  2729. <para>For a pattern <literal>&lt;interleave>
  2730. <replaceable>p1</replaceable> <replaceable>p2</replaceable>
  2731. &lt;/interleave></literal>,</para>
  2732. <itemizedlist>
  2733. <listitem><para>there must not be a name that belongs to both the name
  2734. class of an <literal>element</literal> pattern referenced by a
  2735. <literal>ref</literal> pattern occurring in
  2736. <replaceable>p1</replaceable> and the name class of an
  2737. <literal>element</literal> pattern referenced by a
  2738. <literal>ref</literal> pattern occurring in
  2739. <replaceable>p2</replaceable>, and</para></listitem>
  2740. <listitem><para>a <literal>text</literal> pattern must not occur in
  2741. both <replaceable>p1</replaceable> and
  2742. <replaceable>p2</replaceable>.</para></listitem>
  2743. </itemizedlist>
  2744. <para><xref linkend="attribute-restrictions"/> defines when one
  2745. pattern is considered to occur in another pattern.</para>
  2746. </section>
  2747. </section>
  2748. <section id="conformance">
  2749. <title>Conformance</title>
  2750. <para>A conforming RELAX NG validator must be able to determine for
  2751. any XML document whether it is a correct RELAX NG schema. A
  2752. conforming RELAX NG validator must be able to determine for any XML
  2753. document and for any correct RELAX NG schema whether the document is
  2754. valid with respect to the schema.</para>
  2755. <para>However, the requirements in the preceding paragraph do not
  2756. apply if the schema uses a datatype library that the validator does
  2757. not support. A conforming RELAX NG validator is only required to
  2758. support the built-in datatype library described in <xref
  2759. linkend="built-in-datatype"/>. A validator that claims conformance to
  2760. RELAX NG should document which datatype libraries it supports. The
  2761. requirements in the preceding paragraph also do not apply if the
  2762. schema includes <literal>externalRef</literal> or
  2763. <literal>include</literal> elements and the validator is unable to
  2764. retrieve the resource identified by the URI or is unable to construct
  2765. an element from the retrieved resource. A validator that claims
  2766. conformance to RELAX NG should document its capabilities for handling
  2767. URI references.</para>
  2768. </section>
  2769. <appendix>
  2770. <title>RELAX NG schema for RELAX NG</title>
  2771. <rngref src="relaxng.rng"/>
  2772. </appendix>
  2773. <appendix>
  2774. <title>Changes since version 0.9</title>
  2775. <para>The changes in this version relative to version 0.9
  2776. are as follows:</para>
  2777. <itemizedlist>
  2778. <listitem><para>in the namespace URI, <literal>0.9</literal> has been
  2779. changed to <literal>1.0</literal></para></listitem>
  2780. <listitem><para><literal>data/except//empty</literal> has been added
  2781. as a prohibited path (see <xref
  2782. linkend="context-data-except"/>)</para></listitem>
  2783. <listitem><para><literal>start//empty</literal> has been added
  2784. as a prohibited path (see <xref
  2785. linkend="context-start"/>)</para></listitem>
  2786. <listitem><para><xref linkend="number-child-elements"/> now specifies how a
  2787. <literal>list</literal> element with more than one child element is
  2788. transformed</para></listitem>
  2789. <listitem><para><xref linkend="notAllowed"/> now specifies how a
  2790. <literal>notAllowed</literal> element occurring in an
  2791. <literal>except</literal> element is transformed</para></listitem>
  2792. <listitem><para>although a relative URI is not allowed as the value of
  2793. the <literal>ns</literal> and <literal>datatypeLibrary</literal>
  2794. attributes, an empty string is allowed (see <xref
  2795. linkend="full-syntax"/>)</para></listitem>
  2796. <listitem><para>the removal of unreachable definitions in <xref
  2797. linkend="define-ref"/> is now correctly specified</para></listitem>
  2798. <listitem><para><xref linkend="notAllowed"/> now specifies that
  2799. <literal>define</literal> elements that are no longer reachable are
  2800. removed</para></listitem>
  2801. <listitem><para><xref linkend="constraints"/> has been added; the
  2802. restrictions on the contents of <literal>except</literal> in name
  2803. classes that are now specified in the newly added section were
  2804. previously specified in a subsection of <xref
  2805. linkend="contextual-restriction"/>, which has been
  2806. removed</para></listitem>
  2807. <listitem><para>the treatment of element and attribute values that
  2808. consist only of whitespace has been refined (see <xref
  2809. linkend="element-pattern"/> and <xref
  2810. linkend="data-pattern"/>)</para></listitem>
  2811. <listitem><para>attributes with infinite name classes are now required
  2812. to be repeated (see <xref
  2813. linkend="attribute-restrictions"/>)</para></listitem>
  2814. <listitem><para>restrictions have been imposed on
  2815. <literal>interleave</literal> (see <xref
  2816. linkend="interleave-restrictions"/>); <literal>list//interleave</literal>
  2817. has been added as a prohibited path (see <xref
  2818. linkend="list-restrictions"/>)</para></listitem>
  2819. <listitem><para>some of the prohibited paths in <xref
  2820. linkend="contextual-restriction"/> have been corrected to use
  2821. <literal>ref</literal> rather than
  2822. <literal>element</literal></para></listitem>
  2823. <listitem><para>an error in the inference rule (text 1) in <xref
  2824. linkend="text-pattern"/> has been corrected</para></listitem>
  2825. <listitem><para>the value of the <literal>ns</literal> attribute is
  2826. now unconstrained (see <xref
  2827. linkend="full-syntax"/>)</para></listitem>
  2828. </itemizedlist>
  2829. </appendix>
  2830. <appendix>
  2831. <title>RELAX NG TC (Non-Normative)</title>
  2832. <para>This specification was prepared and approved for publication by
  2833. the RELAX NG TC. The current members of the TC are:</para>
  2834. <itemizedlist>
  2835. <listitem><para>Fabio Arciniegas</para></listitem>
  2836. <listitem><para>James Clark</para></listitem>
  2837. <listitem><para>Mike Fitzgerald</para></listitem>
  2838. <listitem><para>KAWAGUCHI Kohsuke</para></listitem>
  2839. <listitem><para>Josh Lubell</para></listitem>
  2840. <listitem><para>MURATA Makoto</para></listitem>
  2841. <listitem><para>Norman Walsh</para></listitem>
  2842. <listitem><para>David Webber</para></listitem>
  2843. </itemizedlist>
  2844. </appendix>
  2845. <bibliography><title>References</title>
  2846. <bibliodiv><title>Normative</title>
  2847. <bibliomixed id="xml-rec"><abbrev>XML 1.0</abbrev>Tim Bray,
  2848. Jean Paoli, and
  2849. C. M. Sperberg-McQueen, Eve Maler, editors.
  2850. <citetitle><ulink url="http://www.w3.org/TR/REC-xml">Extensible Markup
  2851. Language (XML) 1.0 Second Edition</ulink></citetitle>.
  2852. W3C (World Wide Web Consortium), 2000.</bibliomixed>
  2853. <bibliomixed id="xml-names"><abbrev>XML Namespaces</abbrev>Tim Bray,
  2854. Dave Hollander,
  2855. and Andrew Layman, editors.
  2856. <citetitle><ulink url="http://www.w3.org/TR/REC-xml-names/">Namespaces in
  2857. XML</ulink></citetitle>.
  2858. W3C (World Wide Web Consortium), 1999.</bibliomixed>
  2859. <bibliomixed id="xlink"><abbrev>XLink</abbrev>Steve DeRose, Eve Maler
  2860. and David Orchard, editors.
  2861. <citetitle><ulink url="http://www.w3.org/TR/xlink/">XML Linking
  2862. Language (XLink) Version 1.0</ulink></citetitle>.
  2863. W3C (World Wide Web Consortium), 2001.</bibliomixed>
  2864. <bibliomixed id="infoset"><abbrev>XML Infoset</abbrev>John Cowan, Richard Tobin,
  2865. editors.
  2866. <citetitle><ulink url="http://www.w3.org/TR/xml-infoset/">XML
  2867. Information Set</ulink></citetitle>.
  2868. W3C (World Wide Web Consortium), 2001.</bibliomixed>
  2869. <bibliomixed id="rfc2396"><abbrev>RFC 2396</abbrev>T. Berners-Lee, R. Fielding, L. Masinter.
  2870. <citetitle><ulink url="http://www.ietf.org/rfc/rfc2396.txt" >RFC 2396:
  2871. Uniform Resource Identifiers (URI): Generic
  2872. Syntax</ulink></citetitle>.
  2873. IETF (Internet Engineering Task Force). 1998.</bibliomixed>
  2874. <bibliomixed id="rfc2732"><abbrev>RFC 2732</abbrev>R. Hinden, B. Carpenter, L. Masinter.
  2875. <citetitle><ulink url="http://www.ietf.org/rfc/rfc2732.txt">RFC 2732: Format for Literal IPv6 Addresses in URL's</ulink></citetitle>.
  2876. IETF (Internet Engineering Task Force), 1999.</bibliomixed>
  2877. <bibliomixed id="rfc3023"><abbrev>RFC 3023</abbrev> M. Murata,
  2878. S. St.Laurent, D. Kohn. <citetitle><ulink
  2879. url="http://www.ietf.org/rfc/rfc3023.txt">RFC 3023: XML Media
  2880. Types</ulink></citetitle>. IETF (Internet Engineering Task Force),
  2881. 2001.</bibliomixed>
  2882. </bibliodiv>
  2883. <bibliodiv><title>Non-Normative</title>
  2884. <bibliomixed id="xmlschema-2"><abbrev>W3C XML Schema Datatypes</abbrev>Paul V. Biron, Ashok Malhotra, editors.
  2885. <citetitle><ulink url="http://www.w3.org/TR/xmlschema-2/">XML Schema Part 2: Datatypes</ulink></citetitle>.
  2886. W3C (World Wide Web Consortium), 2001.</bibliomixed>
  2887. <bibliomixed id="trex"><abbrev>TREX</abbrev>James Clark.
  2888. <citetitle><ulink url="http://www.thaiopensource.com/trex/">TREX - Tree Regular Expressions for XML</ulink></citetitle>.
  2889. Thai Open Source Software Center, 2001.</bibliomixed>
  2890. <bibliomixed id="relax"><abbrev>RELAX</abbrev>MURATA Makoto.
  2891. <citetitle><ulink url="http://www.xml.gr.jp/relax/">RELAX (Regular
  2892. Language description for XML)</ulink></citetitle>. INSTAC
  2893. (Information Technology Research and Standardization Center), 2001.</bibliomixed>
  2894. <bibliomixed id="xsfd"><abbrev>XML Schema Formal</abbrev>Allen Brown,
  2895. Matthew Fuchs, Jonathan Robie, Philip Wadler, editors.
  2896. <citetitle><ulink url="http://www.w3.org/TR/xmlschema-formal/">XML Schema: Formal Description</ulink></citetitle>.
  2897. W3C (World Wide Web Consortium), 2001.</bibliomixed>
  2898. <bibliomixed id="tutorial"><abbrev>Tutorial</abbrev>James Clark,
  2899. Makoto MURATA, editors. <citetitle><ulink
  2900. url="http://www.oasis-open.org/committees/relax-ng/tutorial.html">RELAX
  2901. NG Tutorial</ulink></citetitle>. OASIS, 2001.</bibliomixed>
  2902. </bibliodiv>
  2903. </bibliography>
  2904. </article>