View Single Post
  #5 (permalink)  
Old June 21st, 2009, 02:17 PM
Martin Honnen Martin Honnen is offline
Friend of Wrox
Points: 3,131, Level: 23
Points: 3,131, Level: 23 Points: 3,131, Level: 23 Points: 3,131, Level: 23
Activity: 100%
Activity: 100% Activity: 100% Activity: 100%
 
Join Date: Nov 2007
Location: Germany
Posts: 655
Thanks: 0
Thanked 98 Times in 97 Posts
Default

Here is a sample stylesheet using xsl:for-each-group to group and merge the Contact elements, taking the first child element for all child elements besides the AddressIds child element, where the string-join() of all such elements in a group is taken:
Code:
<xsl:stylesheet
  xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
  version="2.0">
  
  <xsl:output indent="yes"/>
  
  <xsl:template match="Contact_CSV">
    <xsl:copy>
      <xsl:copy-of select="header"/>
      <xsl:for-each-group select="Contact" group-by="contactid">
        <xsl:copy>
          <xsl:copy-of select="AddressIds/preceding-sibling::*"/>
          <AddressIds>
            <xsl:value-of select="string-join(current-group()/AddressIds, '|')"/>
          </AddressIds>
          <xsl:copy-of select="AddressIds/following-sibling::*"/>
        </xsl:copy>
      </xsl:for-each-group>
    </xsl:copy>
  </xsl:template>

</xsl:stylesheet>
__________________
Martin Honnen
Microsoft MVP - XML
My blog

Last edited by Martin Honnen : June 21st, 2009 at 02:27 PM. Reason: correction of stylesheet
Reply With Quote
The Following User Says Thank You to Martin Honnen For This Useful Post:
navik_pathak (June 21st, 2009)