its seems easy but for me i found it difficult.........
i want to do transformation usig xsl and xml(adding parameter).
for IE its working fine but for other browser like-firefox,opera its not working.........
i m giving u my complete xml,xsl and transformation code....u only paste and check why it is not working for other browser.....and correct it and let me know......this is really a big challenege for us.....
what my openion:- the way we are adding parameter is going wrong..........
//emp.xml
Expand|Select|Wrap|Line Numbers
- <?xml version="1.0"?>
- <?xml-stylesheet type='text/xsl' href='emp.xsl'?>
- <employee>
- <employee1>
- <first>Abhimanyu</first>
- <last>Singh</last>
- <sex>male</sex>
- <dob>5Aug1983</dob>
- <lang>Hindi</lang>
- </employee1>
- <employee1>
- <first>Abhishek</first>
- <last>Tyagi</last>
- <sex>male</sex>
- <dob>1Sep1983</dob>
- <lang>English</lang>
- </employee1>
- <employee1>
- <first>Ajay</first>
- <last>Gupta</last>
- <sex>male</sex>
- <dob>4Nov1983</dob>
- <lang>marathi</lang>
- </employee1>
- <employee1>
- <first>Mukund</first>
- <last>Gupta</last>
- <sex>male</sex>
- <dob>3Mar1981</dob>
- <lang>english</lang>
- </employee1>
- </employee>
emp.xsl
Expand|Select|Wrap|Line Numbers
- <?
- xml version=" 1.0"?>
- <
- xsl:stylesheet version=" 1.0" xmlns:xsl=" http://www.w3.org/1999/XSL/Transform"
- xmlns:PC="urn:PointCross-GenericFunctions" >
- <
- xsl:output method=" html"/>
- <
- xsl:param name=" Title" />
- <
- xsl:template match=" /">
- <
- html>
- <
- body>
- <
- h1>
- <
- xsl:value-of select=" $Title"/>
- </
- h1>
- <
- table border=" 1">
- <
- tr bgcolor=" #cccccc">
- <
- th align=" left">
- <
- xsl:value-of select=" PC:ColumnTitle(1)"/>
- </
- th>
- <
- th align=" left">
- <
- xsl:value-of select=" PC:ColumnTitle(2)"/>
- </
- th>
- <
- th align=" left"><xsl:value-of select ="PC:ColumnTitle(3)"/>
- </
- th>
- <
- th align=" left"><xsl:value-of select ="PC:ColumnTitle(4)"/>
- </
- th>
- <
- th align=" left"><xsl:value-of select ="PC:ColumnTitle(5)"/>
- </
- th>
- </
- tr>
- <
- xsl:for-each select=" employee/employee1">
- <
- tr>
- <
- td><xsl:value-of select="first"/></ td>
- <
- td><xsl:value-of select="last"/></ td>
- <
- td><xsl:value-of select="sex"/></ td>
- <
- td><xsl:value-of select="dob"/></ td>
- <
- td><xsl:value-of select="lang"/></ td>
- </
- tr>
- </
- xsl:for-each>
- </
- table>
- </
- body>
- </
- html>
- </
- xsl:template>
- </
- xsl:stylesheet>
emp.html
Expand|Select|Wrap|Line Numbers
- <html>
- <head >
- <script type="text/javascript">
Expand|Select|Wrap|Line Numbers
- function OrchGeneric(){
- this.ColumnTitle=_ColumnTitle;
- }
- function _ColumnTitle(Col){
- var rtn="";
- switch (Col){
- case 1:
- rtn="First Name";
- break;
- case 2:
- rtn="Last name";
- break;
- case 3:
- rtn="Sex";
- break;
- case 4:
- rtn="DOB"
- break;
- default:
- rtn="Lang";
- }
- return rtn;
- }
- var Orch=new OrchGeneric();
- function loadXML()
- {
- // code for IE
- if(window.ActiveXObject)
- {
- try{
- var ClientXML = new ActiveXObject("Msxml2.FreeThreadedDOMDocument")
- ClientXML.async = false
- ClientXML.load("emp.xml")
- var ClientXSL = new ActiveXObject(" Msxml2.FreeThreadedDOMDocument")
- ClientXSL.async = false
- ClientXSL.load("emp.xsl")
- var xslTemplate=new ActiveXObject("Msxml2.XSLTemplate")
- xslTemplate.stylesheet=ClientXSL
- var xslProcessor=xslTemplate.createProcessor
- xslProcessor.input=ClientXML ;
- xslProcessor.addObject(Orch, "urn:PointCross-GenericFunctions" );
- xslProcessor.addParameter ("Title", "Employee Record");
- xslProcessor.transform();
- document.write(xslProcessor.output);
- //alert(xslProcessor.output);
- }catch(e){alert(e)}
- }
- // code for Mozilla, etc.
- else if(document.implementation && document.implementation.createDocument)
- {
- try{
- var xslStylesheet;
- var myDOM;
- var xmlDoc;
- var xsltProcessor = new XSLTProcessor();
- // load the xslt file, example1.xsl
- var myXMLHTTPRequest = new XMLHttpRequest();
- myXMLHTTPRequest.open("GET","emp.xsl", false);
- myXMLHTTPRequest.send(null);
- xslStylesheet = myXMLHTTPRequest.responseXML;
- xsltProcessor.importStylesheet(xslStylesheet);
- // load the xml file, example1.xml
- myXMLHTTPRequest = new XMLHttpRequest();
- myXMLHTTPRequest.open("GET","emp.xml", false);
- myXMLHTTPRequest.send(null);
- xmlDoc = myXMLHTTPRequest.responseXML;
- xsltProcessor.setParameter("urn:PointCross-GenericFunctions","Title","");
- var ownerDocument=document.implementation.createDocument("", "test", null);
- var newFragment=xsltProcessor.transformToFragment(xmlDoc,document);
- document.body.appendChild( newFragment);
- }catch(e){alert(e)}
- }
- else
- {
- alert("your browser cannot handle this script");
- }
- }
Expand|Select|Wrap|Line Numbers
- </script>
- </head>
- <body onload="loadXML()" >
- </body>
- </html>
please let me know if u encoumnter any issue....................
thanx and regards,
Abhimanyu Singh