datatypes w = "http://whattf.org/datatype-draft"

# #####################################################################
##  RELAX NG Schema for HTML 5: Global Structure & Metadata          #
# #####################################################################

## Root Element: <html>

	html.elem =
		element html { html.inner & html.attrs }
	html.attrs =
		( common.attrs )
	html.inner =
		(	head.elem
		,	body.elem
		)

## Metadata Container: <head>

	head.elem =
		element head { head.inner & head.attrs }
	head.attrs =
		(	common.attrs
#		&	head.attrs.profile?
		)
#		head.attrs.profile =
#			attribute profile {
#				common.data.uris #REVISIT should these be absolute (zero or more)
#			}
	head.inner =
		(	title.elem
		&	base.elem? # REVISIT need a non-schema checker or Schematron
		&	common.inner.metadata # Limit encoding decl position in Schematron
		)
#	head.inner =
#		(	meta.elem.encoding?
#		,	(	title.elem
#			&	base.elem? # REVISIT need a non-schema checker or Schematron
#			&	common.inner.metadata
#			)
#		)
		
## Content Container: <body>

	body.elem =
		element body { body.inner & body.attrs }
	body.attrs =
		(	common.attrs
		&	(	common.attrs.aria.role.application
			|	common.attrs.aria.landmark.document
			|	common.attrs.aria.role.presentation
			|	common.attrs.aria.implicit.document
			)?
		&	body.attrs.onafterprint?
		&	body.attrs.onbeforeprint?
		&	body.attrs.onbeforeunload?
		&	body.attrs.onhashchange?
		&	body.attrs.onlanguagechange?
		&	body.attrs.onmessage?
		&	body.attrs.onmessageerror?
		&	body.attrs.onoffline?
		&	body.attrs.ononline?
		&	body.attrs.onpagehide?
		&	body.attrs.onpagereveal?
		&	body.attrs.onpageshow?
		&	body.attrs.onpageswap?
		&	body.attrs.onpopstate?
		&	body.attrs.onrejectionhandled?
		&	body.attrs.onstorage?
		&	body.attrs.onunhandledrejection?
		&	body.attrs.onunload?
		)
	body.inner =
		( common.inner.flow )

	body.attrs.onafterprint =
		attribute onafterprint { common.data.functionbody }
	body.attrs.onbeforeprint =
		attribute onbeforeprint { common.data.functionbody }
	body.attrs.onbeforeunload =
		attribute onbeforeunload { common.data.functionbody }
	body.attrs.onhashchange =
		attribute onhashchange { common.data.functionbody }
	body.attrs.onlanguagechange =
		attribute onlanguagechange { common.data.functionbody }
	body.attrs.onmessage =
		attribute onmessage { common.data.functionbody }
	body.attrs.onmessageerror =
		attribute onmessageerror { common.data.functionbody }
	body.attrs.onoffline =
		attribute onoffline { common.data.functionbody }
	body.attrs.ononline =
		attribute ononline { common.data.functionbody }
	body.attrs.onpagehide =
		attribute onpagehide { common.data.functionbody }
	body.attrs.onpagereveal =
		attribute onpagereveal { common.data.functionbody }
	body.attrs.onpageswap =
		attribute onpageswap { common.data.functionbody }
	body.attrs.onpageshow =
		attribute onpageshow { common.data.functionbody }
	body.attrs.onpopstate =
		attribute onpopstate { common.data.functionbody }
	body.attrs.onrejectionhandled =
		attribute onrejectionhandled { common.data.functionbody }
	body.attrs.onstorage =
		attribute onstorage { common.data.functionbody }
	body.attrs.onunhandledrejection =
		attribute onunhandledrejection { common.data.functionbody }
	body.attrs.onunload =
		attribute onunload { common.data.functionbody }

## Document Title: <title>

	title.elem =
		element title { title.inner & title.attrs }
	title.attrs =
		( common.attrs )
	title.inner =
		( text )

## Base URI: <base>

	base.elem =
		element base { base.inner & base.attrs }
	base.attrs =
		(	common.attrs.basic
		&	common.attrs.i18n
		&	common.attrs.present
		&	common.attrs.other
		&	(	(	base.attrs.href
				&	base.attrs.target?
				)
			|	base.attrs.target
			)
		)
	base.attrs.href =
		attribute href {
			common.data.uri
		}
	base.attrs.target =
		attribute target {
			common.data.browsing-context-or-keyword
		}
	base.inner =
		( empty )

