【发布时间】:2015-07-28 07:36:22
【问题描述】:
我有一个看起来像这样的 xml 文件(简化):
<defs>
<def>Pure text</def>
<def>Mixed content, cuz there is also another: <element>element inside</element> and more.</def>
<def><element>Text nodes within elements other than def are ok.</element></def>
<defs>
我正在尝试编写一个带有快速修复的 Shematron 规则,这将使我能够将具有混合内容的 defs 中的每个单词都包含在 <w> 元素中,并将标点符号包含在 <pc> 元素中。换句话说,在应用快速修复后,我会得到
<defs>
<def>Pure text.</def>
<def><w>Mixed</w> <w>content</w><pc>,</pc> <w>cuz</w> <w>there</w> <w>is</w> <w>also</w> <w>another</w><pc>:</pc> <element>element inside</element> <w>and</w> <w>more</w><pc>.</pc></def>
<def><element>Text nodes within elements other than def are ok.</element></def>
<defs>
<w>s 和 <pc>s 之间的空格是可以的。
现在,识别混合内容很容易——我想我做对了。问题是我不知道如何标记 Schematron 中的字符串,然后对每个标记应用修复。这是我已经走了多远:
<sch:pattern id="mixed">
<sch:rule context="def[child::text()][child::*]">
<sch:report test="tokenize(child::text(), '\s+')" sqf:fix="mix_in_def">
Element has mixed content
<!-- the above this gives me the error: a sequence of more than one item is not allowed as the first argument of tokenize-->
</sch:report>
<sqf:fix id="mix_in_def">
<sqf:description>
<sqf:title>Wrap words in w</sqf:title>
<sqf:p>Fixes the mixed content in def by treating each non-tagged string as w.</sqf:p>
</sqf:description>
<sqf:replace match="." node-type="element" target="w">
<!--how do i represent the content of the matched token?-->
</sqf:replace>
<!-- also do i create an altogether separate rule for punctuation?-->
</sqf:fix>
</sch:rule>
</sch:pattern>
任何提示将不胜感激。
丁丁
【问题讨论】:
-
我的回答对您有帮助吗?
-
我还在等待一些反馈,请告诉我我的回答是否有用。
-
绝对。我真的很抱歉我没有承认你的回答。我的错。
-
这很有帮助 :D 没有反馈,我在想你可能在我的回答中发现了问题,我想知道哪里出了问题。
标签: xslt-2.0 tokenize xpath-2.0 schematron