我有一个大文本文件,在某些时候看起来像这样:
<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吗? 我真的想在使用完全不同的东西之前使用它并扩展/纠正它。
I have a large text file that at some point looks like this :
<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>and want to get this result:
<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>In English: I want to go through each <pa> and group them whenever there is a keyword1 or keyword2 or keyword3 in the text() of that node. The splitting-up for the content of the <s> on the : is done in another template and should work once I can group the <pa> correctly.
I have this so far:
<xsl:for-each-group select="$randomnode/*[normalize-space(.)!='']" group-starting-with="pa/text()[contains(., 'keyword1') or contains(., 'keyword2') or contains(., 'keyword3')]">The problem ist that nothing is selected and I have a feeling it is because of text()...
Can I use group-starting-woth on text() at all? I would really like to use this and extend/correct it before I do something completly different..
最满意答案
好吧,我会彻底抛弃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')]]">Well I would ditch the text() completely and simply compare
<xsl:for-each-group select="$randomnode/*[normalize-space(.)!='']" group-starting-with="pa[contains(., 'keyword1') or contains(., 'keyword2') or contains(., 'keyword3')]">If you want to use the text() child node selection then you need
<xsl:for-each-group select="$randomnode/*[normalize-space(.)!='']" group-starting-with="pa[text()[contains(., 'keyword1') or contains(., 'keyword2') or contains(., 'keyword3')]]">更多推荐
发布评论