我有一个大文本文件,在某些时候看起来像这样:
<w>
<randomnode>
<pa/>
<pa>
Keyword1 sometxt1 <thing>abc</thing>: blabla
</pa>
<stuff>abc</stuff>
<pa>
just blabla
</pa>
<pa>
Keyword2 othertxt2: blabla
</pa>
<pa>
just blabla
</pa>
<pa>
just blabla
</pa>
<pa>
Keyword1 xxx: and blabla
</pa>
</randomnode>
</w>
并希望得到这样的结果:
<w>
<randomnode>
<k attr="keyword1 sometxt1">
<p>
<s>
Keyword1 sometxt1 <thing>abc</thing>:
</s>
blabla
</p>
<stuff>abc</stuff>
<p>
just blabla
</p>
</k>
<k attr="keyword1 othertxt2">
<p>
<s>
Keyword2 othertxt2:
</s>
blabla
</p>
<p>
just blabla
</p>
<p>
just blabla
</p>
</k>
<k attr="keyword1 xxx">
<p>
<s>
Keyword1 xxx:
</s>
and blabla
</p>
</k>
</randomnode>
</w>
英文:我想浏览每个<pa>
,并在该节点的text()中有keyword1或keyword2或keyword3时对它们进行分组。
<s>
上:
内容的拆分是在另一个模板中完成的,一旦我可以正确地对<pa>
进行分组,就应该有效。
到目前为止,我有这个:
<xsl:for-each-group select="$randomnode/*[normalize-space(.)!='']"
group-starting-with="pa/text()[contains(., 'keyword1')
or contains(., 'keyword2') or contains(., 'keyword3')]">
问题是没有选择任何东西,我感觉这是因为text()......
我可以在text()上使用group-starting-woth吗?我真的想在使用完全不同的东西之前使用它并扩展/纠正它。
答案 0 :(得分:0)
好吧,我会彻底抛弃text()
并简单地比较
<xsl:for-each-group select="$randomnode/*[normalize-space(.)!='']"
group-starting-with="pa[contains(., 'keyword1')
or contains(., 'keyword2') or contains(., 'keyword3')]">
如果要使用text()
子节点选择,则需要
<xsl:for-each-group select="$randomnode/*[normalize-space(.)!='']"
group-starting-with="pa[text()[contains(., 'keyword1')
or contains(., 'keyword2') or contains(., 'keyword3')]]">