Strange Behavior when Comapring xs:decimal type in Schematron

<oXygen/> general issues.
corymosiman12
Posts: 6
Joined: Tue Jan 28, 2020 2:05 am

Strange Behavior when Comapring xs:decimal type in Schematron

Post by corymosiman12 » Fri Jan 31, 2020 10:58 pm

I have the following in an XML Schema:

Code: Select all

                  
                  <auc:FloorAreas>
                    <auc:FloorArea>
                      <auc:FloorAreaType>Gross</auc:FloorAreaType>
                      <auc:FloorAreaValue>24695</auc:FloorAreaValue>
                    </auc:FloorArea>
                    <auc:FloorArea>
                      <auc:FloorAreaType>Conditioned</auc:FloorAreaType>
                      <auc:FloorAreaValue>124411</auc:FloorAreaValue>
                    </auc:FloorArea>
                    <auc:FloorArea>
                      <auc:FloorAreaType>Cooled only</auc:FloorAreaType>
                      <auc:FloorAreaValue>234</auc:FloorAreaValue>
                    </auc:FloorArea>
                  </auc:FloorAreas>
                  
I have written a Schematron function:

Code: Select all

  <!--  
    Check that the GrosConditioned area is greater than Cooled only + Heated only + Heated and Cooled + Ventilated
    <severity> error
    <param> parent - an auc:FloorArea[auc:FloorAreaType='Conditioned' and auc:FloorAreaValue] element
-->  
  <pattern abstract="true" id="fa.conditionedValueChecks">
    <rule context="$faNode">
      <let name="grossArea" value="if (parent::node()/auc:FloorArea/auc:FloorAreaType[text()='Gross']) then (parent::node()/auc:FloorArea/auc:FloorAreaType[text()='Gross']/parent::auc:FloorArea/auc:FloorAreaValue) else (0.0)"/>
      <let name="cooledOnlyArea" value="if (parent::node()/auc:FloorArea/auc:FloorAreaType[text()='Cooled only']) then (parent::node()/auc:FloorArea/auc:FloorAreaType[text()='Cooled only']/parent::auc:FloorArea/auc:FloorAreaValue) else (0.0)"/>
      <let name="heatedOnlyArea" value="if (parent::node()/auc:FloorArea/auc:FloorAreaType[text()='Heated only']) then (parent::node()/auc:FloorArea/auc:FloorAreaType[text()='Heated only']/parent::auc:FloorArea/auc:FloorAreaValue) else (0.0)"/>
      <let name="heatedCooledArea" value="if (parent::node()/auc:FloorArea/auc:FloorAreaType[text()='Heated and Cooled']) then (parent::node()/auc:FloorArea/auc:FloorAreaType[text()='Heated and Cooled']/parent::auc:FloorArea/auc:FloorAreaValue) else (0.0)"/>
      <let name="ventilatedArea" value="if (parent::node()/auc:FloorArea/auc:FloorAreaType[text()='Ventilated']) then (auc:FloorArea/auc:FloorAreaType[text()='Ventilated']/parent::auc:FloorArea/auc:FloorAreaValue) else (0.0)"/>
      <let name="conditionedAreaValue" value="auc:FloorAreaValue/text()"/>
      <assert test="false()">
        JUST PRINT VALUES: Gross Area (<value-of select="$grossArea"/>) must be greater than or equal to Conditioned Area Value (<value-of select="$conditionedAreaValue"/>)
      </assert>
      <assert test="$grossArea >= $conditionedAreaValue">
        Gross Area (<value-of select="$grossArea"/>) must be greater than or equal to Conditioned Area Value (<value-of select="$conditionedAreaValue"/>)
      </assert>
      <assert test="$conditionedAreaValue >= $cooledOnlyArea + $heatedOnlyArea + $heatedCooledArea + $ventilatedArea">
        Conditioned Area Value (<value-of select="$conditionedAreaValue"/>) must be greater than or equal to: Heated and Cooled (<value-of select="$heatedCooledArea"/>) + Heated only (<value-of select="$heatedOnlyArea"/>) + Cooled only (<value-of select="$cooledOnlyArea"/>) + Ventilated (<value-of select="$ventilatedArea"/>)
      </assert>
    </rule>
  </pattern>
The first assertion is simply so that the values get printed out as a sanity check. What prints out is as follows (the Conditioned value seems to be getting read in correctly):
Screen Shot 2020-01-31 at 12.46.59 PM.png
Screen Shot 2020-01-31 at 12.46.59 PM.png (7.31 KiB) Viewed 228 times
As you see, the value comparison check doesn't fire.

However, if I change the second assertion to check if it is LESS THAN, i.e.

Code: Select all

      <assert test="$grossArea &lt;= $conditionedAreaValue">
        Gross Area (<value-of select="$grossArea"/>) must be greater than or equal to Conditioned Area Value (<value-of select="$conditionedAreaValue"/>)
      </assert>
the rule fires:
Screen Shot 2020-01-31 at 12.50.38 PM.png
Screen Shot 2020-01-31 at 12.50.38 PM.png (14.17 KiB) Viewed 228 times
The other thing is that, it WILL FIRE correctly with certain values. For example:

Code: Select all

                  <auc:FloorAreas>
                    <auc:FloorArea>
                      <auc:FloorAreaType>Gross</auc:FloorAreaType>
                      <auc:FloorAreaValue>24695</auc:FloorAreaValue>
                    </auc:FloorArea>
                    <auc:FloorArea>
                      <auc:FloorAreaType>Conditioned</auc:FloorAreaType>
                      <auc:FloorAreaValue>24696</auc:FloorAreaValue>
                    </auc:FloorArea>
                    <auc:FloorArea>
                      <auc:FloorAreaType>Cooled only</auc:FloorAreaType>
                      <auc:FloorAreaValue>234</auc:FloorAreaValue>
                    </auc:FloorArea>
                  </auc:FloorAreas>
and I change the rule back to the original (i.e. it is checking to make sure that the Gross Area >= Conditioned Area), it fires correctly:
Screen Shot 2020-01-31 at 12.55.07 PM.png
Screen Shot 2020-01-31 at 12.55.07 PM.png (13.39 KiB) Viewed 228 times
Why would this be happening? It seems so outrageously inconsistent.

For reference:
The datatype of the auc:FloorAreaValue is an extension of 'xs:decimal'
I am running XML Editor 21.1, build 2019071807 on macOS 10.14.6

tavy
Posts: 224
Joined: Thu Jul 01, 2004 12:29 pm

Re: Strange Behavior when Comapring xs:decimal type in Schematron

Post by tavy » Mon Feb 03, 2020 5:00 pm

Hello,

I think that the problem is that you compare the string values of the numbers. You need to convert the text value into a number using the number() function. The condition must be something like this "number($grossArea) >= $conditionedAreaValue".

Best Regards.
Octavian
Octavian Nadolu
<oXygen/> XML Editor
http://www.oxygenxml.com

corymosiman12
Posts: 6
Joined: Tue Jan 28, 2020 2:05 am

Re: Strange Behavior when Comapring xs:decimal type in Schematron

Post by corymosiman12 » Thu Feb 06, 2020 6:12 pm

Yes that was simple...thank you!

Post Reply