How to check in xPath if a type is equal to a type or derived from the type

佐手、 提交于 2019-12-02 01:45:30

问题


I'm working with xPath inside Schematron. I'm able to check that a type is equal to a target type. For example 'xsd:string eq xsd:string'.

<sch:rule context="uis:variable/uis:dependency/uis:length">
<sch:assert test="**../../@type eq 'xsd:string'**">      
Text        
</sch:assert>                       
</sch:rule>

How can I check if a type defined by the user, which has been derived from xsd:string? I've tried:

<sch:rule context="uis:variable/uis:dependency/uis:length">
<sch:assert test="**../../@type instance of attribute (*,xsd:string)**">
Text        
</sch:assert>                       
</sch:rule>

But it does't work.


回答1:


There's no exposed XPath 2.0 functionality for doing this. In fact XPath 2.0 types aren't first-class values; there is no way of finding a type from a name known only at run-time, or asking for properties of the type. You'll need to use extensions: both Xerces and Saxon have APIs for interrogating schema components, and you could construct Java extension functions that invoke these.



来源:https://stackoverflow.com/questions/8323452/how-to-check-in-xpath-if-a-type-is-equal-to-a-type-or-derived-from-the-type

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!