PREFIX st:   <http://ns.inria.fr/sparql-template/>
PREFIX fun: <http://w3id.org/sparql-generate/fn/>
PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#>
PREFIX dcterms: <http://purl.org/dc/terms/>
PREFIX xsd: <http://www.w3.org/2001/XMLSchema#> 

BASE <https://saref.etsi.org/documentation/>

TEMPLATE <ontology/description.rqg>( ?onto ) {

  COALESCE( ?html, fun:markdownToHTML(?md), 
    IF( st:call-template( <function/formatText.rqg>,  ?description_en ) != "" , st:call-template( <function/formatText.rqg>,  ?description_en ) , ?undef ), 
    IF( st:call-template( <function/formatText.rqg>,  ?description ) != "" , st:call-template( <function/formatText.rqg>,  ?description ) , ?undef ), 
    "Violation of TS 103 673 Clause 9.4.3.2" )
}
SOURCE <description.html> AS ?html
SOURCE <description.md> AS ?md
WHERE {
  OPTIONAL { 
    ?onto dcterms:description ?description_en .
    FILTER (LANG(?description_en)="en")
  }
  OPTIONAL { 
    ?onto dcterms:description ?description .
    FILTER ( DATATYPE(?description) = xsd:string )
  }
}
LIMIT 1 

