+(defun validate-literal-value (value datatype)
+ "Validate the shared Variant/Occurrence literal representation without mutation."
+ (unless (and (stringp value) (stringp datatype)) (fail :invalid-literal "Value and datatype must be strings."))
+ (unless (topic-maps.tmdm::absolute-locator-p datatype)
+ (fail :invalid-occurrence-datatype "Datatype must be an absolute locator."))
+ (when (and (string= datatype (integer-datatype))
+ (not (integer-lexical-p value)))
+ (fail :invalid-integer-value "Literal value is not an xsd:integer lexical form."))
+ (when (and (string= datatype (decimal-datatype))
+ (not (decimal-lexical-p value)))
+ (fail :invalid-decimal-value "Literal value is not an xsd:decimal lexical form."))
+ (when (string= datatype (date-datatype))
+ (unless (date-lexical-p value)
+ (fail :invalid-date-value "Literal value is not a valid XSD 1.0 date."))
+ (unless (canonical-date-lexical-form value)
+ (fail :date-timezone-canonicalization "XSD date recoverable-timezone canonicalization is outside this slice." t)))
+ (when (string= datatype (datetime-datatype))
+ (unless (datetime-lexical-p value)
+ (fail :invalid-datetime-value "Literal value is not a valid XSD 1.0 dateTime."))
+ (multiple-value-bind (value reason) (canonical-datetime-lexical-form value)
+ (unless value (fail (if (eq reason :unsupported-bce-timezone-rollover)
+ :datetime-bce-timezone-rollover :datetime-leap-second-context)
+ "DateTime BCE rollover/leap-second context is outside this canonical subset." t))))
+ (when (and (string= datatype (iri-datatype))
+ (not (topic-maps.tmdm::absolute-locator-p value)))
+ (fail :invalid-occurrence-value "IRI-valued literals must store an absolute locator."))
+ t)