## Global Relationships: <link>

	link.elem =
		element link { link.inner & link.attrs }
	link.attrs =
		(	common.attrs.basic
		&	common.attrs.i18n
		&	common.attrs.present
		&	common.attrs.other
		&	link.attrs.rel
		&	link.attrs.href?
		&	link.attrs.as?
		&	link.attrs.integrity?
		&	shared-hyperlink.attrs.hreflang?
		&	shared-hyperlink.attrs.media?
		&	shared-hyperlink.attrs.type?
		&	referrerpolicy?
		&	link.attrs.sizes?
		&	link.attrs.color?
		&	link.attrs.disabled?
		&	link.attrs.scope?
		&	link.attrs.updateviacache?
		&	link.attrs.workertype?
		&	link.attrs.imagesrcset?
		&	link.attrs.imagesizes?
		&	common.attrs.fetchpriority?
		#	link.attrs.title included in common.attrs
		&	embedded.content.attrs.crossorigin?
		&	common.attrs.blocking?
		&	common.attrs.aria.role.link?
		)
		link.attrs.href =
			attribute href {
				common.data.uri.non-empty
			}
		link.attrs.rel =
			attribute rel {
				w:rel-value
			}
		link.attrs.as =
			attribute as {
				string "audioworklet"
			|	string "fetch"
			|	string "font"
			|	string "image"
			|	string "json"
			|	string "paintworklet"
			|	string "script"
			|	string "serviceworker"
			|	string "sharedworker"
			|	string "style"
			|	string "track"
			|	string "worker"
			}
		link.attrs.integrity =
			attribute integrity {
				common.data.integrity
			}
		link.attrs.sizes =
			attribute sizes {
				w:string "any" | common.data.sizes
			}
		link.attrs.color =
			attribute color {
				common.data.color
			}
		link.attrs.disabled =
			attribute disabled {
				w:string "disabled" | w:string ""
			}
		link.attrs.scope =
			attribute scope {
				common.data.uri
			}
		link.attrs.updateviacache =
			attribute updateviacache {
				string "imports"
			|	string "all"
			|	string "none"
			}
		link.attrs.workertype =
			attribute workertype {
				string "classic"
			|	string "module"
			}
		link.attrs.imagesrcset =
			attribute imagesrcset {
				string
			} & v5only
		link.attrs.imagesizes =
			attribute imagesizes {
				common.data.source.size.list
			} & v5only
	link.inner =
		( empty )
		
	common.elem.metadata |= link.elem
	common.elem.phrasing |= link.elem
	common.elem.flow |= link.elem

## Global Style: <style>

	style.elem =
		element style { style.inner & style.attrs }
	style.attrs =
		(	common.attrs
		&	style.attrs.media?
		&	common.attrs.blocking?
		#	style.attrs.title included in common.attrs
		)
		style.attrs.media =
			attribute media {
				common.data.mediaquery
			}
	style.inner =
		( common.inner.anything )
		
	common.elem.metadata |= style.elem

## Name-Value Metadata: <meta name>

	meta.name.elem =
		element meta { meta.inner & meta.name.attrs }
	meta.name.attrs =
		(	common.attrs.basic
		&	common.attrs.i18n
		&	common.attrs.present
		&	common.attrs.other
		&	meta.name.attrs.name
		&	meta.name.attrs.content
		&	common.attrs.microdata.itemref?
		&	common.attrs.microdata.itemscope?
		&	common.attrs.microdata.itemtype?
		&	common.attrs.microdata.itemid?
		&	shared-hyperlink.attrs.media?
		)
		meta.name.attrs.name =
			attribute name {
				w:non-empty-string
			}
		meta.name.attrs.content =
			attribute content {
				string
			}
	meta.inner =
		( empty )
		
	common.elem.metadata |= meta.name.elem

## "refresh" pragma directive: <meta http-equiv='refresh'>

	meta.http-equiv.refresh.elem =
		element meta { meta.inner & meta.http-equiv.refresh.attrs }
	meta.http-equiv.refresh.attrs =
		(	common.attrs.basic
		&	common.attrs.i18n
		&	common.attrs.present
		&	common.attrs.other
		&	meta.http-equiv.attrs.http-equiv.refresh
		&	meta.http-equiv.attrs.content.refresh
		)
		meta.http-equiv.attrs.http-equiv.refresh =
			attribute http-equiv {
				w:string "refresh"
			}
		meta.http-equiv.attrs.content.refresh =
			attribute content { 
				common.data.refresh
			}
	common.elem.metadata |= meta.http-equiv.refresh.elem # not quite right per spec
                                                       # if the definition is 
                                                       # reused in another language

