使用XSLT合并两个xml元素

时间:2012-12-18 07:16:13

标签: xslt-2.0

我有一个大的xml文件,如下所示

:
:
<CN>222</CN>
<CT>Raam</CT>
:
:

我想将这两个元素合并为

<CN>222 Raam</CN>

然后将其转换为

<div>222 Raam</div>

这是最终输出。

1 个答案:

答案 0 :(得分:1)

如果您只需要合并div中的两个连续元素(我不明白中间人CN的用途),那么请使用

<xsl:template match="@* | node()">
  <xsl:copy>
    <xsl:apply-templates select="@* | node()"/>
  </xsl:copy>
</xsl:template>

<xsl:template match="CN[following-sibling::*[1][self::CT]]">
  <div>
    <xsl:value-of select="concat(., ' ', following-sibling::*[1][self::CT])"/>
  </div>
</xsl:template>

<xsl:template match="CT[preceding-sibling::*[1][self::CN]]"/>
相关问题