问题
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