I have following xslt, which creates separate records only using invoice field. I have a requirement where it should create separate record for each unique invoice and id fields. Below is my XSLT. How can I achieve this with my below xslt ?
<?xml version="1.0" encoding="utf-16"?> <xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:msxsl="urn:schemas-microsoft-com:xslt" xmlns:var="http://schemas.microsoft.com/BizTalk/2003/var" exclude-result-prefixes="msxsl var s0" version="1.0" xmlns:s0="http://Brightstar.Integration.IPMSerengeti.Schemas.Invoices" xmlns:ns0="http://Brightstar.Integration.Serengeti.IPM.Schemas.IPM_SR"> <xsl:output omit-xml-declaration="yes" method="xml" version="1.0" /> <xsl:template match="/"> <xsl:apply-templates select="/s0:invoices" /> </xsl:template> <xsl:key name="groups" match="invoice" use="invoice"/> <xsl:template match="/s0:invoices" > <ns0:Root> <xsl:for-each select="invoice[generate-id(.)=generate-id(key('groups',invoice))]"> <xsl:sort select="id" order="ascending"/> <req> <xsl:attribute name="CpnyId"> <xsl:value-of select="1011"/> </xsl:attribute> <xsl:attribute name="VendId"> <xsl:value-of select="id/text()"/> </xsl:attribute> <xsl:attribute name="InvcNbr"> <xsl:value-of select="invoice/text()"/> </xsl:attribute> <xsl:attribute name="InvcDate"> <xsl:value-of select="concat(substring(date,7,4),'-',substring(date,1,2),'-',substring(date,4,2),'+00:00')"/> </xsl:attribute> <xsl:attribute name="ReqAmt"> <xsl:value-of select="sum(key('groups', invoice)/amount)"/> </xsl:attribute> <xsl:for-each select="key('groups',invoice) "> <rit> <xsl:attribute name="CpnyId"> <xsl:value-of select="company"/> </xsl:attribute> <xsl:attribute name="Acct"> <xsl:value-of select="account"/> </xsl:attribute> <xsl:attribute name="Sub"> <xsl:value-of select="subaccount"/> </xsl:attribute> <xsl:attribute name="TranAmt"> <xsl:value-of select="amount"/> </xsl:attribute> <xsl:attribute name="Descr"> <xsl:value-of select="description"/> </xsl:attribute> </rit> </xsl:for-each> <!-- </Detail>--> </req> </xsl:for-each> </ns0:Root> </xsl:template> </xsl:stylesheet>