Problem with ISO Schematron/XPath 2.0

This should cover W3C XML Schema, Relax NG and DTD related problems.
madde001
Posts: 80
Location: Durham, NC, USA

Problem with ISO Schematron/XPath 2.0

Thu Dec 18, 2008 9:58 pm

hi guys,

It's been awhile since I've used Schematron and I'm pretty shaky on Xpath 2.0.

I'm having a problem getting the attached ISO Schematron to compile relative to the attached xml instance doc. It doesn't like my use of namespace prefixes, and my XPath expression is evidently bad.

I'm sure I'm doing something(s) stupid. Can you tell me what it is?

John

===========
Schematron:

<?xml version="1.0" encoding="UTF-8"?>
<schema xmlns="http://purl.oclc.org/dsdl/schematron"
xmlns:iso="http://purl.oclc.org/dsdl/schematron">
<iso:pattern id="calculate-N-stage" xmlns:colon="http://www.cap.org/pert/2009/01/colon/"
xmlns:pert="http://www.cap.org/pert/2009/01/">
<iso:rule context="pert:N/@value">
<iso:let name="posNodes" value="sum(//pert:nodeGroup/@positiveNodes)"/>
<iso:let name="N" value="//pert:N/@value"/>
<iso:assert test="if (posNodes = 0) then N = 0 else if (posNodes &lt; 4)
then N = 1 else N = 2">Value of N-stage does not match the number of positive
nodes.</iso:assert>
</iso:rule>
</iso:pattern>
</schema>


===================
Instance:

<?xml version="1.0" encoding="UTF-8"?>
<?oxygen SCHSchema="N.sch"?>
<synopsis pert:schemaLocation="http://www.cap.org/pert/2009/01/resection@colon.rng"
pert:version="2009-01-01" xmlns="http://www.cap.org/pert/2009/01/"
xmlns:colon="http://www.cap.org/pert/2009/01/colon/"
xmlns:pert="http://www.cap.org/pert/2009/01/">
<comment xml:lang="en">This synopsis demonstrates the resection@colon.rng schema</comment>
<displayText>SYNOPTIC REPORT</displayText>
<clinical>
<comment>Might want to provide wrapper for free text</comment>
<displayText>Clinical History</displayText>
<priorTherapies>
<priorTherapy date="2008-05" description="Chemoirradiation"/>
</priorTherapies>
</clinical>
<specimen>
<displayText>Specimen</displayText>
<procedures>
<procedure value="abdominoperineal resection">
<comment>In this example this procedure was an A-P resection</comment>
</procedure>
</procedures>
<sites>
<displayText>What is the site?</displayText>
<site value="rectum"/>
<site value="sigmoidColon"/>
</sites>
<tumorLocations>
<tumorLocation value="rectum"/>
</tumorLocations>
<colon:polyp>
<colon:hasConfiguration value="pedunculated"/>
<colon:hasSize unit="cm" value="1.3"/>
</colon:polyp>
<colon:specimenIntegrity value="fragmented"/>
<colon:specimenLength unit="cm" value="23"/>
</specimen>
<tumor>
<histologicTypes>
<histologicType value="adenocarcinoma"/>
</histologicTypes>
<grade gradingSystem="WHO" value="high"/>
<colon:immuneResponse>
<colon:intratumoralResponse value="marked"/>
<colon:peritumoralResponse value="marked"/>
</colon:immuneResponse>
<colon:suggestMicrosatelliteInstability>
<colon:highGrade value="false"/>
<colon:medullaryComponent value="true"/>
<colon:mucinousComponent percentage="50" value="true"/>
</colon:suggestMicrosatelliteInstability>
<colon:tumorPerforation value="false"/>
</tumor>
<extent>
<colon:invasion>
<colon:deepestInvasion value="muscularisPropria"/>
<colon:adjacentStructure value="pelvic sidewall"/>
</colon:invasion>
<tumorSize dimension-1="2.1" dimension-2="1.7" dimension-3="1.2" unit="cm"/>
</extent>
<accessory>
<colon:preexistingPolyp value="serratedAdenoma"/>
<colon:discontinuousExtramuralExtension value="false"/>
<lymphovascularInvasion value="inconclusive"/>
<perineuralInvasion value="inconclusive"/>
<venousInvasion value="false"/>
<treatmentEffect value="slightResponse"/>
</accessory>
<margins>
<margin location="proximal" status="negative"/>
<margin location="distal" status="negative"/>
<margin location="circumferential" status="negative"/>
</margins>
<nodes>
<nodeGroup laterality="right" location="anorectal" positiveNodes="1" totalNodes="5"/>
<nodeGroup laterality="right" location="anterior cecal" positiveNodes="2" totalNodes="6"/>
</nodes>
<stage>
<classification value="p"/>
<T value="2"/>
<N value="0"/>
<M value="X"/>
<prefix value="a r y"/>
</stage>
</synopsis>
madde001
Posts: 80
Location: Durham, NC, USA

