Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Understanding schematron validation

I am new to xml and I am having difficulties in understanding what is happening in the below statement. The Schematron file is from https://schemas.wmo.int/iwxxm/3.0.0/rule/iwxxm.sch

<sch:rule context="//*[contains(name(),'MeteorologicalAerodromeTrendForecast')]/iwxxm:weather">
<sch:assert test="@xlink:href = document('codes.wmo.int-49-2-AerodromePresentOrForecastWeather.rdf')/rdf:RDF/*/skos:member/*/@*[local-name()='about'] or @nilReason">
MeteorologicalAerodromeTrendForecast iwxxm:weather elements should be a member of http://codes.wmo.int/49-2/AerodromePresentOrForecastWeather
</sch:assert>
</sch:rule>

I understand that there is a rule to check the element iwxxm:weather, but i am unable to understand the test condition. Can anyone explain it to me please? For what value, the test will pass.

The test is failing at a line in the xml which is

<iwxxm:MeteorologicalAerodromeForecast gml:id="uuid.c42e9861-aed6-449f-b4cd-4789e96464d5" cloudAndVisibilityOK="false">
          <iwxxm:prevailingVisibility uom="m">350</iwxxm:prevailingVisibility>
          <iwxxm:surfaceWind>
            <iwxxm:AerodromeSurfaceWindForecast variableWindDirection="false">
              <iwxxm:meanWindDirection uom="deg">240</iwxxm:meanWindDirection>
              <iwxxm:meanWindSpeed uom="[kn_i]">8</iwxxm:meanWindSpeed>
            </iwxxm:AerodromeSurfaceWindForecast>
          </iwxxm:surfaceWind>
 Here ---->         <iwxxm:weather xlink:href="http://codes.wmo.int/49-2/AerodromePresentOrForecastWeather/_RA"/> 
          <iwxxm:cloud>

Thanks

like image 260
NJMR Avatar asked Feb 19 '20 08:02

NJMR


People also ask

What is schematron validation?

Schematron is a rule-based validation language for making assertions about the presence or absence of patterns in XML trees. It is a structural schema language expressed in XML using a small number of elements and XPath.


2 Answers

The Schematron assertion is verifying that one of the following two conditions are met:

  1. the xlink:href attribute value of the iwxxm:weather context element is equal to that of the about attribute from a particular RDF document:

    • The document() function is used to access an external XML document. In this case, it is the codes.wmo.int-49-2-AerodromePresentOrForecastWeather.rdf RDF document.
    • Then it applies an XPath to select the attribute that has a local-name of about (doesn't matter if it is bound to a namespace or not)
    • that is attached to an element (doesn't matter what the name of the element is)
    • that is the child of a skos:member element
    • that is the child of an element (doesn't matter what the name of the element is)
    • that is the child of the rdf:RDF document element.

For instance, if the RDF document looked like this:

  <rdf:RDF xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" 
           xmlns:skos="http://www.w3.org/2004/02/skos/core#">
  <foo>
    <skos:member>
      <bar skos:about="http://codes.wmo.int/49-2/AerodromePresentOrForecastWeather/_RA"/>
    </skos:member>
  </foo>
</rdf:RDF>
  1. or the iwxxm:weather context element has a nilReason attribute

For instance, if the element were to look like this:

<iwxxm:weather nilReason="true" /> 
like image 170
Mads Hansen Avatar answered Nov 05 '22 20:11

Mads Hansen


given the target node:

<iwxxm:weather xlink:href="http://codes.wmo.int/49-2/AerodromePresentOrForecastWeather/_RA"/>

and the assertion test:

@xlink:href = document('codes.wmo.int-49-2-AerodromePresentOrForecastWeather.rdf')/rdf:RDF/*/skos:member/*/@*[local-name()='about'] or @nilReason

it compares the value of iwxxm:weather/@xlink:href and document('codes.wmo.int-49-2-AerodromePresentOrForecastWeather.rdf')/rdf:RDF/*/skos:member/*/@*[local-name()='about'], since this is an assertion, it returns true if the compared values do not match OR iwxxm:weather does not have an attribute @nilReason.

It will pass if iwxxm:weather/@xlink:href and document('codes.wmo.int-49-2-AerodromePresentOrForecastWeather.rdf')/rdf:RDF/*/skos:member/*/@*[local-name()='about'] is an equal match or iwxxm:weather should have an attribute @nilReason.

like image 22
Joel M. Lamsen Avatar answered Nov 05 '22 19:11

Joel M. Lamsen