 |
| XSLT General questions and answers about XSLT. For issues strictly specific to the book XSLT 1.1 Programmers Reference, please post to that forum instead. |
Welcome to the p2p.wrox.com Forums.
You are currently viewing the XSLT section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
|
|
|
|

June 21st, 2009, 12:41 AM
|
|
Authorized User
|
|
Join Date: Apr 2009
Posts: 19
Thanks: 4
Thanked 0 Times in 0 Posts
|
|
XML Merge Records using XSLT
Hi All,
I am new to XSLT and i am reading via "XSLT grouping" google phrase but not able to get my arms around it as i am not an XSLT pro.
I have following a sample XML data, which is Contact data in XML as input where header is just header element and contact is looping records
Code:
<?xml version="1.0" encoding="UTF-8"?>
<Contact_CSV>
- <header>
<last_name/>
<first_name/>
<salutation/>
<ebs_status/>
<job_title/>
<email/>
<phonecountrycode/>
<phoneareacode/>
<phonemainnumber/>
<phoneextension/>
<faxcountrycode/>
<faxareacode/>
<faxmainnumber/>
<faxextension/>
<cellcountrycode/>
<cellareacode/>
<cellmainnumber/>
<cellextension/>
<contactid/>
<primaryaccountid/>
<primaryaddressid/>
<salesrep/>
<externalsystemid/>
<WorkPhoneEBSID/>
<FaxEBSID/>
<CellEBSID/>
<EmailEBSID/>
<AddressIds/>
<AccountIds/>
</header>
<Contact>
<last_name>pathak</last_name>
<first_name>prashant</first_name>
<salutation/>
<ebs_status/>
<job_title/>
<email/>
<phonecountrycode>+1 badphonenumber</phonecountrycode>
<phoneareacode>+1 badphonenumber</phoneareacode>
<phonemainnumber>+1 badphonenumber</phonemainnumber>
<phoneextension>+1 badphonenumber</phoneextension>
<faxcountrycode>+1 707 1112222</faxcountrycode>
<faxareacode>+1 707 1112222</faxareacode>
<faxmainnumber>+1 707 1112222</faxmainnumber>
<faxextension>+1 707 1112222</faxextension>
<cellcountrycode>+352 0607070123467</cellcountrycode>
<cellareacode>+352 0607070123467</cellareacode>
<cellmainnumber>+352 0607070123467</cellmainnumber>
<cellextension>+352 0607070123467</cellextension>
<contactid>AAGA-3G1NHA</contactid>
<primaryaccountid>AAGA-3G1LK0</primaryaccountid>
<primaryaddressid>AAGA-3G1N9U</primaryaddressid>
<salesrep>7001</salesrep>
<externalsystemid/>
<WorkPhoneEBSID/>
<FaxEBSID/>
<CellEBSID/>
<EmailEBSID/>
<AddressIds>AAGA-3G1N9U</AddressIds>
<AccountIds>AAGA-3G1LK0</AccountIds>
</Contact>
<Contact>
<last_name>pathak</last_name>
<first_name>prashant</first_name>
<salutation/>
<ebs_status/>
<job_title/>
<email/>
<phonecountrycode>+1 badphonenumber</phonecountrycode>
<phoneareacode>+1 badphonenumber</phoneareacode>
<phonemainnumber>+1 badphonenumber</phonemainnumber>
<phoneextension>+1 badphonenumber</phoneextension>
<faxcountrycode>+1 707 1112222</faxcountrycode>
<faxareacode>+1 707 1112222</faxareacode>
<faxmainnumber>+1 707 1112222</faxmainnumber>
<faxextension>+1 707 1112222</faxextension>
<cellcountrycode>+352 0607070123467</cellcountrycode>
<cellareacode>+352 0607070123467</cellareacode>
<cellmainnumber>+352 0607070123467</cellmainnumber>
<cellextension>+352 0607070123467</cellextension>
<contactid>AAGA-3G1NHA</contactid>
<primaryaccountid>AAGA-3G1LK0</primaryaccountid>
<primaryaddressid>AAGA-3G1N9U</primaryaddressid>
<salesrep>7001</salesrep>
<externalsystemid/>
<WorkPhoneEBSID/>
<FaxEBSID/>
<CellEBSID/>
<EmailEBSID/>
<AddressIds>AAGA-3G1NA0</AddressIds>
<AccountIds>AAGA-3G1LK0</AccountIds>
</Contact>
</Contact_CSV>
desired Contact Data in XML as output Merge attribute AddressId sort AddressId
Code:
<?xml version="1.0" encoding="UTF-8"?>
<Contact_CSV>
- <header>
<last_name/>
<first_name/>
<salutation/>
<ebs_status/>
<job_title/>
<email/>
<phonecountrycode/>
<phoneareacode/>
<phonemainnumber/>
<phoneextension/>
<faxcountrycode/>
<faxareacode/>
<faxmainnumber/>
<faxextension/>
<cellcountrycode/>
<cellareacode/>
<cellmainnumber/>
<cellextension/>
<contactid/>
<primaryaccountid/>
<primaryaddressid/>
<salesrep/>
<externalsystemid/>
<WorkPhoneEBSID/>
<FaxEBSID/>
<CellEBSID/>
<EmailEBSID/>
<AddressIds/>
<AccountIds/>
</header>
<Contact>
<last_name>pathak</last_name>
<first_name>prashant</first_name>
<salutation/>
<ebs_status/>
<job_title/>
<email/>
<phonecountrycode>+1 badphonenumber</phonecountrycode>
<phoneareacode>+1 badphonenumber</phoneareacode>
<phonemainnumber>+1 badphonenumber</phonemainnumber>
<phoneextension>+1 badphonenumber</phoneextension>
<faxcountrycode>+1 707 1112222</faxcountrycode>
<faxareacode>+1 707 1112222</faxareacode>
<faxmainnumber>+1 707 1112222</faxmainnumber>
<faxextension>+1 707 1112222</faxextension>
<cellcountrycode>+352 0607070123467</cellcountrycode>
<cellareacode>+352 0607070123467</cellareacode>
<cellmainnumber>+352 0607070123467</cellmainnumber>
<cellextension>+352 0607070123467</cellextension>
<contactid>AAGA-3G1NHA</contactid>
<primaryaccountid>AAGA-3G1LK0</primaryaccountid>
<primaryaddressid>AAGA-3G1N9U</primaryaddressid>
<salesrep>7001</salesrep>
<externalsystemid/>
<WorkPhoneEBSID/>
<FaxEBSID/>
<CellEBSID/>
<EmailEBSID/>
<AddressIds>AAGA-3G1N9U|AAGA-3G1NA0</AddressIds>
<AccountIds>AAGA-3G1LK0</AccountIds>
</Contact>
after reading various site using "XSLT grouping" search i am able to form an XSLT as following but not giving me any output.
Code:
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet exclude-result-prefixes="exslt saxon bpws cis ihmap" version="2.0" xmlns:bpws="http://schemas.xmlsoap.org/ws/2003/03/business-process/" xmlns:cis="http://www.approuter.com/schemas/2003/1/UserCallouts/" xmlns:exslt="http://exslt.org/common" xmlns:ihmap="http://www.approuter.com/xmlns/2002/Mapping" xmlns:saxon="http://saxon.sf.net/" xmlns:xml="http://www.w3.org/XML/1998/namespace" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output encoding="UTF-8" indent="yes" method="xml"/>
<xsl:key name="keyContactID" match="Contact" use="contactid" />
<xsl:variable name="srcDoc2" select="bpws:getVariableData('SSI_Contact_CSV')"/>
<xsl:template match="/">
<xsl:element name="Contact" namespace="">
<xsl:for-each select="$srcDoc2/SSI_Contact_CSV/Contact[generate-id(.) = generate-id(key('keyContactID', contactid)[19])]">
<xsl:variable name="lngContactID"><xsl:value-of select="contactid" /></xsl:variable>
<xsl:variable name="lngContactID" select="//Contact[contactid=$lngContactID]" />
<xsl:element name="header" namespace="">
<xsl:element name="last_name" namespace=""/>
<xsl:element name="first_name" namespace=""/>
<xsl:element name="salutation" namespace=""/>
<xsl:element name="ebs_status" namespace=""/>
<xsl:element name="job_title" namespace=""/>
<xsl:element name="email" namespace=""/>
<xsl:element name="phonecountrycode" namespace=""/>
<xsl:element name="phoneareacode" namespace=""/>
<xsl:element name="phonemainnumber" namespace=""/>
<xsl:element name="phoneextension" namespace=""/>
<xsl:element name="faxcountrycode" namespace=""/>
<xsl:element name="faxareacode" namespace=""/>
<xsl:element name="faxmainnumber" namespace=""/>
<xsl:element name="faxextension" namespace=""/>
<xsl:element name="cellcountrycode" namespace=""/>
<xsl:element name="cellareacode" namespace=""/>
<xsl:element name="cellmainnumber" namespace=""/>
<xsl:element name="cellextension" namespace=""/>
<xsl:element name="contactid" namespace=""/>
<xsl:element name="primaryaccountid" namespace=""/>
<xsl:element name="primaryaddressid" namespace=""/>
<xsl:element name="salesrep" namespace=""/>
<xsl:element name="externalsystemid" namespace=""/>
<xsl:element name="WorkPhoneEBSID" namespace=""/>
<xsl:element name="FaxEBSID" namespace=""/>
<xsl:element name="CellEBSID" namespace=""/>
<xsl:element name="EmailEBSID" namespace=""/>
<xsl:element name="AddressIds" namespace=""/>
<xsl:element name="AccountIds" namespace=""/>
</xsl:element>
<xsl:element name="Contact" namespace="">
<xsl:element name="last_name" namespace="">
<xsl:value-of select="last_name"/>
</xsl:element>
<xsl:element name="first_name" namespace="">
<xsl:value-of select="first_name"/>
</xsl:element>
<xsl:element name="salutation" namespace="">
<xsl:value-of select="salutation"/>
</xsl:element>
<xsl:element name="ebs_status" namespace="">
<xsl:value-of select="ebs_status"/>
</xsl:element>
<xsl:element name="job_title" namespace="">
<xsl:value-of select="job_title"/>
</xsl:element>
<xsl:element name="email" namespace="">
<xsl:value-of select="email"/>
</xsl:element>
<xsl:element name="phonecountrycode" namespace="">
<xsl:value-of select="phonecountrycode"/>
</xsl:element>
<xsl:element name="phoneareacode" namespace="">
<xsl:value-of select="phoneareacode"/>
</xsl:element>
<xsl:element name="phonemainnumber" namespace="">
<xsl:value-of select="phonemainnumber"/>
</xsl:element>
<xsl:element name="phoneextension" namespace="">
<xsl:value-of select="phoneextension"/>
</xsl:element>
<xsl:element name="faxcountrycode" namespace="">
<xsl:value-of select="faxcountrycode"/>
</xsl:element>
<xsl:element name="faxareacode" namespace="">
<xsl:value-of select="faxareacode"/>
</xsl:element>
<xsl:element name="faxmainnumber" namespace="">
<xsl:value-of select="faxmainnumber"/>
</xsl:element>
<xsl:element name="faxextension" namespace="">
<xsl:value-of select="faxextension"/>
</xsl:element>
<xsl:element name="cellcountrycode" namespace="">
<xsl:value-of select="cellcountrycode"/>
</xsl:element>
<xsl:element name="cellareacode" namespace="">
<xsl:value-of select="cellareacode"/>
</xsl:element>
<xsl:element name="cellmainnumber" namespace="">
<xsl:value-of select="cellmainnumber"/>
</xsl:element>
<xsl:element name="cellextension" namespace="">
<xsl:value-of select="cellextension"/>
</xsl:element>
<xsl:element name="contactid" namespace="">
<xsl:value-of select="contactid"/>
</xsl:element>
<xsl:element name="primaryaccountid" namespace="">
<xsl:value-of select="primaryaccountid"/>
</xsl:element>
<xsl:element name="primaryaddressid" namespace="">
<xsl:value-of select="primaryaddressid"/>
</xsl:element>
<xsl:element name="salesrep" namespace="">
<xsl:value-of select="salesrep"/>
</xsl:element>
<xsl:element name="externalsystemid" namespace="">
<xsl:value-of select="externalsystemid"/>
</xsl:element>
<xsl:element name="WorkPhoneEBSID" namespace="">
<xsl:value-of select="WorkPhoneEBSID"/>
</xsl:element>
<xsl:element name="FaxEBSID" namespace="">
<xsl:value-of select="FaxEBSID"/>
</xsl:element>
<xsl:element name="CellEBSID" namespace="">
<xsl:value-of select="CellEBSID"/>
</xsl:element>
<xsl:element name="EmailEBSID" namespace="">
<xsl:value-of select="EmailEBSID"/>
</xsl:element>
<xsl:element name="AddressIds" namespace="">
<xsl:value-of select="AddressIds"/>
</xsl:element>
<xsl:element name="AccountIds" namespace="">
<xsl:value-of select="AccountIds"/>
</xsl:element>
</xsl:element>
</xsl:for-each>
</xsl:element>
</xsl:template>
</xsl:stylesheet>
i know these so much of XML tags but i am overwhelmed and scratching my head thinking where to begin...thanks in advance
|
|