Re: Problem with ISO Schematron/XPath 2.0

Thu Dec 18, 2008 11:59 pm

Hi,

I discovered four of the problems:

(1) I guess I need to specify queryBinding="xslt2" on the <schema> element.

(2) The namespace issue is because I need to put <iso:ns> elements under the <schema> element; it's not enough to specify them using xmlns:xyz="http://www.foo.com".

(3) My context path was no good; should not be an attribute.

(4) I need to use "$" in front of references to variables defined in my <iso:let> statements.

This raises another point: is it possible to embed ISO Schematron/XPath 2.0 schema fragments into Relax NG schemas? Both #1 and #2 seem to be impossible for embedded Schematron, since the <schema> element isn't used.

John
george
Site Admin
Posts: 2100

Re: Problem with ISO Schematron/XPath 2.0

Fri Dec 19, 2008 5:25 am

Hi John,

In addition you can use also diagnostics to let the user know how to fix the problem, see for instance

Code: Select all

<?xml version="1.0" encoding="UTF-8"?>
<iso:schema
    xmlns:iso="http://purl.oclc.org/dsdl/schematron" queryBinding="xslt2">
    <iso:ns uri="http://www.cap.org/pert/2009/01/" prefix="pert"/>
   
    <iso:pattern id="calculate-N-stage" xmlns:colon="http://www.cap.org/pert/2009/01/colon/"
        xmlns:pert="http://www.cap.org/pert/2009/01/">
        <iso:rule context="pert:N[@value]">
            <iso:let name="posNodes" value="sum(//pert:nodeGroup/@positiveNodes)"/>
            <iso:let name="N" value="@value"/>
            <iso:assert test="if ($posNodes = 0) then $N = 0 else if ($posNodes &lt; 4)
                then $N = 1 else $N = 2">Value of N-stage does not match the number of positive
                nodes.</iso:assert>
            <iso:report test="$posNodes=0 and not($N=0)">The value for N-stage should be 0.</iso:report>
            <iso:report test="$posNodes &lt; 4 and not($N=1)">The value for N-stage should be 1.</iso:report>
            <iso:report test="$posNodes > 4 and not($N=2)">The value for N-stage should be 2.</iso:report>
        </iso:rule>
    </iso:pattern>
</iso:schema>


giving on the sample input:

Code: Select all

SystemID: C:\george\test\test.xml
Location: 81:0
Description: [ISO Schematron (XSLT 2.0)] Value of N-stage does not match the number of positive nodes. (if ($posNodes = 0) then $N = 0 else if ($posNodes &lt; 4) then $N = 1 else $N = 2)

SystemID: C:\george\test\test.xml
Location: 81:0
Description: [ISO Schematron (XSLT 2.0)] Warning: [report] The value for N-stage should be 1. ($posNodes &lt; 4 and not($N=1))


I think we use xslt2 as query binding when we extract the embedded ISO Schematron rules. Quickly trying the schema below seems to work fine with oXygen 10:

Code: Select all

