<?xml version="1.0" encoding="UTF-8"?>
<!--
  An audience description: who reads a page, and what they need from it.
  Published at /audiences/audience.xsd, beside the files it describes: one
  file per audience (/audiences/<id>.xml, the element `audience`) and an
  index of them (/audiences/index.xml, the element `audiences`).

  A page names its audiences in its head, in order, the first its main
  audience:

    <link rel="audience" href="/audiences/tech-lead.xml">
    <meta name="page-kind" content="pitch">

  A need is named "<audience id>.<need id>". Which needs a page answers is
  not published: a tool judges that from the page's text.

  README.md, "Audiences and page kinds", is the convention in full. Any
  site may publish files of this format; a tool reads them from the links
  of the page it is given, and knows no audience of its own.

  This file is the site's (website/schema/audience.xsd); the build copies
  it and writes the audience files from content/site.xml.
-->
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema"
           xmlns="https://www.tinyactors.dev/ns/audience"
           targetNamespace="https://www.tinyactors.dev/ns/audience"
           elementFormDefault="qualified"
           xpathDefaultNamespace="##targetNamespace"
           version="1.1">

  <xs:element name="audience">
    <xs:annotation><xs:documentation>
      One kind of reader. `id` names it on its site, and is the first part
      of each of its needs' references. `name` is who they are in a few
      words, `description` their situation, `knows` what they know
      already. Then their needs, one line each, in three kinds: `want`
      (what they look for), `task` (what they came to do) and `objection`
      (what makes them doubt, in their words). A need's `id` is unique
      within its audience; elsewhere it is "audience-id.need-id".
    </xs:documentation></xs:annotation>
    <xs:complexType>
      <xs:sequence>
        <xs:element name="name" type="text"/>
        <xs:element name="description" type="text"/>
        <xs:element name="knows" type="text"/>
        <xs:element name="want" type="need" maxOccurs="unbounded"/>
        <xs:element name="task" type="need" maxOccurs="unbounded"/>
        <xs:element name="objection" type="need" minOccurs="0" maxOccurs="unbounded"/>
      </xs:sequence>
      <xs:attribute name="id" type="id" use="required"/>
    </xs:complexType>
    <xs:unique name="need-ids">
      <xs:selector xpath="want|task|objection"/>
      <xs:field xpath="@id"/>
    </xs:unique>
  </xs:element>

  <xs:element name="audiences">
    <xs:annotation><xs:documentation>
      The index of a site's audiences: each `item` names one by its `id`,
      the file that describes it (`href`, relative to the index) and its
      name.
    </xs:documentation></xs:annotation>
    <xs:complexType>
      <xs:sequence>
        <xs:element name="item" maxOccurs="unbounded">
          <xs:complexType>
            <xs:simpleContent>
              <xs:extension base="text">
                <xs:attribute name="id" type="id" use="required"/>
                <xs:attribute name="href" type="xs:anyURI" use="required"/>
              </xs:extension>
            </xs:simpleContent>
          </xs:complexType>
        </xs:element>
      </xs:sequence>
    </xs:complexType>
    <xs:unique name="item-ids">
      <xs:selector xpath="item"/>
      <xs:field xpath="@id"/>
    </xs:unique>
  </xs:element>

  <xs:complexType name="need">
    <xs:annotation><xs:documentation>One need, one line: its text, and its id within the audience.</xs:documentation></xs:annotation>
    <xs:simpleContent>
      <xs:extension base="text">
        <xs:attribute name="id" type="id" use="required"/>
      </xs:extension>
    </xs:simpleContent>
  </xs:complexType>

  <xs:simpleType name="id">
    <xs:annotation><xs:documentation>Lowercase words joined by hyphens: "tech-lead", "host-dies".</xs:documentation></xs:annotation>
    <xs:restriction base="xs:token">
      <xs:pattern value="[a-z][a-z0-9]*(-[a-z0-9]+)*"/>
    </xs:restriction>
  </xs:simpleType>

  <xs:simpleType name="text">
    <xs:annotation><xs:documentation>Plain text, no markup.</xs:documentation></xs:annotation>
    <xs:restriction base="xs:token">
      <xs:minLength value="1"/>
    </xs:restriction>
  </xs:simpleType>
</xs:schema>