June 21st, 2009, 03:41 AM
|
 |
Wrox Author
|
|
Join Date: Apr 2004
Posts: 4,962
Thanks: 0
Thanked 292 Times in 287 Posts
|
|
A few points.
Are you using XSLT 1.0 or 2.0? You stylesheet says version="2.0". If that's the case, you don't need to use the complicated Muenchian grouping approach, you can use the much simpler xsl:for-each-group instruction.
Secondly, when posting to a forum like this, please simplify the problem to get rid of inessentials. We don't need to see a list of forty fields, when the problem would be exactly the same with four. Simplifying it not only helps us to understand the problem more easily, it also helps you to understand it.
Finally, XSLT code is a lot more readable if you use literal result elements. Instead of <xsl:element name="x" namespace=""/>, write <x/>.
__________________
Michael Kay
http://www.saxonica.com/
Author, XSLT 2.0 and XPath 2.0 Programmer\'s Reference
|
|
The Following User Says Thank You to mhkay For This Useful Post:
|
|
|

June 21st, 2009, 10:42 AM
|
|
Authorized User
|
|
Join Date: Apr 2009
Posts: 19
Thanks: 4
Thanked 0 Times in 0 Posts
|
|
Hi mhkay,
please see this after for-each-group? i am doing right thing doesnt looks like can you please take a look and point the obvisous flow if you see?
I have following a sample XML data, which is Contact data in XML as input where header is just header element and contact is looping records
Code:
<?xml version="1.0" encoding="UTF-8"?>
<Contact_CSV>
- <header>
<last_name/>
<first_name/>
<contactid/>
<primaryaccountid/>
<primaryaddressid/>
<AddressIds/>
<AccountIds/>
</header>
<Contact>
<last_name>pathak</last_name>
<first_name>prashant</first_name>
<contactid>AAGA-3G1NHA</contactid>
<primaryaccountid>AAGA-3G1LK0</primaryaccountid>
<primaryaddressid>AAGA-3G1N9U</primaryaddressid>
<AddressIds>AAGA-3G1N9U</AddressIds>
<AccountIds>AAGA-3G1LK0</AccountIds>
</Contact>
<Contact>
<last_name>pathak</last_name>
<first_name>prashant</first_name>
<contactid>AAGA-3G1NHA</contactid>
<primaryaccountid>AAGA-3G1LK0</primaryaccountid>
<primaryaddressid>AAGA-3G1N9U</primaryaddressid>
<AddressIds>AAGA-3G1NA0</AddressIds>
<AccountIds>AAGA-3G1LK0</AccountIds>
</Contact>
</Contact_CSV>
desired Contact Data in XML as output Merge attribute AddressId sort AddressId
Code:
<?xml version="1.0" encoding="UTF-8"?>
<Contact_CSV>
- <header>
<last_name/>
<first_name/>
<contactid/>
<AddressIds/>
<AccountIds/>
</header>
<Contact>
<last_name>pathak</last_name>
<first_name>prashant</first_name>
<contactid>AAGA-3G1NHA</contactid>
<primaryaccountid>AAGA-3G1LK0</primaryaccountid>
<primaryaddressid>AAGA-3G1N9U</primaryaddressid>
<AddressIds>AAGA-3G1N9U|AAGA-3G1NA0</AddressIds>
<AccountIds>AAGA-3G1LK0</AccountIds>
</Contact>
after reading various site using "XSLT grouping" search i am able to form an XSLT as following but not giving me any output.
Code:
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet exclude-result-prefixes="exslt saxon bpws cis ihmap" version="2.0" xmlns:bpws="http://schemas.xmlsoap.org/ws/2003/03/business-process/" xmlns:cis="http://www.approuter.com/schemas/2003/1/UserCallouts/" xmlns:exslt="http://exslt.org/common" xmlns:ihmap="http://www.approuter.com/xmlns/2002/Mapping" xmlns:saxon="http://saxon.sf.net/" xmlns:xml="http://www.w3.org/XML/1998/namespace" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output encoding="UTF-8" indent="yes" method="xml"/>
<xsl:template match="/">
<xsl:element name="Contact_CSV" namespace="">
<xsl:element name="header" namespace="">
<xsl:element name="last_name" namespace=""/>
<xsl:element name="first_name" namespace=""/>
<xsl:element name="contactid" namespace=""/>
<xsl:element name="primaryaccountid" namespace=""/>
<xsl:element name="primaryaddressid" namespace=""/>
<xsl:element name="AddressIds" namespace=""/>
<xsl:element name="AccountIds" namespace=""/>
</xsl:element>
<xsl:for-each-group select="Contact" group-by="@contactid">
<xsl:element name="Contact" namespace="">
<xsl:element name="last_name" namespace="">
<xsl:value-of select="last_name"/>
</xsl:element>
<xsl:element name="first_name" namespace="">
<xsl:value-of select="first_name"/>
</xsl:element>
<xsl:element name="contactid" namespace="">
<xsl:value-of select="contactid"/>
</xsl:element>
<xsl:element name="primaryaccountid" namespace="">
<xsl:value-of select="primaryaccountid"/>
</xsl:element>
<xsl:element name="primaryaddressid" namespace="">
<xsl:value-of select="primaryaddressid"/>
</xsl:element>
<xsl:element name="AddressIds" namespace="">
<xsl:value-of select="AddressIds"/>
</xsl:element>
<xsl:element name="AccountIds" namespace="">
<xsl:value-of select="AccountIds"/>
</xsl:element>
</xsl:element>
</xsl:for-each-group>
</xsl:element>
</xsl:template>
</xsl:stylesheet>
|
|

