尝试在 XSLT 中构建模板以匹配特定的 Xpath 案例。
在这个示例 XML 文档中,我想匹配整个文档中的所有文本,<x>
中除外。 :
<root>
<tag1> I want this text </tag1>
<tag2> I want this text </tag2>
<x> I don't want to match on this text </x>
<tag3> I want this text </tag3>
</root>
关于这个 Xpath 有什么想法吗?我正在尝试为其构建一个模板,以针对此特定案例转换我的文档。
到目前为止,我想出的是这样的东西,但它不起作用:
<xsl:template match="text()[not(matches(.,x))]">
有什么想法吗?
最佳答案
当你写 .它采用文本节点的字符串值,而不是父节点的节点名称。匹配需要一个字符串参数
你可以这样写:
<xsl:template match="text()[not(matches(name(..),'x'))]">
或者更好:
<xsl:template match="text()[not(parent::x)]">
关于xml - 用于匹配文档中除特定元素中的文本节点之外的所有文本节点的 Xpath,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13312603/