[xsl] xsl:for-each in Corresp Tag

Subject: [xsl] xsl:for-each in Corresp Tag
From: "Byomokesh Sahoo sahoo.byomokesh@xxxxxxxxx" <xsl-list-service@xxxxxxxxxxxxxxxxxxxxxx>
Date: Thu, 20 Feb 2020 15:46:07 -0000
Hi,

Here my xml and xslt

XML
<article>
<corresp><label>To</label> Anne Marie Darling, <institution
content-type="department">Department of Epidemiology</institution>,
<institution>Boston University</institution>, <addr-line
content-type="street">715 Albany Street</addr-line>,
<country>USA</country>; <email>amdarlin@xxxxxx</email></corresp>

<corresp><label>To</label> Christle; <institution
content-type="department">Department of Epidemiology</institution>,
<addr-line content-type="postal-code">02118</addr-line>,
<country>USA</country>; <email>amdarlin@xxxxxx</email></corresp>

<corresp><label>To</label> Anne Marie Darling; <institution>Department of
Epidemiology</institution>, <addr-line
content-type="city">Takd</addr-line>, <country>USA</country>; <email>
amdarlin@xxxxxx</email></corresp>

<corresp>Joanne Lawrence, Association of British Neurologists, Ormond
House, 27 Boswell Street, London WC1N 3JZ, UK; <email>
joanne.lawrence@xxxxxxxxxx</email></corresp>
</article>

my XSLT

<xsl:template match="article">
<xsl:element name="article">

<xsl:apply-templates/>
</xsl:element>
</xsl:template>

<xsl:template match="corresp">
<xsl:element name="corresp">

<xsl:for-each select="label">
<xsl:element name="x">
<xsl:value-of select="."/>
</xsl:element>
<xsl:text>, </xsl:text>
</xsl:for-each>
<institution>
<xsl:for-each select="institution">
<xsl:choose>
<xsl:when test="@content-type='department'">

<xsl:element name="department">
<xsl:apply-templates select="node()" mode="copy-no-namespaces"/>
</xsl:element>
<xsl:text>, </xsl:text>
</xsl:when>
<xsl:otherwise>
<xsl:element name="institution-name">
<xsl:value-of select="."/>
</xsl:element>
</xsl:otherwise>
</xsl:choose>
</xsl:for-each>
</institution>
<xsl:text>, </xsl:text>

<xsl:for-each select="addr-line">
<xsl:choose>
<xsl:when test="@content-type='street'">
<xsl:element name="street">
<xsl:value-of select="."/>
</xsl:element>
<xsl:text>, </xsl:text>
</xsl:when>
<xsl:when test="@content-type='postal-code'">
<xsl:element name="postal-code">
<xsl:value-of select="."/>
</xsl:element>
<xsl:text>, </xsl:text>
</xsl:when>
</xsl:choose>
</xsl:for-each>
<xsl:for-each select="country">
<xsl:element name="country">
<xsl:value-of select="."/>
</xsl:element>
<xsl:text>; </xsl:text>
</xsl:for-each>
<xsl:for-each select="email">
<xsl:element name="email">
<xsl:value-of select="."/>
</xsl:element>
</xsl:for-each>
</xsl:element>
</xsl:template>

Expected Output

<article>
<corresp><x>To</x> Anne Marie Darling, <institution><department>Department
of Epidemiology</department>, <institution-name>Boston
University</institution-name></institution>, <street>715 Albany
Street</street>, <country>USA</country>; <email>amdarlin@xxxxxx
</email></corresp>

<corresp><x>To</x> Christle; <institution><department>Department of
Epidemiology</department></institution>, <addr-line
content-type="postal-code">02118</addr-line>, <country>USA</country>;
<email>amdarlin@xxxxxx</email></corresp>

<corresp><x>To</x> Anne Marie Darling;
<institution><institution-name>Department of
Epidemiology</institution-name></institution>, <city>Takd</city>,
<country>USA</country>; <email>amdarlin@xxxxxx</email></corresp>

<corresp>Joanne Lawrence, Association of British Neurologists, Ormond
House, 27 Boswell Street, London WC1N 3JZ, UK; <email>
joanne.lawrence@xxxxxxxxxx</email></corresp>
</article>

Please suggest.

thanks
Byomokesh

Current Thread