Xml 如何使用XPath 1.0重用Schematron中的断言测试?
如何使用XPath 1.0重用Schematron断言测试?具体来说,如何使用找到的属性名重用测试。如果我不能做到这一点,我希望重用一个测试,并且只为每个命名属性进行一个测试。(我认为只有XPath2.0可以使用变量)。从XSD模式中可以看到,我有相同的测试,但使用不同的属性名称。注意:我知道时区测试不是万无一失的,它只是一个例子 给定XML:Xml 如何使用XPath 1.0重用Schematron中的断言测试?,xml,xpath,xsd,reusability,schematron,Xml,Xpath,Xsd,Reusability,Schematron,如何使用XPath 1.0重用Schematron断言测试?具体来说,如何使用找到的属性名重用测试。如果我不能做到这一点,我希望重用一个测试,并且只为每个命名属性进行一个测试。(我认为只有XPath2.0可以使用变量)。从XSD模式中可以看到,我有相同的测试,但使用不同的属性名称。注意:我知道时区测试不是万无一失的,它只是一个例子 给定XML: <?xml version="1.0" encoding="utf-8"?> <MyData versionDate="2010-12
<?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>
<?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>
给定XSD:
<?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>
<?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>
Schematron验证
不得包含时区信息
不得包含时区信息
从您的第一个给定上下文“*[@signedWhen],您应该可以访问当前节点。您可以通过“/@value”提取其他属性。此外,您可以使用sch:let作为变量保留此值。这就是如何关联这两个数据值的方法,尽管我不能完全确定这是否是您的全部问题。从您的第一个给定上下文“*[@signedWhen],您应该可以访问当前节点。您可以通过“/@value”提取其他属性。此外,您可以使用sch:let作为变量保留此值。这就是如何关联这两个数据值的方法,尽管我不能完全确定这是否是您的全部问题。我不能像XPath 2.0那样使用let变量,也不能像XPath 2.0那样使用let变量