RelaxNG/publiset.rnc
author iinov
dim., 21 oct. 2018 16:02:16 +0200
changeset 465 4e3338f519f9
parent 448 9bc794bf36b0
permissions -rw-r--r--
Dictée

start = publiset


publiset = element publiset {
   publiset.attributes,
   publiset.content
}

publiset.attributes =
   version.attribute
version.attribute = attribute version { "1.0" }

publiset.content =
   composition
 | selection


# =============================================================================
#                                  HEAD LEVEL
# =============================================================================

# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ title, subtitle ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

title = element title { title.content }
shorttitle = element shorttitle { title.content }
subtitle = element subtitle { title.content }

title.content = inlines

# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ identifier ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

# ~~~~~~ identifier
identifier = element identifier {
   (attribute type { "ean" }, for.attribute?, xsd:token {pattern = "\d{13}"})
 | (attribute type { "uri" }, for.attribute?, xsd:anyURI)
}

for.attribute = attribute for { xsd:NCName }

# ~~~~~~ identifier.ean
identifier.ean = element identifier {
   attribute type { "ean" }, for.attribute?, xsd:token {pattern = "\d{13}"}
}

# ~~~~~~ identifier.uri
identifier.uri = element identifier {
   attribute type { "uri" }, for.attribute?, xsd:anyURI
}

# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ copyright ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

copyright = element copyright { copyright.content }

copyright.content = simple.inlines

# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ collection ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

collection = element collection { collection.content }

collection.content = simple.inlines

# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ contributors ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

# ~~~~~~ contributors
contributors = element contributors { contributors.content }

contributors.content =
   contributor+

# ~~~~~~ contributor
contributor = element contributor { contributor.content }

contributor.content =
   identifier.uri?,
   (((firstname, secondname?)?, lastname) | label),
   address?,
   link?,
   role+

# ~~~~~~ firstname, secondname, lastname, label
firstname = element firstname { firstname.content }
secondname = element secondname { secondname.content }
lastname = element lastname { lastname.content }
label = element label { label.content }

firstname.content = simple.inlines
secondname.content = simple.inlines
lastname.content = simple.inlines
label.content = simple.inlines

# ~~~~~~ address
address = element address { address.content }

address.content = simple.inlines

# ~~~~~~ role
role = element role { role.content }

role.content = "author" | "illustrator" | "photographer" | "publisher"
    | "packager" | "translator"

# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ source ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

source = element source {
   (  (attribute type { "book" }, source.content.book)
    | (attribute type { "file" }, source.content.file))
}

source.content.book =
   identifier.ean?
 & title
 & subtitle?
 & copyright?
 & collection?
 & folio?
 & pages?

source.content.file =
   identifier.uri

# ~~~~~~ folio
folio = element folio { folio.content }

folio.content = xsd:positiveInteger | xsd:token {pattern = "[DLXVI]+"}

# ~~~~~~ pages
pages = element pages { pages.content }

pages.content = xsd:positiveInteger

# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ keyword & subject ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

# ~~~~~~ keywordset
keywordset = element keywordset { keywordset.content }

keywordset.content = keyword+

# ~~~~~~ keyword
keyword = element keyword { keyword.content }

keyword.content = simple.inlines

# ~~~~~~ subjectset
subjectset = element subjectset { subjectset.content }

subjectset.content = subject+

# ~~~~~~ subject
subject = element subject { subject.content }

subject.content = simple.inlines

# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ index ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

# ~~~~~~ indexset
indexset = element indexset { indexset.content }

indexset.content = head.index+

# ~~~~~~ index
head.index = element index { head.index.content }

head.index.content =
   index.entry, index.entry?

# ~~~~~~ index.entry
index.entry = element entry { simple.inlines }

# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ abstract ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

abstract = element abstract { abstract.content }

abstract.content =
   p+

# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ cover ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

cover = element cover { cover.content }

cover.content =
   cover.image

cover.image = element image { cover.image.attributes }

cover.image.attributes =
   media.id.attribute
media.id.attribute = attribute id { xsd:NMTOKEN }

# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ element ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

\element = element element { element.attributes, element.content }

element.attributes =
   name.attribute
name.attribute = attribute name { xsd:NCName }
   
element.content =
   (inlines | \element+)


# =============================================================================
#                                  TOP LEVEL
# =============================================================================

# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ composition ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

# ~~~~~~ composition
composition = element composition {
   composition.attributes,
   composition.content
}

