gpt4 book ai didi

java - XSL - 匹配节点的文本并附加另一个节点作为同级节点

转载 作者:行者123 更新时间:2023-12-01 15:21:06 25 4
gpt4 key购买 nike

我有这样的 XML:

<a>
<b>
<c>some text here</c>
</b>
</a>
<a>
<b>
<c>another cool text</c>
</b>
</a>

我需要在//a/b/c/text() 中匹配单词“cool”并像这样转换 XML

<a>
<b>
<c>some text here</c>
</b>
</a>
<x>
<y> prepend to cool text </y>
</x>
<a>
<b>
<c>another cool text</c>
</b>
</a>

我尝试过这个:

<xsl:template
match="//a/b/c/matches(text(),'\.*cool\*.')">
...
</xsl:template>

但运气不佳:

XTSE0340: XSLT Pattern syntax error at char 153 on line 30 in {...\.*cool\*...}:
Function call may appear only at the start of a pattern

我在这里缺少什么?

最佳答案

您的匹配不正确,应该在括号内进行测试[]:

<xsl:template
match="//a/b/c[matches(text(), '.*cool.*')]">
...
</xsl:template>

此外,如果您的正则表达式那么简单,那么您可以使用 XPath 方法 contains()

关于java - XSL - 匹配节点的文本并附加另一个节点作为同级节点,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10920736/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com