June 21st, 2009, 11:35 AM
|
|
Authorized User
|
|
Join Date: Apr 2009
Posts: 19
Thanks: 4
Thanked 0 Times in 0 Posts
|
|
Hi mhkay,
i got success on XSLT but i am stuck at merging records as both records have same contactid but different AddressId i need to concate AddressId group by contactid.
Following XLST seems to work XMLSpy please give me pointer to concate AddressId
Code:
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet exclude-result-prefixes="exslt saxon bpws cis ihmap" version="2.0" xmlns:bpws="http://schemas.xmlsoap.org/ws/2003/03/business-process/" xmlns:cis="http://www.approuter.com/schemas/2003/1/UserCallouts/" xmlns:exslt="http://exslt.org/common" xmlns:ihmap="http://www.approuter.com/xmlns/2002/Mapping" xmlns:saxon="http://saxon.sf.net/" xmlns:xml="http://www.w3.org/XML/1998/namespace" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output encoding="UTF-8" indent="yes" method="xml"/>
<xsl:template match="/">
<xsl:element name="Contact_CSV" namespace="">
<xsl:element name="header" namespace="">
<xsl:element name="last_name" namespace=""/>
<xsl:element name="first_name" namespace=""/>
<xsl:element name="contactid" namespace=""/>
<xsl:element name="primaryaccountid" namespace=""/>
<xsl:element name="primaryaddressid" namespace=""/>
<xsl:element name="AddressIds" namespace=""/>
<xsl:element name="AccountIds" namespace=""/>
</xsl:element>
<xsl:for-each-group select="Contact_CSV/Contact" group-by=".">
<xsl:sort select="."/>
<xsl:value-of select="."/>
<xsl:for-each-group select="current-group()" group-by="contactid">
<xsl:element name="Contact" namespace="">
<xsl:element name="last_name" namespace="">
<xsl:value-of select="last_name"/>
</xsl:element>
<xsl:element name="first_name" namespace="">
<xsl:value-of select="first_name"/>
</xsl:element>
<xsl:element name="contactid" namespace="">
<xsl:value-of select="contactid"/>
</xsl:element>
<xsl:element name="primaryaccountid" namespace="">
<xsl:value-of select="primaryaccountid"/>
</xsl:element>
<xsl:element name="primaryaddressid" namespace="">
<xsl:value-of select="primaryaddressid"/>
</xsl:element>
<xsl:element name="AddressIds" namespace="">
<xsl:value-of select="AddressIds"/>
</xsl:element>
<xsl:element name="AccountIds" namespace="">
<xsl:value-of select="AccountIds"/>
</xsl:element>
</xsl:element>
</xsl:for-each-group>
</xsl:for-each-group>
</xsl:element>
</xsl:template>
</xsl:stylesheet>
|
|