composition.attributes =
   composition.id.attribute?
 & lang.attribute?
 & path.attribute?
 & pi-fid.attribute?
 & pi-source.attribute?
 & (xpath.attribute | xslt.attribute)?
 & remap.attributes
composition.id.attribute = attribute id { xsd:NMTOKEN }
lang.attribute = attribute xml:lang { xsd:language }
path.attribute = attribute path { xsd:anyURI }
pi-fid.attribute = attribute pi-fid { xsd:boolean }
pi-source.attribute = attribute pi-source { xsd:boolean }
xpath.attribute = attribute xpath { text }
xslt.attribute = attribute xslt { xsd:anyURI }

composition.content =
   composition.head?,
   (composition.division | composition.file)+

# ~~~~~~ composition.head
composition.head = element head {
   composition.head.attributes, composition.head.content }

composition.head.attributes =
   remap.attributes

composition.head.content =
   (title & shorttitle? & subtitle*)?
 & identifier*
 & copyright*
 & collection?
 & contributors?
 & date?
 & (source, source?)?
 & keywordset?
 & subjectset?
 & indexset?
 & abstract?
 & cover?
 & \element*

# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ selection ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

# ~~~~~~ selection
selection = element selection {
   selection.attributes,
   selection.content
}

selection.attributes =
   selection.id.attribute?
 & lang.attribute?
 & path.attribute?
selection.id.attribute = attribute id { xsd:NMTOKEN }

selection.content =
   selection.head?,
   (selection.division | selection.file | link)+

# ~~~~~~ selection.head
selection.head = element head { composition.head.content }


# =============================================================================
#                                DIVISION LEVEL
# =============================================================================

# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ division ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

# ~~~~~~ division
composition.division = element division {
   composition.division.attributes,
   composition.division.content
}
selection.division = element division {
   selection.division.attributes,
   selection.division.content
}

composition.division.attributes =
   path.attribute?
 & (xpath.attribute | xslt.attribute)?
 & remap.attributes
 & argument.attribute?
 & mode.attribute?
selection.division.attributes =
   path.attribute?
 & argument.attribute?
 & mode.attribute?

composition.division.content =
   composition.head?,
   (composition.division | composition.file)+
selection.division.content =
   selection.head?,
   (selection.division | selection.file | link)+


# =============================================================================
#                                  FILE LEVEL
# =============================================================================

# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ file ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

composition.file = element file { composition.file.attributes, file.content }
selection.file = element file { selection.file.attributes, file.content }

composition.file.attributes =
   path.attribute?
 & (xpath.attribute | xslt.attribute)?
 & argument.attribute?
 & mode.attribute?
 & title.attribute?
selection.file.attributes =
   path.attribute?
argument.attribute = attribute argument { text }
mode.attribute = attribute mode { text }
title.attribute = attribute title { text }

file.content = xsd:anyURI


# =============================================================================
#                                 BLOCK LEVEL
# =============================================================================

# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ p ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

p = element p { p.content }

p.content =
   inlines


# =============================================================================
#                                 INLINE LEVEL
# =============================================================================

# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ inlines ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

simple.inlines = mixed {
   sup*
 & sub*
}

inlines = mixed {
   sup*
 & sub*

 & highlight*
 & emphasis*
 & name*
}

# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ sub, sup ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

sup = element sup { simple.inlines }

sub = element sub { inlines }

# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ highlight ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

highlight = element highlight { highlight.content }

highlight.content = inlines

# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ emphasis ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

emphasis = element emphasis { emphasis.content }

emphasis.content = inlines

# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ name ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

name = element name { name.attributes, name.content }

name.attributes =
   name.of.attribute?
name.of.attribute = attribute of {
   "person" | "company" | "book" | "newspaper" | "party" | "movie"
 | "painting" }

name.content = mixed { sup* }

# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ date ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

date = element date { date.attributes, date.content }

date.attributes =
   date.value.attribute
date.value.attribute = attribute value { xsd:date | xsd:gYearMonth | xsd:gYear }

date.content = mixed { sup* }

# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ link ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

link = element link { link.attributes, link.content }

link.attributes =
   uri.attribute
uri.attribute = attribute uri { xsd:anyURI }

link.content = simple.inlines


# =============================================================================
#                               REMAP ATTRIBUTES
# =============================================================================

remap.attributes =
   as.attribute?
 & attributes.attribute?
 & transform.attribute?
as.attribute = attribute as { xsd:QName }
attributes.attribute =
   attribute attributes {list { (xsd:token {pattern = "\c+=\S+"})+ }}
transform.attribute = attribute transform { xsd:anyURI }