Home > Software design >  XSD to assert 2 values given the attribtues name
XSD to assert 2 values given the attribtues name

Time:07-07

I am trying to write an assertion in my XML Schema that checks that the value of param with the attribute name = "Max_measurement_value" should always be superior to the value of param with the attribute name = "Min_measurement_value"

XML

<SET>
  <PAGE>
    <OBJETS>
      <OBJET name="x">
        <PARAMS>
          <param name="Max_measurement_value" type="Real" libelle="Maximum measurement value">17.0000</param>
          <param name="Min_measurement_value" type="Real" libelle="Minimum measurement value">0.000000</param>
        </PARAMS>
      </OBJET>
      <OBJET name="y">
        <PARAMS>
          <param name="Max_measurement_value" type="Real" libelle="Maximum measurement value">25.0000</param>
          <param name="Min_measurement_value" type="Real" libelle="Minimum measurement value">2.000000</param>
        </PARAMS>
      </OBJET>
    <OBJETS>
  <PAGE>
<SET>

in my XSD, I am using CTA because I have other param that are not FloatType

<xs:alternative test="@name='Max_measurement_value'" type="FloatType" />
<xs:alternative test="@name='Min_measurement_value'" type="FloatType" />

And I have created a complextype to define the param attribtues

<xs:complexType name="FloatType">
  <xs:simpleContent>
    <xs:extension base="xs:float">
      <xs:attribute name="name" type="xs:string"/>
      <xs:attribute name="type" type="xs:string"/>
      <xs:attribute name="libelle" type="xs:string"/>
    </xs:extension>
  </xs:simpleContent>
</xs:complexType>

I am note sure how to do this assert on this one since I am kind of a beginner to xml/xsd. Thank you for you help !

CodePudding user response:

I would have expected to see, on the declaration of the PARAMS element, something like

<xs:assert test='
  if (exists(param[@name="Min_measurement_value"])
       and exists(param[@name="Max_measurement_value"])) 
  then param[@name="Max_measurement_value"] ge    
       param[@name="Min_measurement_value"]
  else true()'/>
  • Related