我想在某些带有Schematron的特定XML内联元素(例如<ph> )之前添加空格,但前提是没有空格。我看不出我的统治问题。你能帮忙吗?
<sch:pattern id="add-space-before-ph">
<sch:rule context="ph">
<sch:assert test="preceding::text()[not(ends-with(., ' '))]"
role="warning"
sqf:fix="add-space-before-ph">Add space before <ph></sch:assert>
<sqf:fix id="add-space-before-ph">
<sqf:description>
<sqf:title>Add space before <ph></sqf:title>
</sqf:description>
<sqf:add position="before" match="." select="' '"/>
</sqf:fix>
</sch:rule>
</sch:pattern>发布于 2016-06-06 15:49:33
断言有两个问题:第一个问题是当断言未实现时显示消息,因此您需要否定它的条件;第二个问题是,您实际上是将文本节点与特定条件匹配,而不是检查文本节点是否满足某个条件,因此我认为断言应该如下所示:
<sch:assert test="ends-with(preceding::text()[1], ' ')"
role="warning"
sqf:fix="add-space-before-ph">Add space before <ph> </sch:assert> 您还应该考虑到这样一个事实:在ph值之前,可以有多个空格+换行(XML可能是非常打印的)。
https://stackoverflow.com/questions/37594229
复制相似问题