## "default-style" pragma directive: <meta http-equiv='default-style'>

	meta.http-equiv.default-style.elem =
		element meta { meta.inner & meta.http-equiv.default-style.attrs }
	meta.http-equiv.default-style.attrs =
		(	common.attrs.basic
		&	common.attrs.i18n
		&	common.attrs.present
		&	common.attrs.other
		&	meta.http-equiv.attrs.http-equiv.default-style
		&	meta.http-equiv.attrs.content.default-style
		)
		meta.http-equiv.attrs.http-equiv.default-style =
			attribute http-equiv {
				w:string "default-style"
			}
		meta.http-equiv.attrs.content.default-style =
			attribute content {
				common.data.default-style
			}
		
	common.elem.metadata |= meta.http-equiv.default-style.elem # not quite right per spec
                                                               # if the definition is 
                                                               # reused in another language

## Content Security Policy pragma directive: <meta http-equiv='content-security-policy'>

	meta.http-equiv.content-security-policy.elem =
		element meta { meta.inner & meta.http-equiv.content-security-policy.attrs }
	meta.http-equiv.content-security-policy.attrs =
		(	common.attrs.basic
		&	common.attrs.i18n
		&	common.attrs.present
		&	common.attrs.other
		&	meta.http-equiv.attrs.http-equiv.content-security-policy
		&	meta.http-equiv.attrs.content.content-security-policy
		)
		meta.http-equiv.attrs.http-equiv.content-security-policy =
			attribute http-equiv {
				w:string "content-security-policy"
			}
		meta.http-equiv.attrs.content.content-security-policy =
			attribute content {
				common.data.content-security-policy
			}
	common.elem.metadata |= meta.http-equiv.content-security-policy.elem

## "x-ua-compatible" pragma directive: <meta http-equiv='x-ua-compatible'>

	meta.http-equiv.x-ua-compatible.elem =
		element meta { meta.inner & meta.http-equiv.x-ua-compatible.attrs }
	meta.http-equiv.x-ua-compatible.attrs =
		(	common.attrs.basic
		&	common.attrs.i18n
		&	common.attrs.present
		&	common.attrs.other
		&	meta.http-equiv.attrs.http-equiv.x-ua-compatible
		&	meta.http-equiv.attrs.content.x-ua-compatible
		)
		meta.http-equiv.attrs.http-equiv.x-ua-compatible =
			attribute http-equiv {
				w:string "x-ua-compatible"
			}
		meta.http-equiv.attrs.content.x-ua-compatible =
			attribute content {
				common.data.x-ua-compatible
			}
	common.elem.metadata |= meta.http-equiv.x-ua-compatible.elem

## Inline Character Encoding Statement for HTML: <meta charset>

	meta.charset.elem =
		element meta { meta.inner & meta.charset.attrs }
	meta.charset.attrs =
		(	common.attrs.basic
		&	common.attrs.i18n
		&	common.attrs.present
		&	common.attrs.other
		&	meta.charset.attrs.charset
		)
		meta.charset.attrs.charset =
			attribute charset {
				(string & HTMLonly)
				| (xsd:string {
					pattern = "[uU][tT][fF]-8"
				} & XMLonly )
			} 

## Inline Character Encoding Statement for HTML: <meta http-equiv='content-type'>

	meta.http-equiv.content-type.elem =
		element meta { meta.inner & meta.http-equiv.content-type.attrs }
		& HTMLonly
	meta.http-equiv.content-type.attrs =
		(	common.attrs.basic
		&	common.attrs.i18n
		&	common.attrs.present
		&	common.attrs.other
		&	meta.http-equiv.attrs.http-equiv.content-type
		&	meta.http-equiv.attrs.content.content-type
		)
		meta.http-equiv.attrs.http-equiv.content-type =
			attribute http-equiv {
				w:string "content-type"
			}
		meta.http-equiv.attrs.content.content-type =
			attribute content {
				common.data.meta-charset
			}

	common.elem.metadata |= ( meta.charset.elem | meta.http-equiv.content-type.elem )
