[ xml:id = "datatypes-common" ]
div {
  datatype.ID = datatype.ID.lexical
  datatype.IDREF = datatype.IDREF.lexical
  datatype.IDREFS = datatype.IDREFS.lexical
    
  datatype.languagecode = datatype.BCP47
  # http://www.w3.org/TR/xmlschema11-2/#language
  datatype.BCP47 = xsd:language { pattern = "[a-zA-Z]{1,8}(-[a-zA-Z0-9]{1,8})*" }
  # http://www.w3.org/TR/xmlschema11-2/#ID  
  datatype.ID.xsd = xsd:ID
  # http://www.w3.org/TR/xmlschema11-2/#NCName
  datatype.IDREF.lexical = xsd:NCName
  datatype.IDREFS.lexical = list { datatype.IDREF.lexical+ }
  datatype.ID.lexical = xsd:NCName
  # http://www.w3.org/TR/xmlschema11-2/#IDREF
  datatype.IDREF.xsd = xsd:IDREF
  # http://www.w3.org/TR/xmlschema11-2/#IDREFS
  datatype.IDREFS.xsd = xsd:IDREFS  
  # http://www.w3.org/TR/xmlschema11-2/#NMTOKEN
  datatype.NMTOKEN = xsd:NMTOKEN
  # http://www.w3.org/TR/xmlschema11-2/#NMTOKENS  
  datatype.NMTOKENS = xsd:NMTOKENS
  # http://www.w3.org/TR/xmlschema11-2/#string
  datatype.string = xsd:string
  datatype.string.nonempty = xsd:token { minLength='1' }    
  datatype.text = text
  # http://www.w3.org/TR/xmlschema11-2/#nt-dateRep
  datatype.date = xsd:date
  # http://www.w3.org/TR/xmlschema11-2/#nt-dateTimeRep
  datatype.dateTime = xsd:dateTime
  # http://www.w3.org/TR/xmlschema11-2/#nt-timeRep
  datatype.date.or.dateTime = datatype.date | datatype.dateTime     
  datatype.LEIRI = xsd:anyURI
  # http://www.w3.org/TR/xmlschema11-2/#anyURI
  # http://tools.ietf.org/html/rfc3986#appendix-B
  # http://www.w3.org/TR/html5/urls.html#valid-url-potentially-surrounded-by-spaces  
  datatype.URI = xsd:anyURI
  datatype.URI.absolute = xsd:anyURI
  datatype.IRI = datatype.URI  
  datatype.character.encoding = datatype.iana.charset
  datatype.iana.charset = xsd:NMTOKEN  
  # http://www.w3.org/TR/html5/infrastructure.html#valid-mime-type
  # http://tools.ietf.org/html/rfc4288#section-4.2
  # http://tools.ietf.org/html/rfc2616#section-3.7
  datatype.mimetype = xsd:string { pattern='[a-zA-Z0-9!#$&+\-\^_]+/[a-zA-Z0-9!#$&+\-\^_]+.*' }  
  datatype.mimetype.nocharset = datatype.mimetype
  # http://www.w3.org/TR/xmlschema11-2/#nonNegativeInteger
  # http://www.w3.org/TR/html5/common-microsyntaxes.html#non-negative-integers
  datatype.non-negative.integer = xsd:nonNegativeInteger
  # http://www.w3.org/TR/xmlschema11-2/#positiveInteger
  datatype.positive.integer = xsd:positiveInteger
  # http://www.w3.org/TR/xmlschema11-2/#integer  
  datatype.integer = xsd:integer
  # http://www.w3.org/TR/xmlschema11-2/#nt-floatRep
  # http://www.w3.org/TR/html5/common-microsyntaxes.html#real-numbers
  datatype.float = xsd:float
  datatype.float.positive = xsd:float { minExclusive = '0'}
  datatype.float.non-negative = xsd:float { minInclusive = '0' }
  
}
[ xml:id = "datatypes-smil" ]
div {
  # http://www.w3.org/TR/smil/smil-timing.html#TimingSyntax-Full-clock-value
  # http://www.w3.org/TR/smil/smil-timing.html#TimingSyntax-Partial-clock-value
  # http://www.w3.org/TR/smil/smil-timing.html#TimingSyntax-Timecount-value
  datatype.smil.npt =
    xsd:string { pattern = "(\s*)[0-9]+:[0-5][0-9]:[0-5][0-9](\.[0-9]+)?(\s*)" }
  | xsd:string { pattern = "(\s*)[0-5][0-9]:[0-5][0-9](\.[0-9]+)?(\s*)" }
  | xsd:string { pattern = "(\s*)[0-9]+(\.[0-9]+)?(h|min|s|ms)?(\s*)" }          
}

[ xml:id = "datatypes-vocab" ]
div {
  datatype.property = xsd:NMTOKEN
  datatype.properties = xsd:NMTOKENS
  datatype.prefixdecl = text  #\s*([\i-[:]][\c-[:]]*: +[^ ]+)(\s+[\i-[:]][\c-[:]]*: +[^ ]+)*\s*
}

