RelaxNG/publimeta.rnc
changeset 260 a904cb6b2760
child 262 2906cd61506b
equal deleted inserted replaced
259:8b0f1432fd11 260:a904cb6b2760
       
     1 # $Id$
       
     2 
       
     3 start = publimeta
       
     4 
       
     5 
       
     6 publimeta = element publimeta {
       
     7    publimeta.attributes,
       
     8    publimeta.content
       
     9 }
       
    10 
       
    11 publimeta.attributes =
       
    12    version.attribute
       
    13 version.attribute = attribute version { "1.0" }
       
    14 
       
    15 publimeta.content =
       
    16    metadatas
       
    17 
       
    18 
       
    19 # =============================================================================
       
    20 #                                    TOP LEVEL
       
    21 # =============================================================================
       
    22 
       
    23 # ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ metadatas ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
       
    24 
       
    25 metadatas = element metadatas { metadatas.content }
       
    26 
       
    27 metadatas.content =
       
    28    metadata+
       
    29 
       
    30 # ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ metadata ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
       
    31 
       
    32 metadata = element metadata { metadata.attributes, metadata.content }
       
    33 
       
    34 metadata.attributes =
       
    35    metadata.for.attribute
       
    36  & lang.attribute?
       
    37 metadata.for.attribute = attribute for { xsd:NMTOKEN }
       
    38 lang.attribute = attribute xml:lang { xsd:language }
       
    39    
       
    40 metadata.content =
       
    41    (title, shorttitle?, subtitle*)?
       
    42  & identifier*
       
    43  & copyright*
       
    44  & collection?
       
    45  & contributors?
       
    46  & date?
       
    47  & keywordset?
       
    48  & subjectset?
       
    49  & abstract?
       
    50  & price?
       
    51 
       
    52 
       
    53 # =============================================================================
       
    54 #                                  METADATA LEVEL
       
    55 # =============================================================================
       
    56 
       
    57 # ~~~~~~~~~~~~~~~~~~~~~~~ title, shorttitle, subtitle ~~~~~~~~~~~~~~~~~~~~~~~~~
       
    58 
       
    59 title = element title { title.content }
       
    60 shorttitle = element shorttitle { title.content }
       
    61 subtitle = element subtitle { title.content }
       
    62 
       
    63 title.content = inlines
       
    64 
       
    65 # ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ identifier ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
       
    66 
       
    67 # ~~~~~~ identifier
       
    68 identifier = element identifier {
       
    69    (attribute type { "ean" }, for.attribute?, xsd:token {pattern = "\d{13}"})
       
    70  | (attribute type { "uri" }, for.attribute?, xsd:anyURI)
       
    71 }
       
    72 
       
    73 for.attribute = attribute for { xsd:NCName }
       
    74 
       
    75 # ~~~~~~ identifier.ean
       
    76 identifier.ean = element identifier {
       
    77    attribute type { "ean" }, for.attribute?, xsd:token {pattern = "\d{13}"}
       
    78 }
       
    79 
       
    80 # ~~~~~~ identifier.uri
       
    81 identifier.uri = element identifier {
       
    82    attribute type { "uri" }, for.attribute?, xsd:anyURI
       
    83 }
       
    84 
       
    85 # ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ copyright ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
       
    86 
       
    87 copyright = element copyright { copyright.content }
       
    88 
       
    89 copyright.content = inlines
       
    90 
       
    91 # ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ collection ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
       
    92 
       
    93 collection = element collection { collection.content }
       
    94 
       
    95 collection.content = inlines
       
    96 
       
    97 # ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ contributors ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
       
    98 
       
    99 # ~~~~~~ contributors
       
   100 contributors = element contributors { contributors.content }
       
   101 
       
   102 contributors.content =
       
   103    contributor+
       
   104 
       
   105 # ~~~~~~ contributor
       
   106 contributor = element contributor { contributor.content }
       
   107 
       
   108 contributor.content =
       
   109    (((firstname, secondname?)?, lastname) | label),
       
   110    address?,
       
   111    link?,
       
   112    role+
       
   113 
       
   114 # ~~~~~~ firstname, secondname, lastname, label
       
   115 firstname = element firstname { firstname.content }
       
   116 secondname = element secondname { secondname.content }
       
   117 lastname = element lastname { lastname.content }
       
   118 label = element label { label.content }
       
   119 
       
   120 firstname.content = inlines
       
   121 secondname.content = inlines
       
   122 lastname.content = inlines
       
   123 label.content = inlines
       
   124 
       
   125 # ~~~~~~ address
       
   126 address = element address { address.content }
       
   127 
       
   128 address.content = inlines
       
   129 
       
   130 # ~~~~~~ role
       
   131 role = element role { role.content }
       
   132 
       
   133 role.content = "author" | "illustrator" | "publisher" | "packager"
       
   134 
       
   135 # ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ keyword & subject ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
       
   136 
       
   137 # ~~~~~~ keywordset
       
   138 keywordset = element keywordset { keywordset.content }
       
   139 
       
   140 keywordset.content = keyword+
       
   141 
       
   142 # ~~~~~~ keyword
       
   143 keyword = element keyword { keyword.content }
       
   144 
       
   145 keyword.content = mixed { sup*, sub* }
       
   146 
       
   147 # ~~~~~~ subjectset
       
   148 subjectset = element subjectset { subjectset.content }
       
   149 
       
   150 subjectset.content = subject+
       
   151 
       
   152 # ~~~~~~ subject
       
   153 subject = element subject { subject.content }
       
   154 
       
   155 subject.content = mixed { sup*, sub* }
       
   156 
       
   157 # ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ abstract ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
       
   158 
       
   159 abstract = element abstract { abstract.content }
       
   160 
       
   161 abstract.content =
       
   162    p+
       
   163 
       
   164 # ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ price ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
       
   165 
       
   166 price = element price { price.attributes, price.content }
       
   167 
       
   168 price.attributes =
       
   169    currency.attribute
       
   170 currency.attribute = attribute currency { "EUR" | "USD" }
       
   171 
       
   172 price.content = xsd:float
       
   173    
       
   174 
       
   175 # =============================================================================
       
   176 #                                 BLOCK LEVEL
       
   177 # =============================================================================
       
   178 
       
   179 # ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ p ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
       
   180 
       
   181 p = element p { p.content }
       
   182 
       
   183 p.content =
       
   184    inlines
       
   185 
       
   186 
       
   187 # =============================================================================
       
   188 #                                 INLINE LEVEL
       
   189 # =============================================================================
       
   190 
       
   191 # ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ inlines ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
       
   192 
       
   193 inlines = mixed {
       
   194    sup*
       
   195  & sub*
       
   196  & date*
       
   197  & name*
       
   198  & highlight*
       
   199  & link*
       
   200 }
       
   201 
       
   202 # ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ sub, sup ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
       
   203 
       
   204 sup = element sup { inlines }
       
   205 
       
   206 sub = element sub { inlines }
       
   207 
       
   208 # ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ date ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
       
   209 
       
   210 date = element date { date.attributes, date.content }
       
   211 
       
   212 date.attributes =
       
   213    date.value.attribute
       
   214 date.value.attribute = attribute value { xsd:date | xsd:gYearMonth | xsd:gYear }
       
   215 
       
   216 date.content = mixed { sup* }
       
   217 
       
   218 # ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ name ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
       
   219 
       
   220 name = element name { name.attributes, name.content }
       
   221 
       
   222 name.attributes =
       
   223    name.of.attribute?
       
   224 name.of.attribute = attribute of {
       
   225    "person" | "company" | "book" | "newspaper" | "party" | "painting"
       
   226  | "movie" }
       
   227 
       
   228 name.content = mixed { sup* }
       
   229 
       
   230 # ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ highlight ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
       
   231 
       
   232 highlight = element highlight { highlight.content }
       
   233 
       
   234 highlight.content = inlines
       
   235 
       
   236 # ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ link ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
       
   237 
       
   238 link = element link { link.attributes, link.content }
       
   239 
       
   240 link.attributes =
       
   241    uri.attribute
       
   242 uri.attribute = attribute uri { xsd:anyURI }
       
   243 
       
   244 link.content = mixed { sup* & sub* & date* & name* & highlight* }
       
   245 
       
   246 
       
   247 # =============================================================================
       
   248 #                               REMAP ATTRIBUTES
       
   249 # =============================================================================
       
   250 
       
   251 remap.attributes =
       
   252    as.attribute?
       
   253  & attributes.attribute?
       
   254  & transform.attribute?
       
   255 as.attribute = attribute as { xsd:QName }
       
   256 attributes.attribute =
       
   257    attribute attributes {list { (xsd:token {pattern = "\c+=\S+"})+ }}
       
   258 transform.attribute = attribute transform { xsd:anyURI }