<?xml version="1.0" encoding="UTF-8"?>
<grammar ns="http://www.w3.org/XML/1998/namespace"
  xmlns:colon="http://www.cap.org/pert/2009/01/colon/" xmlns:pert="http://www.cap.org/pert/2009/01/"
  xmlns="http://relaxng.org/ns/structure/1.0"
  datatypeLibrary="http://www.w3.org/2001/XMLSchema-datatypes"
  xmlns:iso="http://purl.oclc.org/dsdl/schematron">
  <start>
    <iso:ns uri="http://www.cap.org/pert/2009/01/" prefix="pert"/>
   
    <iso:pattern id="calculate-N-stage" xmlns:colon="http://www.cap.org/pert/2009/01/colon/"
      xmlns:pert="http://www.cap.org/pert/2009/01/">
      <iso:rule context="pert:N[@value]">
        <iso:let name="posNodes" value="sum(//pert:nodeGroup/@positiveNodes)"/>
        <iso:let name="N" value="@value"/>
        <iso:assert test="if ($posNodes = 0) then $N = 0 else if ($posNodes &lt; 4)
          then $N = 1 else $N = 2">Value of N-stage does not match the number of positive
          nodes.</iso:assert>
        <iso:report test="$posNodes=0 and not($N=0)">The value for N-stage should be 0.</iso:report>
        <iso:report test="$posNodes &lt; 4 and not($N=1)">The value for N-stage should be 1.</iso:report>
        <iso:report test="$posNodes > 4 and not($N=2)">The value for N-stage should be 2.</iso:report>
      </iso:rule>
    </iso:pattern>
    <element name="pert:synopsis">
      <attribute name="pert:schemaLocation">
        <data type="anyURI"/>
      </attribute>
      <attribute name="pert:version">
        <data type="NMTOKEN"/>
      </attribute>
      <ref name="comment"/>
      <ref name="displayText"/>
      <element name="pert:clinical">
        <ref name="comment"/>
        <ref name="displayText"/>
        <element name="pert:priorTherapies">
          <element name="pert:priorTherapy">
            <attribute name="date">
              <data type="NMTOKEN"/>
            </attribute>
            <attribute name="description">
              <data type="NCName"/>
            </attribute>
          </element>
        </element>
      </element>
      <element name="pert:specimen">
        <ref name="displayText"/>
        <element name="pert:procedures">
          <element name="pert:procedure">
            <attribute name="value"/>
            <ref name="comment"/>
          </element>
        </element>
        <element name="pert:sites">
          <ref name="displayText"/>
          <oneOrMore>
            <element name="pert:site">
              <attribute name="value">
                <data type="NCName"/>
              </attribute>
            </element>
          </oneOrMore>
        </element>
        <element name="pert:tumorLocations">
          <element name="pert:tumorLocation">
            <attribute name="value">
              <data type="NCName"/>
            </attribute>
          </element>
        </element>
        <element name="colon:polyp">
          <element name="colon:hasConfiguration">
            <attribute name="value">
              <data type="NCName"/>
            </attribute>
          </element>
          <element name="colon:hasSize">
            <attribute name="unit">
              <data type="NCName"/>
            </attribute>
            <attribute name="value">
              <data type="decimal"/>
            </attribute>
          </element>
        </element>
        <element name="colon:specimenIntegrity">
          <attribute name="value">
            <data type="NCName"/>
          </attribute>
        </element>
        <element name="colon:specimenLength">
          <attribute name="unit">
            <data type="NCName"/>
          </attribute>
          <attribute name="value">
            <data type="integer"/>
          </attribute>
        </element>
      </element>
      <element name="pert:tumor">
        <element name="pert:histologicTypes">
          <element name="pert:histologicType">
            <attribute name="value">
              <data type="NCName"/>
            </attribute>
          </element>
        </element>
        <element name="pert:grade">
          <attribute name="gradingSystem">
            <data type="NCName"/>
          </attribute>
          <attribute name="value">
            <data type="NCName"/>
          </attribute>
        </element>
        <element name="colon:immuneResponse">
          <element name="colon:intratumoralResponse">
            <attribute name="value">
              <data type="NCName"/>
            </attribute>
          </element>
          <element name="colon:peritumoralResponse">
            <attribute name="value">
              <data type="NCName"/>
            </attribute>
          </element>
        </element>
        <element name="colon:suggestMicrosatelliteInstability">
          <element name="colon:highGrade">
            <attribute name="value">
              <data type="boolean"/>
            </attribute>
          </element>
          <element name="colon:medullaryComponent">
            <attribute name="value">
              <data type="boolean"/>
            </attribute>
          </element>
          <element name="colon:mucinousComponent">
            <attribute name="percentage">
              <data type="integer"/>
            </attribute>
            <attribute name="value">
              <data type="boolean"/>
            </attribute>
          </element>
        </element>
        <element name="colon:tumorPerforation">
          <attribute name="value">
            <data type="boolean"/>
          </attribute>
        </element>
      </element>
      <element name="pert:extent">
        <element name="colon:invasion">
          <element name="colon:deepestInvasion">
            <attribute name="value">
              <data type="NCName"/>
            </attribute>
          </element>
          <element name="colon:adjacentStructure">
            <attribute name="value"/>
          </element>
        </element>
        <element name="pert:tumorSize">
          <attribute name="dimension-1">
            <data type="decimal"/>
          </attribute>
          <attribute name="dimension-2">
            <data type="decimal"/>
          </attribute>
          <attribute name="dimension-3">
            <data type="decimal"/>
          </attribute>
          <attribute name="unit">
            <data type="NCName"/>
          </attribute>
        </element>
      </element>
      <element name="pert:accessory">
        <element name="colon:preexistingPolyp">
          <attribute name="value">
            <data type="NCName"/>
          </attribute>
        </element>
        <element name="colon:discontinuousExtramuralExtension">
          <attribute name="value">
            <data type="boolean"/>
          </attribute>
        </element>
        <element name="pert:lymphovascularInvasion">
          <attribute name="value">
            <data type="NCName"/>
          </attribute>
        </element>
        <element name="pert:perineuralInvasion">
          <attribute name="value">
            <data type="NCName"/>
          </attribute>
        </element>
        <element name="pert:venousInvasion">
          <attribute name="value">
            <data type="boolean"/>
          </attribute>
        </element>
        <element name="pert:treatmentEffect">
          <attribute name="value">
            <data type="NCName"/>
          </attribute>
        </element>
      </element>
      <element name="pert:margins">
        <oneOrMore>
          <element name="pert:margin">
            <attribute name="location">
              <data type="NCName"/>
            </attribute>
            <attribute name="status">
              <data type="NCName"/>
            </attribute>
          </element>
        </oneOrMore>
      </element>
      <element name="pert:nodes">
        <oneOrMore>
          <element name="pert:nodeGroup">
            <attribute name="laterality">
              <data type="NCName"/>
            </attribute>
            <attribute name="location"/>
            <attribute name="positiveNodes">
              <data type="integer"/>
            </attribute>
            <attribute name="totalNodes">
              <data type="integer"/>
            </attribute>
          </element>
        </oneOrMore>
      </element>
      <element name="pert:stage">
        <element name="pert:classification">
          <attribute name="value">
            <data type="NCName"/>
          </attribute>
        </element>
        <element name="pert:T">
          <attribute name="value">
            <data type="integer"/>
          </attribute>
        </element>
        <element name="pert:N">
          <attribute name="value">
            <data type="integer"/>
          </attribute>
        </element>
        <element name="pert:M">
          <attribute name="value">
            <data type="NCName"/>
          </attribute>
        </element>
        <element name="pert:prefix">
          <attribute name="value"/>
        </element>
      </element>
    </element>
  </start>
  <define name="comment">
    <element name="pert:comment">
      <optional>
        <attribute name="xml:lang">
          <data type="NCName"/>
        </attribute>
      </optional>
      <text/>
    </element>
  </define>
  <define name="displayText">
    <element name="pert:displayText">
      <text/>
    </element>
  </define>