June 21st, 2009, 01:17 PM
|
|
Friend of Wrox
|
|
Join Date: Nov 2007
Posts: 1,243
Thanks: 0
Thanked 245 Times in 244 Posts
|
|
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, Data Platform Development) 2005/04 - 2013/03
My blog
Last edited by Martin Honnen; June 21st, 2009 at 01:27 PM..
Reason: correction of stylesheet
|
|
The Following User Says Thank You to Martin Honnen For This Useful Post:
|
|
|

June 21st, 2009, 08:53 PM
|
|
Authorized User
|
|
Join Date: Apr 2009
Posts: 19
Thanks: 4
Thanked 0 Times in 0 Posts
|
|
thanks Martin....this is amazing...little code and does amazing stuff..thanks again...
|
|

June 22nd, 2009, 12:01 PM
|
|
Authorized User
|
|
Join Date: Apr 2009
Posts: 19
Thanks: 4
Thanked 0 Times in 0 Posts
|
|
Hi Mhkay/Martin,
please verify the following XSLT for removing duplicate
Code:
<?xml version="1.0" encoding="UTF-8"?>
<Contact_CSV>
<header>
<last_name/>
<first_name/>
<contactid/>
<primaryaccountid/>
<primaryaddressid/>
<AddressIds/>
<AccountIds/>
</header>
<Contact>
<last_name>My Last Name</last_name>
<first_name>My First Name</first_name>
<contactid>AAGA-3G9GQE</contactid>
<primaryaccountid>AAGA-3G94WA</primaryaccountid>
<primaryaddressid>AAGA-3FY71P</primaryaddressid>
<AddressIds>AAGA-3FY71P</AddressIds>
<AccountIds>AAGA-3G94WA</AccountIds>
</Contact>
<Contact>
<last_name>My Last Name</last_name>
<first_name>My First Name</first_name>
<contactid>AAGA-3G9GQE</contactid>
<primaryaccountid>AAGA-3G94WA</primaryaccountid>
<primaryaddressid>AAGA-3FY71P</primaryaddressid>
<AddressIds>AAGA-3FY71P</AddressIds>
<AccountIds>AAGA-3G94WA</AccountIds>
</Contact>
</Contact_CSV>
what am i missing
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="current-group()"/>
</xsl:copy>
</xsl:for-each-group>
</xsl:copy>
</xsl:template>
</xsl:stylesheet>
this is not removing duplicate
|
|

