You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

如何用XSL合并XML的Name与Surname节点生成新节点

Fixing XSLT to Combine Name and Surname with a Space

Your current XSLT is missing a space between the Name and Surname values, which is why you’re getting combined text without a gap (like JanKowalski instead of Jan Kowalski). Here’s how to fix it:

Corrected XSLT Code

<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
  <xsl:template match="/">
    <xsl:for-each select="ClientList/Client">
      <xsl:element name="NameSurname">
        <!-- Option 1: Explicitly add a space using xsl:text -->
        <xsl:value-of select="Name"/>
        <xsl:text> </xsl:text>
        <xsl:value-of select="Surname"/>
        
        <!-- Alternatively, use concat() for a more concise approach:
        <xsl:value-of select="concat(Name, ' ', Surname)"/>
        -->
      </xsl:element>
    </xsl:for-each>
  </xsl:template>
</xsl:stylesheet>

Breakdown of the Fix:

  • Option 1: Using <xsl:text> </xsl:text> guarantees a single space between the first and last name. This is explicit and avoids accidental whitespace issues from line breaks in your code.
  • Option 2: The concat() function combines the Name value, a space string, and the Surname value into one unified string, which is output directly. This is a cleaner way to handle concatenation in a single line.

Input XML

<ClientList>
  <Client>
    <Name>Jan</Name>
    <Surname>Kowalski</Surname>
  </Client>
</ClientList>

Expected Output XML

<NameSurname>Jan Kowalski</NameSurname>

Either approach will give you the desired formatted name with the proper space between components.

内容的提问来源于stack exchange,提问作者Name

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.05.26 10:19:21