</grammar>


Regards,
George
George Cristian Bina
madde001
Posts: 80
Location: Durham, NC, USA

Re: Problem with ISO Schematron/XPath 2.0

Fri Dec 19, 2008 5:21 pm

George,

Thanks for the tips -- I'm definitely going to add some diagnostics as you suggested.

A question about embedding ISO Schematron -- does it matter where the <iso:ns> elements appear in the containing schema (top level vs. deep)? I have this big project I've mentioned before that has lots of includes. If I put the <iso:ns> inside a nested <rng:grammar>. will it be visible throughout the project?

John
george
Site Admin
Posts: 2100

Re: Problem with ISO Schematron/XPath 2.0

Fri Dec 19, 2008 5:52 pm

Hi John,

It should not matter. The iso:schema model is something like

(((WC[##other:"http://purl.oclc.org/dsdl/schematron"] | WC[""]){0-UNBOUNDED}) | include | title | ns | p | let | phase | pattern | diagnostics){0-UNBOUNDED}

That suggests that there is not a requirement for ns to appear first.

Just try and if you encounter any issues let us know.

Best Regards,
George
George Cristian Bina
madde001
Posts: 80
Location: Durham, NC, USA

Re: Problem with ISO Schematron/XPath 2.0

Fri Dec 19, 2008 8:41 pm

George,

So far, so good.

BTW, you know how you can include elements in the Schematron schema in the Editor > Content Completion >XSD using a preference?

Can you do the same thing for RNG? This preference setting doesn't seem to have any effect for the RNG or RNC editors.

John
george
Site Admin
Posts: 2100

Re: Problem with ISO Schematron/XPath 2.0

Sun Dec 21, 2008 10:20 am

Hi Jon,

That is available indeed only for XSD.

Best Regards,
George
George Cristian Bina

Return to “XML Schemas”

Who is online

Users browsing this forum: No registered users and 0 guests