Link to home
Start Free TrialLog in
Avatar of kalyangkm
kalyangkmFlag for United States of America

asked on

Concatenating multiple occurrences of the same field into one string

Hi

I have to concatenate the multiple occurrences of the same field as follows, FYI, I am using xslt 1.0

Input code fragment
 <E1EDKT1 SEGMENT="1">
         <TDID>ZTDT</TDID>
         <E1EDKT2 SEGMENT="1"/>
            <TDLINE>ABC</TDLINE>
         </E1EDKT2>
        <E1EDKT2 SEGMENT="1"/>
            <TDLINE>DEF</TDLINE>
         </E1EDKT2>
     </E1EDKT1>

Open in new window


Output desired

<Reference> ABCDEF </Reference>

Open in new window


Code  that I am trying to apply by using string-join function
<Reference>
			    <xsl:when test="normalize-space(E1EDKT1/TDID) = 'ZTDT'">
				  <xsl:value-of select="fn:string-join(/E1EDKT2/TDLINE, ' ')" />
				</xsl:when>
  </Reference>

Open in new window

Avatar of kalyangkm
kalyangkm
Flag of United States of America image

ASKER

As String-join is not supported in XSLT 1.0 I am trying in a different way but having trouble achieving the concatenation. Please advice.

<xsl:for-each select="E1EDKT1">
			      <xsl:choose>
			         <xsl:when test="normalize-space(TDID) = 'F01'">
				   <xsl:for-each select="E1EDKT2/TDLINE">
					<Reference>
				            <xsl:value-of select="." />              
                                          </Reference>
				    </xsl:for-each>
				   </xsl:when>
				  </xsl:choose>
				 
		 </xsl:for-each> 

Open in new window

SOLUTION
Avatar of kalyangkm
kalyangkm
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
ASKER CERTIFIED SOLUTION
Avatar of Gertone (Geert Bormans)
Gertone (Geert Bormans)
Flag of Belgium image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
value-of does concatenate all the string nodes found

you can also use concat()
<Reference>
   <xsl:value-of select="concat(E1EDKT2[1]/TDLINE, ' ', E1EDKT2[2]/TDLINE)"/>
</Reference>

If you want a space in between (and you know there is only two)

Depending on the exact requirements there is a lot more you can do
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Because it is the correct solution