namespace a = "http://relaxng.org/ns/compatibility/annotations/1.0"
namespace cs = "http://purl.org/net/xbiblio/csl"
namespace dc = "http://purl.org/dc/elements/1.1/"

dc:title [ "Extension schema for the Citation Style Language styles repository" ]
dc:creator [ "Rintze M. Zelle" ]
dc:rights [
  "Copyright 2013 Rintze M. Zelle. Permission to freely use, copy and distribute."
]
dc:description [
  "Enforces stricter requirements for the styles in the official CSL styles repository."
]

include "csl.rnc" {

  ## Remove legacy attributes from cs:style of dependents
  dependent-style.style =
    element cs:style {
      style.default-locale,
      version,
      dependent-style.style.info
    }

  ## - Only allow cs:issn once
  ## - Require a cs:rights element
  ## - Forgo "interleave" (so the elements need to be in the order specified),
  ##   so that we can require
  ##   * one cs:link with "self"
  ##   * any number of cs:link with "template"
  ##   * at least one cs:link with "documentation"
  ##   * one cs:category with "citation-format"
  ##   * any number of cs:category with "field".
  ## Metadata for independent styles.
  independent-style.style.info =
    element cs:info {
      info.title,
      info.title-short?,
      info.id,
      independent-style.info.link.self,
      independent-style.info.link.template*,
      independent-style.info.link.documentation+,
      info.author*,
      info.contributor*,
      info.category.citation-format,
      info.category.field*,
      info.issn?,
      info.eissn?,
      info.issnl?,
      info.summary?,
      info.published?,
      info.updated,
      info.rights
    }
    
  ## - Only allow cs:issn once
  ## - Require a cs:rights element
  ## - Forgo "interleave" (so the elements need to be in the order specified),
  ##   so that we can require
  ##   * one cs:link with "self"
  ##   * one cs:link with "independent-parent"
  ##   * any number of cs:link with "documentation"
  ##   * one cs:category with "citation-format"
  ##   * any number of cs:category with "field".
  ## Metadata for dependent styles.
  dependent-style.style.info =
    element cs:info {
      info.title,
      info.title-short?,
      info.id,
      independent-style.info.link.self,
      independent-style.info.link.independent-parent,
      independent-style.info.link.documentation*,
      info.author*,
      info.contributor*,
      info.category.citation-format,
      info.category.field*,
      info.issn?,
      info.eissn?,
      info.issnl?,
      info.summary?,
      info.published?,
      info.updated,
      info.rights
    }

  ## Require "license" attribute; require specific value for "license" attribute and
  ## text content for cs:rights
  info.rights =
    element cs:rights {
      attribute license { "http://creativecommons.org/licenses/by-sa/3.0/" },
      attribute xml:lang { xsd:language }?,
      "This work is licensed under a Creative Commons Attribution-ShareAlike 3.0 License"
    }

  ## Remove legacy attributes from cs:et-al
  names.et-al =
    
    ## Specify the term used for et-al abbreviation and its formatting. 
    element cs:et-al {
      
      ## Select the term to use for et-al abbreviation.
      [ a:defaultValue = "et-al" ]
      attribute term { "et-al" | "and others" }?,
      font-formatting
    }
}

independent-style.info.link.self =
element cs:link {
  attribute href { xsd:anyURI },
  attribute rel { "self" },
  info-text
}

independent-style.info.link.template =
element cs:link {
  attribute href { xsd:anyURI },
  attribute rel { "template" },
  info-text
}

independent-style.info.link.independent-parent =
element cs:link {
  attribute href { xsd:anyURI },
  attribute rel { "independent-parent" },
  info-text
}

independent-style.info.link.documentation =
element cs:link {
  attribute href { xsd:anyURI },
  attribute rel { "documentation" },
  info-text
}

info.category.citation-format =
element cs:category {
  attribute citation-format { category.citation-format }
}

info.category.field =
element cs:category {
  attribute field { category.field }
}