[ xml:id = "datatypes-ssml" ]
div {
  # http://www.w3.org/TR/speech-synthesis11/#edef_phoneme
  datatype.ssml.PhoneticExpression = xsd:string
  datatype.ssml.PhoneticAlphabet = xsd:string { pattern = "(ipa|x-.+)" }
}

[ xml:id = "datatypes-html5" ]
div {
  datatype.html5.browsing.context.name.or.keyword = xsd:string { pattern = "()|([^_].*)|(_[bB][lL][aA][nN][kK])|(_[sS][eE][lL][fF])|(_[pP][aA][rR][eE][nN][tT])|(_[tT][oO][pP])" }
  datatype.html5.browsing.context.name = xsd:string { pattern = "()|([^_].*)" }  
  datatype.html5.token = xsd:string { pattern = '[^\s]+' }
  # http://www.w3.org/TR/html5/common-microsyntaxes.html#space-separated-tokens
  datatype.html5.space.separated.tokens = list { datatype.html5.token* }
  datatype.html5.ordered.set.unique.tokens = datatype.html5.space.separated.tokens  
  datatype.html5.URL.spaces = datatype.URI
  # http://dev.w3.org/csswg/css3-mediaqueries/#syntax
  # http://www.w3.org/TR/html5/common-microsyntaxes.html#mq
  datatype.html5.media.query = xsd:string
  datatype.html5.name = xsd:string
  datatype.html5.name.reference = xsd:string { pattern = "#.+" }
  
  # http://www.w3.org/TR/html5/common-microsyntaxes.html#months
  datatype.html5.month = xsd:token { pattern ='([0-9]{4,})-([0-9]{2})' }  
  # http://www.w3.org/TR/html5/common-microsyntaxes.html#dates
  datatype.html5.date = xsd:token { pattern ='([0-9]{4,})-([0-9]{2})-([0-9]{2})'}
  # http://www.w3.org/TR/html5/common-microsyntaxes.html#times
  datatype.html5.time = xsd:token { pattern ='([0-9]{2}):([0-9]{2})(:[0-9]{2}(\.[0-9]+)?)?'}
  # http://www.w3.org/TR/html5/common-microsyntaxes.html#local-dates-and-times
  datatype.html5.datetime.local = xsd:token { pattern = '([0-9]{4,})-([0-9]{2})-([0-9]{2})T([0-9]{2}):([0-9]{2})(:[0-9]{2}(\.[0-9]+)?)?' }
  # http://www.w3.org/TR/html5/common-microsyntaxes.html#global-dates-and-times
  datatype.html5.datetime.global = xsd:token { pattern = '([0-9]{4,})-([0-9]{2})-([0-9]{2})T([0-9]{2}):([0-9]{2})(:[0-9]{2}(\.[0-9]+)?)?(Z|((\+|-)([0-9]{2}):([0-9]{2})))' }  
  datatype.html5.datetime = datatype.html5.datetime.global
  # http://www.w3.org/TR/html5/common-microsyntaxes.html#vaguer-moments-in-time
  datatype.html5.date.or.time = datatype.html5.date | datatype.html5.time | datatype.html5.datetime.global
  # http://www.w3.org/TR/html5/common-microsyntaxes.html#vaguer-moments-in-time
  datatype.html5.date.optional.time = datatype.html5.date | datatype.html5.datetime.global
  datatype.html5.week = xsd:token { pattern ='([0-9]{4,})-W([0-9]{2})' }
  
  datatype.html5.accesskey = datatype.html5.ordered.set.unique.tokens
  datatype.html5.coords.rectangle = xsd:token { pattern = "-?[0-9]+,-?[0-9]+,-?[0-9]+,-?[0-9]+" }
  datatype.html5.coords.circle = xsd:token { pattern = "-?[0-9]+,-?[0-9]+,[0-9]+" }
  datatype.html5.coords.poly = xsd:token { pattern = "-?[0-9]+,-?[0-9]+,-?[0-9]+,-?[0-9]+,-?[0-9]+,-?[0-9]+(,-?[0-9]+,-?[0-9]+)*" }
  datatype.html5.js = xsd:string
  datatype.html5.script = xsd:string
  datatype.html5.script.documentation = xsd:string
  datatype.html5.iframe.srcdoc.xml = xsd:string
  datatype.style = xsd:string
  datatype.html5.sizes = list { xsd:string { pattern = "[1-9][0-9]*x[1-9][0-9]*" }+ }
  datatype.html5.emailaddress = xsd:string { pattern = "[^@]+@[^@]+" }
  datatype.html5.emailaddresslist = xsd:string { pattern = "([^@]+@[^@]+,)*([^@]+@[^@]+)" }
  # http://www.w3.org/TR/html5/common-microsyntaxes.html#colors
  datatype.html5.color = xsd:string { pattern = '#([A-Fa-f0-9]{6})' }
}

[ xml:id = "datatypes-html5forms" ]
div {
  datatype.html5.forms.mimetypelist = xsd:string
  # http://www.w3.org/TR/html5/forms.html#attr-form-accept-charset
  datatype.html5.forms.charsetlist = list { datatype.character.encoding+ }
  datatype.html5.forms.pattern = xsd:string  
  datatype.html5.forms.string.nolinebreaks = xsd:string 
}

