create a list of elements having common element using xslt

sherrytickle

New Member
I have been trying to write a style sheet for the following documents which can check for all the users their awards and add the name of that user as subelement to the /awards/award element \[code\]<document> <users> <user identity="1"> <name> <first>abc</first> <last>xyz</last> </name> <achievements> <achievement>Award A</achievement> <achievement>Award B</achievement> </achievements> </user> <user identity="2"> <name> <first>123</first> <last>DEF</last> </name> <achievements> <received>Award A</received> </achievements> </user> <user identity = "3"> <name> <first>aaa</first> <last>bbb</last> </name> <achievements> <received>Award B</received> </achievements> </user> </users> <!--awards--> <awards> <award> <name>Award A</name> <!--here the list of the users who recieved this award has to be included--> </award> <award> <name>Award B</name> </award> </awards></document>\[/code\]I wrote down the following incomplete stylesheet\[code\]<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0"> <xsl:output method="xml" indent="yes"/> <xsl:template match="node()|@*"> <xsl:copy> <xsl:apply-templates select="node()|@*"/> </xsl:copy> </xsl:template> <xsl:template match="awards/award"> <xsl:copy> <xsl:apply-templates select="node()|@*"/> <!--how can i create a list of all users who have this award--> </xsl:copy> </xsl:template></xsl:stylesheet>\[/code\]I can not figure out the way of writing a query in the template "awards/award" like "add all those users who have received this award as sub elements called user and the value of added element to be the name of the users" and gives following output. I will much appreciate if someone can guide me to the correct approach.\[code\]<document> <users> <user identity="1"> <name> <first>abc</first> <last>xyz</last> </name> <achievements> <achievement>Award A</achievement> <achievement>Award B</achievement> </achievements> </user> <user identity="2"> <name> <first>123</first> <last>DEF</last> </name> <achievements> <received>Award A</received> </achievements> </user> <user identity="3"> <name> <first>aaa</first> <last>bbb</last> </name> <achievements> <received>Award B</received> </achievements> </user> </users> <!--awards--> <awards> <award> <name>Award A</name> <user identity="1">abc xyz</user> <user identity="2">123 DEF</user> </award> <award> <name>Award B</name> <user identity="1">abc xyz</user> <user identity="3">aaa bbb</user> </award> </awards></document>\[/code\]thanks in advance
 
Back
Top