Is it possible to make a rule in XPath which identifies xml elements like this one:
<A>something...<A>
?
I am using Schematron and I need to specify that some elements must not have children like the one in the example, that's why I need to identify them.
Thanks in advance
For the following input:
<?xml version="1.0" encoding="utf-8"?>
<root>
<a>Only Text</a>
<a><b>Child node</b></a>
<a><b>Child node</b>Mixed content</a>
</root>
These Schematron rules should do what you want:
<?xml version="1.0" encoding="UTF-8"?>
<iso:schema xmlns:iso="http://purl.oclc.org/dsdl/schematron">
<iso:pattern id="children tests">
<iso:rule context="a">
<iso:assert test="child::node()">
Element has nodes
</iso:assert>
<iso:report test="child::*">
Element has child elements
</iso:report>
<iso:assert test="empty(child::text())">
Element has text
</iso:assert>
<iso:report test="child::text() and empty(child::*)">
Element has only text
</iso:report>
</iso:rule>
</iso:pattern>
</iso:schema>
来源:https://stackoverflow.com/questions/14651586/identify-xml-text-elements-with-schematron