how to concatenate multiple xml node entries using xslt 1.0

mmalik15
mmalik15 used Ask the Experts™
on
I need to concatenate entries and need to separate each entry with a space.

For example:
<dc:description>Includes bibliographical references and index.</dc:description>
<dc:description>The need for a multiprofessional approach in wound care / Karen Ousey and Caroline McIntosh.</dc:description>  
<dc:description>Description based on print version record.</dc:description> and I want output like this
Includes bibliographical references and index. The need for a multiprofessional approach in wound care / Karen Ousey and Caroline McIntosh. Description based on print version record.
Comment
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
Kevin CrossChief Technology Officer
Most Valuable Expert 2011

Commented:
Is each XML element shown a different row in SQL Server? Or is this a straight XSL transformation question?

Author

Commented:
its a straight xml to xml conversion using xslt

the xslt below creates three body elements but i want to merge all of them in one body element

<xsl:for-each select="dc:description">
                  <body>

                        <xsl:copy-of  select="./text()"/>

                  </body>
            </xsl:for-each>

Author

Commented:
I dont know why sql server zone has been selected as i only selected xml :S
Amazon Web Services

Are you thinking about creating an Amazon Web Services account for your business? Not sure where to start? In this course you’ll get an overview of the history of AWS and take a tour of their user interface.

Author

Commented:
thanks
I guess, you need something like this:
<body>
	<xsl:for-each select="dc:description">
		<xsl:value-of select="."/><xsl:text> </xsl:text>
	</xsl:for-each>
</body>

Open in new window

Kevin CrossChief Technology Officer
Most Valuable Expert 2011

Commented:
You are most welcome. I am more on the database side, but from my past experience with XSLT I would think you want the <body> on the outside of the <xsl:for-each>. Then you are just using the for-each to get the copy-of or value-of each instance of <dc:description>. To get the additional space, try a <xsl:text> to include a literal " ".

e.g.,
<body>
   <xsl:for-each select="dc:description">
      <xsl:value-of  select="."/>
      <xsl:if test="position()!=last()">
         <xsl:text> </xsl:text>
      </xsl:if>
   </xsl:for-each>
</body>

Open in new window


Hope that helps until XML/XSL Experts arrive.
Kevin CrossChief Technology Officer
Most Valuable Expert 2011

Commented:
Wow. See what I mean, it took me 10 minutes to type out what a true Expert could in five. *laughing*
See http:#a36489960 for answer.

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial