none
Concatenation using XSLT - BizTalk repeating field RRS feed

  • Question

  • I have a requirement where in my Inbound Message I receive repeated field.
    I have to output concatinating one field as in Output below. How can I achieve this ?
    Is this through XSLT ? inLine XSLT  or Orchestration.

    Please advise

    Input

    <ns0:Test xmlns:ns0="http://TestJSON.OneFiled">
      <Name>Andrew</Name>
      <OfficeRoles>Developer</OfficeRoles>
      <OfficeRoles>Support</OfficeRoles>
      <OfficeRoles>QA</OfficeRoles>
      <OfficeRoles>Analyst</OfficeRoles>
    </ns0:Test>

    My Inbound Schema

    <?xml version="1.0" encoding="utf-16"?>
    <xs:schema xmlns:b="http://schemas.microsoft.com/BizTalk/2003" attributeFormDefault="unqualified" elementFormDefault="unqualified" targetNamespace="http://TestJSON.OneFiled" xmlns:xs="http://www.w3.org/2001/XMLSchema">
      <xs:element name="Test">
        <xs:complexType>
          <xs:sequence>
            <xs:element maxOccurs="unbounded" name="OfficeRoles" type="xs:string" />
            <xs:element minOccurs="0" name="Name" type="xs:string" />
          </xs:sequence>
        </xs:complexType>
      </xs:element>
    </xs:schema>

    Output 

    <ns0:Test xmlns:ns0="http://TestJSON.OneFiled">
      <Name>Andrew</Name>
      <OfficeRoles>Developer, Support, QA,Analyst </OfficeRoles>  
    </ns0:Test>



    RH

    Thursday, September 5, 2019 7:48 PM

All replies

  • Give a try the Cumulative Concatenate string functoid.

    Cumulative Concatenate Functoid


    Mandar Dharmadhikari

    Thursday, September 5, 2019 11:26 PM
    Moderator
  • Try this XSLT:

    <xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0" xmlns:ns0="http://TestJSON.OneFiled">
      <xsl:template match="ns0:Test">
        <ns0:Test>
          <Name>
            <xsl:value-of select="Name/text()" />
          </Name>
          <OfficeRoles>
            <xsl:for-each select="OfficeRoles">
              <xsl:value-of select="." />
              <xsl:if test="position() != last()">, </xsl:if>
            </xsl:for-each>
          </OfficeRoles>
        </ns0:Test>
      </xsl:template>
    </xsl:stylesheet>

    Morten la Cour

    Friday, September 6, 2019 1:41 PM
  • when I tried that it works, but it is giving big long empty spaces . How to fix this ?

    and in JSON it is coming as below. I need to remove all \r\n


    RH


    • Edited by Dan2890 Friday, September 6, 2019 3:01 PM a
    Friday, September 6, 2019 2:13 PM
  • Try this

    <xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0" xmlns:ns0="http://TestJSON.OneFiled">
      <xsl:template match="ns0:Test">
        <ns0:Test>
          <Name>
            <xsl:value-of select="Name/text()" />
          </Name>
          <OfficeRoles>
            <xsl:for-each select="OfficeRoles">
              <xsl:value-of select="normalize-space(.)" />
              <xsl:if test="position() != last()">, </xsl:if>
            </xsl:for-each>
          </OfficeRoles>
        </ns0:Test>
      </xsl:template>
    </xsl:stylesheet>

    Morten la Cour

    • Proposed as answer by Rasmus Jaeger Friday, September 13, 2019 8:41 AM
    Friday, September 6, 2019 8:54 PM
  • I tried the code, but no that didnt work. Its giving me same result with spaces as sent in screenshot before.

    Please advise how to fix this ?


    RH

    Friday, September 6, 2019 9:15 PM