|
|
 |
| 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 p2p Programmer to Programmer discussion community. This is a community of more than 40,000 computer programmers including Wrox book authors and readers. As a guest, you can read any forum posting. By joining our free Wrox p2p community you can post your own programming questions and respond to other programmers’ questions. Registered users also don't have to see the ads that are displayed to guests. Registration is fast, simple and absolutely free so please, join today!
Join today and post to win prizes! Post more to increase your chances of being Wrox’s top poster of the month.
|
 |
|

June 21st, 2009, 01: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, 04:41 AM
|
 |
Wrox Author
Points: 12,642, Level: 48 |
|
|
Join Date: Apr 2004
Location: Reading, Berks, United Kingdom.
Posts: 3,900
Thanks: 0
Thanked 80 Times in 78 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, 11: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, 12:35 PM
|
|
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, 02:17 PM
|
|
Friend of Wrox
|
|
Join Date: Nov 2007
Location: Germany
Posts: 626
Thanks: 0
Thanked 88 Times in 88 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
My blog
Last edited by Martin Honnen : June 21st, 2009 at 02:27 PM.
Reason: correction of stylesheet
|
|
The Following User Says Thank You to Martin Honnen For This Useful Post:
|
|

June 21st, 2009, 09: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, 01: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, 01:06 PM
|
|
Friend of Wrox
|
|
Join Date: Nov 2007
Location: Germany
Posts: 626
Thanks: 0
Thanked 88 Times in 88 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
My blog
|
|
The Following User Says Thank You to Martin Honnen For This Useful Post:
|
|

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

June 22nd, 2009, 06: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
|
| Thread Tools |
Search this Thread |
|
|
|
| Display Modes |
Linear Mode
|
Posting Rules
|
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
HTML code is Off
|
|
|
|
 |