June 22nd, 2009, 12:06 PM
|
|
Friend of Wrox
|
|
Join Date: Nov 2007
Posts: 1,243
Thanks: 0
Thanked 245 Times in 244 Posts
|
|
Well you group but then copy the context node (which I think is the first item in the current group) and then inside of that you output the complete group.
I guess you want
Code:
<xsl:template match="Contact_CSV">
<xsl:copy>
<xsl:copy-of select="header"/>
<xsl:for-each-group select="Contact" group-by="contactid">
<xsl:copy-of select="."/>
</xsl:for-each-group>
</xsl:copy>
</xsl:template>
__________________
Martin Honnen
Microsoft MVP (XML, Data Platform Development) 2005/04 - 2013/03
My blog
|
|
The Following User Says Thank You to Martin Honnen For This Useful Post:
|
|
|

June 22nd, 2009, 12:20 PM
|
|
Authorized User
|
|
Join Date: Apr 2009
Posts: 19
Thanks: 4
Thanked 0 Times in 0 Posts
|
|
Thanks..Martin..
|
|

June 22nd, 2009, 05:02 PM
|
|
Authorized User
|
|
Join Date: Apr 2009
Posts: 19
Thanks: 4
Thanked 0 Times in 0 Posts
|
|
Hi Martin/Mhkay,
Please let me know how can i first sort AddressId and concat them after?
Thanks
Prashant Pathak
|
|
 |