karthikin Posted August 5, 2011 Share Posted August 5, 2011 This is my xml file: <?xml version="1.0" encoding="UTF-8"?><CONTACTS><CONTACT><FirstName>Arun</FirstName><LastName>Arun_Neelam</LastName><Email>nuraaa_iceee@yahoo.co.in</Email></CONTACT><CONTACT><FirstName>Arun</FirstName><LastName>Arun_Neelam</LastName><Email>nuraaa_iceee@gmail.com</Email></CONTACT></CONTACTS> I want to have the output in the following way: <?xml version="1.0" encoding="windows-1250"?><CONTACTS> <CONTACT> <FirstName>Arun</FirstName> <LastName>Arun_Neelam</LastName> <Email>nuraaa_iceee@gmail.com</Email> <Email>nuraaa_iceee@yahoo.co.in</Email></CONTACT></CONTACTS> How do i group them by checking two identical values of the <FirstName><LastName>, if it's true then take the email values and put it as a single contact.I'm not sure I can do it with current-group() and current-grouping-key().Thank you for your support. Link to comment Share on other sites More sharing options...
Martin Honnen Posted August 5, 2011 Share Posted August 5, 2011 With XSLT 2.0 you can use <xsl:template match="CONTACTS"> <xsl:copy> <xsl:for-each-group select="CONTACT" group-by="concat(FirstName, '|', LastName)"> <xsl:copy> <xsl:copy-of select="FirstName, LastName, current-group()/Email"/> </xsl:copy> </xsl:for-each-group> </xsl:copy></xsl:template> With XSLT 1.0 you can use Muenchian grouping. Link to comment Share on other sites More sharing options...
karthikin Posted August 5, 2011 Author Share Posted August 5, 2011 With XSLT 2.0 you can use<xsl:template match="CONTACTS"> <xsl:copy> <xsl:for-each-group select="CONTACT" group-by="concat(FirstName, '|', LastName)"> <xsl:copy> <xsl:copy-of select="FirstName, LastName, current-group()/Email"/> </xsl:copy> </xsl:for-each-group> </xsl:copy></xsl:template> With XSLT 1.0 you can use Muenchian grouping. Thanks for the solution. Link to comment Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.