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