Is it possible with XSLT?
Created May 4, 2012
Davanum Srinivas Yes, it is possible. Use the following XSL file.
<?xml version="1.0"?> <xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0"> <xsl:output method="html" indent="yes"/> <xsl:variable name="my-user-list" select="//user" /> <xsl:variable name="my-user-list2" select="//user[not(./@firstname=following::user/@firstname)]" /> <xsl:template match="/"> <users> <xsl:for-each select="$my-user-list2"> <xsl:variable name="my-user" select="." /> <user> <username> <first> <xsl:value-of select="$my-user/@firstname" /> </first> <last> <xsl:value-of select="$my-user/@lastname" /> </last> <articles> <xsl:for-each select="$my-user-list"> <xsl:variable name="my-user2" select="." /> <xsl:if test='//*[$my-user/@firstname = $my-user2/@firstname]'> <article> <xsl:value-of select="$my-user2/@article" /> </article> </xsl:if> </xsl:for-each> </articles> </username> </user> </xsl:for-each> </users> </xsl:template> </xsl:stylesheet>The output is as follows:
<users> <user> <username> <first>Jack</first> <last>Jill</last> <articles> <article>Three</article> </articles> </username> </user> <user> <username> <first>John</first> <last>Joe</last> <articles> <article>One</article> <article>Two</article> </articles> </username> </user> </users>