karthikin Posted June 30, 2011 Share Posted June 30, 2011 Hi Guys, I want to change my xml format in to another format using XSLT. I have manged to change the format i have problem in getting the type of email and the value of email. Please help me guys..This is my original xml file: <?xml version="1.0" encoding="windows-1250"?><CONTACTS> <CONTACT> <FirstName>Arun_niit</FirstName> <LastName>Arun_niit</LastName> <EMail>nura_ice@yahoo.co.in</EMail> </CONTACT> <CONTACT> <FirstName>FodenBen'</FirstName> <LastName>Ben' Foden</LastName> <URL>http://www.facebook.com/profile.php?id=100002440474277</URL> </CONTACT> <CONTACT> <FirstName>GhorbelMahmoud</FirstName> <LastName>Mahmoud Ghorbel</LastName> <EMail>mahmoud.ghorbel@alcatel-lucent.com</EMail> </CONTACT> <CONTACT> <FirstName>keyankarthik</FirstName> <LastName>karthik keyan</LastName> <EMail>karthycse@yahoo.co.in</EMail> </CONTACT> <CONTACT> <FirstName>Rangarajkarthik</FirstName> <LastName>karthik Rangaraj</LastName> <EMail>kart2006@gmail.com</EMail> <EMail>karthikrangaraj@yahoo.com</EMail> </CONTACT> <CONTACT> <FirstName>ReddyAkky</FirstName> <LastName>Akky Reddy</LastName> <EMail>akkireddych@gmail.com</EMail> </CONTACT> <CONTACT> <FirstName>SandfordFrankie</FirstName> <LastName>Frankie Sandford</LastName> <URL>http://www.facebook.com/FrankieSandfordApprovedPage</URL> </CONTACT> <CONTACT> <FirstName>TheSatsRochelle</FirstName> <LastName>Rochelle TheSats</LastName> <URL>http://www.facebook.com/profile.php?id=100002487211054</URL> </CONTACT> <CONTACT> <FirstName>KumarVeera</FirstName> <LastName>Veera_Kumar</LastName> <EMail>KUMARg_81@yahoo.com</EMail> </CONTACT></CONTACTS> I want the output like this: <?xml version="1.0" encoding="UTF-8"?><CONTACTS><CONTACT><PDE-Identity>N65539</PDE-Identity><FirstName>Arun_niit</FirstName><LastName>Arun_niit</LastName><Facebook-ID/><EMail><Type="yahoo" Value="nura_ice@yahoo.co.in"/></EMail></CONTACT><CONTACT><PDE-Identity>N65546</PDE-Identity><FirstName>FodenBen'</FirstName><LastName>Ben' Foden</LastName><URL>http://www.facebook.com/profile.php?id=100002440474277</URL><Facebook-ID>100002440474277</Facebook-ID><EMAILS/></CONTACT><CONTACT><PDE-Identity>N65553</PDE-Identity><FirstName>GhorbelMahmoud</FirstName><LastName>Mahmoud Ghorbel</LastName><Facebook-ID/><EMail><Type="alcatel-lucent" Value="mahmoud.ghorbel@alcatel-lucent.com"/></EMail><CONTACT><PDE-Identity>N65567</PDE-Identity><FirstName>Rangarajkarthik</FirstName><LastName>karthik Rangaraj</LastName><Facebook-ID/><EMail><Type="gmail" Value="kart2006@gmail.com"/><Type="yahoo" Value="karthikrangaraj@yahoo.com"/></EMail></CONTACT></CONTACTS> This is my xsl file: <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"> <xsl:output method="xml" indent="yes"/> <xsl:strip-space elements="*"/> <xsl:template match="node()|@*"> <xsl:copy> <xsl:apply-templates select="node()|@*"/> </xsl:copy> </xsl:template> <xsl:template match="CONTACT"> <xsl:copy> <PDE-Identity> <xsl:value-of select="generate-id(.)"/> </PDE-Identity> <xsl:copy-of select="FirstName|LastName|URL"/> <Facebook-ID><!-- To extract the ID value from URL/Email --> <xsl:choose> <xsl:when test="URL"> <xsl:value-of select="substring-after(URL,'?id=')"/> </xsl:when> <xsl:otherwise> <!-- <xsl:value-of select="substring-before(EMail[1],'@')"/>--> </xsl:otherwise> </xsl:choose> </Facebook-ID> <EMAIL> <Type = "" <xsl:value-of select="substring-before( substring-after(.,'@'), '.')"/> <value ="" <xsl:value-of select="."/> </EMAIL> </xsl:copy> </xsl:template></xsl:stylesheet> In my xsl file, i have problem with the extracting the email type and vales in the right format. Please help me guys. Thank you.Note: By mistake i have the same topic in xml section. Sorry for that. Link to comment Share on other sites More sharing options...
Martin Honnen Posted June 30, 2011 Share Posted June 30, 2011 Sorry but <Type="alcatel-lucent" Value="mahmoud.ghorbel@alcatel-lucent.com"/> is not XML so it is not clear what output you want. Link to comment Share on other sites More sharing options...
karthikin Posted June 30, 2011 Author Share Posted June 30, 2011 Sorry but<?xml version="1.0" encoding="UTF-8"?><CONTACTS><CONTACT><PDE-Identity>N65539</PDE-Identity><FirstName>Arun_niit</FirstName><LastName>Arun_niit</LastName><Facebook-ID/><EMAILS><EMail><Type>yahoo</Type><Value>nura_ice@yahoo.co.in</Value></EMail></EMAILS></CONTACT><CONTACT><PDE-Identity>N65546</PDE-Identity><FirstName>FodenBen'</FirstName><LastName>Ben' Foden</LastName><URL>http://www.facebook.com/profile.php?id=100002440474277</URL><Facebook-ID>100002440474277</Facebook-ID><EMAILS/></CONTACT><CONTACT><PDE-Identity>N65553</PDE-Identity><FirstName>GhorbelMahmoud</FirstName><LastName>Mahmoud Ghorbel</LastName><Facebook-ID/><EMAILS><EMail><Type>alcatel-lucent</Type><Value>mahmoud.ghorbel@alcatel-lucent.com</Value></EMail></EMAILS></CONTACT><CONTACT><PDE-Identity>N65560</PDE-Identity><FirstName>keyankarthik</FirstName><LastName>karthik keyan</LastName><Facebook-ID/><EMAILS><EMail><Type>yahoo</Type><Value>karthycse@yahoo.co.in</Value></EMail></EMAILS></CONTACT><CONTACT><PDE-Identity>N65567</PDE-Identity><FirstName>Rangarajkarthik</FirstName><LastName>karthik Rangaraj</LastName><Facebook-ID/><EMAILS><EMail><Type>gmail</Type><Value>kart2006@gmail.com</Value></EMail><EMail><Type>yahoo</Type><Value>karthikrangaraj@yahoo.com</Value></EMail></EMAILS></CONTACT><CONTACT><PDE-Identity>N65576</PDE-Identity><FirstName>ReddyAkky</FirstName><LastName>Akky Reddy</LastName><Facebook-ID/><EMAILS><EMail><Type>gmail</Type><Value>akkireddych@gmail.com</Value></EMail></EMAILS></CONTACT><CONTACT><PDE-Identity>N65583</PDE-Identity><FirstName>SandfordFrankie</FirstName><LastName>Frankie Sandford</LastName><URL>http://www.facebook.com/FrankieSandfordApprovedPage</URL><Facebook-ID/><EMAILS/></CONTACT><CONTACT><PDE-Identity>N65590</PDE-Identity><FirstName>TheSatsRochelle</FirstName><LastName>Rochelle TheSats</LastName><URL>http://www.facebook.com/profile.php?id=100002487211054</URL><Facebook-ID>100002487211054</Facebook-ID><EMAILS/></CONTACT><CONTACT><PDE-Identity>N65597</PDE-Identity><FirstName>KumarVeera</FirstName><LastName>Veera_Kumar</LastName><Facebook-ID/><EMAILS><EMail><Type>yahoo</Type><Value>KUMARg_81@yahoo.com</Value></EMail><EMail><Type>gmail</Type><Value>KUMARg_81@gmail.com</Value></EMail></EMAILS></CONTACT></CONTACTS> :I have problem in parsing the email values using XMLHttpRequest in xul javascript. I want to change the format of the xml file and it would be easy to parse the xml file in xul. Please help me... i would like to have the output like this: <?xml version="1.0" encoding="UTF-8"?><CONTACTS><CONTACT><PDE-Identity>N65539</PDE-Identity><FirstName>Arun_niit</FirstName><LastName>Arun_niit</LastName><Facebook-ID/><Emails><Email Type="yahoo" Value="nura_ice@yahoo.co.in"/></Emails></CONTACT><CONTACT><PDE-Identity>N65546</PDE-Identity><FirstName>FodenBen'</FirstName><LastName>Ben' Foden</LastName><URL>http://www.facebook.com/profile.php?id=100002440474277</URL><Facebook-ID>100002440474277</Facebook-ID><EMAILS/></CONTACT><CONTACT><PDE-Identity>N65553</PDE-Identity><FirstName>GhorbelMahmoud</FirstName><LastName>Mahmoud Ghorbel</LastName><Facebook-ID/><Emails><Email Type="alcatel-lucent" Value="mahmoud.ghorbel@alcatel-lucent.com"/></Emails><CONTACT><PDE-Identity>N65567</PDE-Identity><FirstName>Rangarajkarthik</FirstName><LastName>karthik Rangaraj</LastName><Facebook-ID/><Emails><Email Type="gmail" Value="kart2006@gmail.com"/><Email Type="yahoo" Value="karthikrangaraj@yahoo.com"/></Emails></CONTACT></CONTACTS> Thank you very much.Is it the right way of doing it: <Emails> <xsl:apply-templates select="EMail"/> <Emails> <xsl:template match="EMail"> <EMail Type="<xsl:value-of select="substring-before(substring-after(.,'@'), '.')"/>" Value="<xsl:value-of select="."/>"/> </xsl:template> Link to comment Share on other sites More sharing options...
Martin Honnen Posted July 1, 2011 Share Posted July 1, 2011 The right way is using attribute value templates <EMail Type="{substring-before(substring-after(.,'@'), '.')}" Value="{.}"/> Link to comment Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.