Conditional types

Sometimes one XML element name should map to different editor node types depending on its attributes — for example a <ref> that is a cross-reference in one case and an external link in another. JinnTap supports this by letting a schema entry be an array of definitions instead of a single object.

Array form with when

Each item may carry a when object — a map of attribute → value that must all match for that definition to apply:

"ref": [
  {
    "type": "ref",                 // used when target starts as an internal reference
    "when": { "type": "internal" }
  },
  {
    "type": "inline"               // the fallback for every other <ref>
  }
]

How dispatch works

This lets a single tag round-trip faithfully while behaving as different editor constructs based on its attributes.

Attribute-level when

A related capability lets a single attribute carry an array of conditional definitions, so the attribute panel shows a different editor (e.g. a different authority connector) depending on another attribute's value. Here when is an XPath test string rather than an attribute → value map. The JATS schema uses this for named-content, where @content-type selects which connector specific-use gets:

"named-content": {
  "type": "inline",
  "attributes": {
    "specific-use": [
      {
        "when": "@content-type = 'person'",
        "type": "string",
        "connector": { "name": "GND", "type": "person", "prefix": "gnd" }
      },
      {
        "when": "@content-type = 'place'",
        "type": "string",
        "connector": { "name": "GeoNames", "type": "place", "prefix": "geo" }
      }
    ]
  }
}

Definitions are tried in order and the first whose when matches wins (see src/attribute-panel.js). Only tests of the form @name = 'value' are currently supported.

Notes