猿问

Xpath:如果存在多个子项,则选择多个父项

我在将 xml 文件的多个值放入 html 表时遇到问题。

我想使用以下 xpath 表达式获得具有 tcp.TcpDispatcherProperties 的 destinationConnectors 属性的所有父项的名称:

"/serverConfiguration/channels/channel[destinationConnectors/connector/properties[@class='com.mirth.connect.connectors.tcp.TcpDispatcherProperties']]/name"

用这个表达:

父级只显示一次,即使它有多个具有此类的目的地

问题是,如果有多个 destinationConnectors [1..n],我只会在我的 html 表中一次从 //channels/name 获取父级。

例如,我想用 xml.evaluate 在 Javascript 中显示的内容,如果我有 3 个频道 - Channel1 有 1 个目的地,Channel2 有 2 个目的地:

------------  -------------  -------------

Channel1Name | Channel2Name | Channel2Name

------------  -------------  -------------

Destination1  Destination2a  Destination2b

我想要的输出是:

  • Channel1Name 来自“/serverConfiguration/channels/channel/name”

  • Channel2Name 来自“/serverConfiguration/channels/channel/name”

  • Channel2Name 来自“/serverConfiguration/channels/channel/name”

不是

  • 频道名称

  • 频道名称


繁华开满天机
浏览 196回答 1
1回答

陪伴而非守候

以下 xpath 查询返回您需要的内容://channel/destinationConnectors/connector/properties[@class='com.mirth.connect.connectors.tcp.TcpDispatcherProperties']/concat(../../../name, ' : ',  ../name)描述://channel:对于channel任何地方的每个元素/destinationConnectors/connector:下降到properties通过destinationConnectors/connector//properties[@class='com.mirth.connect.connectors.tcp.TcpDispatcherProperties']:选择每个找到properties的属性class==c.m.c.c.t.TcpDispatcherProperties/concat(../../../name, ' : ',  ../name):concat()盛大,盛大父母channel name与父connector name元素将返回:Channel1 : Destination 1 Channel2 : Destination 2a Channel2 : Destination 2b更新示例:http : //xpather.com/o3eFcOCg
随时随地看视频慕课网APP

相关分类

JavaScript
我要回答