2012-03-16 58 views
1

如何使用XPath 1.0重新使用Schematron断言测试?具体如何使用找到的属性名称重复使用测试。如果我不能这样做,我想重新使用一个测试,并对每个命名属性进行一次测试。 (我认为只有XPath 2.0可以使用变量)。正如您从XSD架构中看到的那样,我使用了相同的测试,但使用了不同的属性名称。注意:我知道时区测试并非万无一失,只是一个例子。如何在XPath 1.0中使用Schematron中的assert测试?

由于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> 

回答

1

从你的第一个给定的情况下,“* [@ signedWhen],你应该有访问当前节点。你可以通过“./@value”来获取其他属性,此外,你可以使用sch:let作为变量来保存这个值,这就是你可以如何关联这两个数据值的方法,尽管我并不完全确定这个是哟你完整的问题。

+1

我无法使用let变量,因为它是用于XPath 2.0的 – user610064 2012-03-24 13:55:42

相关问题