【发布时间】:2016-02-05 20:01:37
【问题描述】:
我要疯了……
test 无法使用广泛匹配的任何正则表达式,例如 '^.+$'(显示在示例文件中),但适用于特定的 '^C.+$'
我也试过test="string-length(.) > 0",但失败了。
请帮忙。
这是 XML 文件:
<article>
<back><ack>
<title>Acknowledgements</title>
<p>The authors would like to thank <funding-source rid="sp1">CNPq</funding-source> (Process numbers <award-id rid="sp1">303287/2013-6</award-id> and <award-id rid="sp1">303559/2012-8</award-id>), <funding-source rid="sp2">FAPESP</funding-source> (Process number <award-id rid="sp2">2012/12207-6</award-id>) and <funding-source rid="sp3">CAPES</funding-source> (Process number <award-id rid="sp3">12357-13-8</award-id>) for the financial support.</p>
</ack></back></article>
这是失败的 schematron 文件:
<schema xmlns="http://purl.oclc.org/dsdl/schematron"
queryBinding="exslt"
xml:lang="en">
<ns uri="http://www.w3.org/1999/xlink" prefix="xlink"/>
<ns uri="http://exslt.org/regular-expressions" prefix="regexp"/>
<pattern id="funding_info">
<title>Make sure funding-source does not happen inside p</title>
<assert test="regexp:test(current(), '^.+$')">
EC-CHECK: Nao deve haver 'funding-source' nem 'award-id' dentro de 'p'
</assert>
</rule>
</pattern>
</schema>
这是 WORKS 的 schematron 文件:
<schema xmlns="http://purl.oclc.org/dsdl/schematron"
queryBinding="exslt"
xml:lang="en">
<ns uri="http://www.w3.org/1999/xlink" prefix="xlink"/>
<ns uri="http://exslt.org/regular-expressions" prefix="regexp"/>
<pattern id="funding_info">
<title>Make sure funding-source does not happen inside p</title>
<assert test="regexp:test(current(), '^C.+$')">
EC-CHECK: Nao deve haver 'funding-source' nem 'award-id' dentro de 'p'
</assert>
</rule>
</pattern>
</schema>
【问题讨论】:
-
我猜在第一个文件中
.正在丢弃换行符。其次,它匹配C,然后转到everything,因为.在正则表达式中跟随C。 -
我对@987654333@了解不多,但是如果您能够添加
modes,那么添加模式s。 -
试试
^[\s\S]+$或^[^]+$ -
工作或失败,如果有的话,第一个应该总是工作。如果第二个有效,那么这不是因为明显的正则表达式结构,而是因为 schematron 对它的解释。这当然是错的。
-
您没有指定规则的上下文。另外,您能否解释一下为什么使用 exslt queryBinding 而不是标准的 queryBinding 和函数?
标签: regex xml xslt schematron