连接两个节点值 [英] Concatenate two node values

查看:30
本文介绍了连接两个节点值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有以下 XML 结构,我需要组合 handlingInstructionText 的值:

I have the following XML structure, and I need to combine the values of handlingInstructionText:

<handlingInstruction>
    <handlingInstructionText>CTAC  |  MARTINE HOEYLAERTS</handlingInstructionText>
</handlingInstruction>
<handlingInstruction>
    <handlingInstructionText>PHON  |  02/7225235</handlingInstructionText>
</handlingInstruction>

我的预期输出是

CTAC  |  MARTINE HOEYLAERTS PHON  |  02/7225235

我目前正在使用字符串连接函数,但我目前使用的 xsl 版本似乎不支持它.

I'm currently using the string-join function but it seems not supported by the version of xsl that I'm currently using.

<xsl:value-of select="otxsl:var-put('Join2_handlingInstructionText',
string-join(handlingInstruction/concat(handlingInstructionText/text(),
' ', handlingInstructionText/text())))" />

我已经尝试使用 for-each 函数来获取每个值,但我希望它只成为 1 行代码.

I already tried using a for-each function to get each value but I want it to make it a 1 line code only.

推荐答案

XSLT 1.0

<xsl:value-of select="concat(handlingInstruction[1]/handlingInstructionText,
                             ' ',
                             handlingInstruction[2]/handlingInstructionText)"/>

将返回您的预期输出:

CTAC | MARTINE HOEYLAERTS PHON | 02/7225235

对于给定的输入 XML:

for your given input XML:

<r>
  <handlingInstruction>
      <handlingInstructionText>CTAC  |  MARTINE HOEYLAERTS</handlingInstructionText>
  </handlingInstruction>
  <handlingInstruction>
      <handlingInstructionText>PHON  |  02/7225235</handlingInstructionText>
  </handlingInstruction>
</r>

假设 r 是当前节点.点击试用

更新:因此,在您的 var-put 扩展的上下文中,这将是:

Update: So, in the context of your var-put extension, this would be:

<xsl:value-of select=
              "otxsl:var-put('Join2_handlingInstructionText',
                              concat(handlingInstruction[1]/handlingInstructionText,
                                     ' ',
                                     handlingInstruction[2]/handlingInstructionText))"/>

这篇关于连接两个节点值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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