如何使用“翻译"节点集上的 Xpath 函数 [英] How to use the "translate" Xpath function on a node-set

查看:23
本文介绍了如何使用“翻译"节点集上的 Xpath 函数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个 XML 文档,其中包含我想去掉的带破折号的项目

例如

<xmlDoc>
   <items>
      <item>a-b-c</item>
      <item>c-d-e</item>
   <items>
</xmlDoc>

我知道我可以使用此 xpath 查找替换单个项目

/xmldoc/items/item[1]/translate(text(),'-','')

哪个会返回

"abc"

但是,我如何为整个集合执行此操作?

这不起作用

/xmldoc/items/item/translate(text(),'-','')

也不是这个

translate(/xmldoc/items/item/text(),'-','')

有没有办法做到这一点?

Is there a way at all to achieve that?

推荐答案

我知道我可以找到-替换单个使用此 xpath 的项目

I know I can find-replace a single item using this xpath

/xmldoc/items/item[1]/translate(text(),'-','')

哪个会返回

"abc"

但是,我该如何为全套?

however, how do I do this for the entire set?

这无法通过单个 XPath 1.0 表达式完成.

使用以下 XPath 2.0 表达式 生成一系列字符串,每个字符串都是对相应字符串值应用 translate() 函数的结果节点:

Use the following XPath 2.0 expression to produce a sequence of strings, each being the result of the application of the translate() function on the string value of the corresponding node:

/xmlDoc/items/item/translate(.,'-', '')

这篇关于如何使用“翻译"节点集上的 Xpath 函数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