如何使用 XPath 1.0 重用 Schematron 断言测试?具体来说,如何使用找到的属性名称重用测试。如果我不能这样做,我想重用一个测试,并且对每个命名属性只进行一个测试。(我认为只有 XPath 2.0 可以使用变量)。正如您从 XSD 架构中看到的那样,我进行了相同的测试,但使用了不同的属性名称。注意:我知道时区测试不是万无一失的,这只是一个例子。
给定 XML:
<?xml version="1.0" encoding="utf-8"?>
<MyData versionDate="2010-12-09" dataBeginDate="2012-03-01" dataEndDate="2012-03-10" extractedWhen="2012-03-09T10:08:40">
<Site Site_key="999">
<SitePatient Patient_key="1">
<txt_MyName value="test myname"/>
<txt_Surname value="test surname" signedWhen="2012-03-08T22:02:39"/>
<dat_BirthDate value="2010-06-15" signedWhen="2012-03-08T22:02:39"/>
<sel_Status value="Enrolled" signedWhen="2012-03-08T22:02:39"/>
<dat_StatusDate value="2012-03-05-05:00" signedWhen="2012-03-08T22:02:39"/>
<sel_Something value="" valueDate="2012-03-08" signedWhen="2012-03-08T22:02:39"/>
</SitePatient>
</Site>
</MyData>
给定 XSD:
<?xml version="1.0" encoding="utf-8"?>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema"
xmlns:sch="http://www.ascc.net/xml/schematron">
<xs:annotation>
<xs:appinfo>
<sch:title>Schematron Validation</sch:title>
</xs:appinfo>
<xs:appinfo>
<sch:pattern name="Check TimeZone constraints">
<sch:rule context="*[@signedWhen]">
<sch:assert test="(substring(@signedWhen, 11, 1) != '-') and (substring(@signedWhen, 11, 1) != '+') and (substring(@signedWhen, 11, 1) != 'Z')">
<name/> must not include TimeZone information
</sch:assert>
</sch:rule>
</sch:pattern>
</xs:appinfo>
<xs:appinfo>
<sch:pattern name="Check TimeZone constraints">
<sch:rule context="*[@valueDate]">
<sch:assert test="(substring(@valueDate, 11, 1) != '-') and (substring(@valueDate, 11, 1) != '+') and (substring(@valueDate, 11, 1) != 'Z')">
<name/> must not include TimeZone information
</sch:assert>
</sch:rule>
</sch:pattern>
</xs:appinfo>