Developer forum

Forum » Templates » XML in templates

XML in templates


Reply

Hi,

 

I need to call an XML with XSLT to a page template, but I have never done it. Could someone help me?

 

I cannot manipulate the XML, but I have changed the XLST to the client's needs. THey are both in the File Manager though.

 

Best Regards,

Nuno


Replies

 
Nicolai Høeg Pedersen
Reply
nuno wrote:

Hi,

 

I need to call an XML with XSLT to a page template, but I have never done it. Could someone help me?

 

I cannot manipulate the XML, but I have changed the XLST to the client's needs. THey are both in the File Manager though.

 

Best Regards,

Nuno


Not sure what you want to do.

 

Do you want to download a XML file and parse it with a XSLT and display the result as part of the page template?

 

You could take a look at the Content Integrator module - it can do this.

 
Reply

Hi Nicolai,

 

A client has an XML file that is updated every 2 or 3 hours via FTP. The ideia is to use XSLT to transform the data (which is done), and now we just want it to be rendered on a specific place.

 

Is there a basic way to do this, without using the module?

 

Best Regards,

Nuno

 
Nicolai Høeg Pedersen
Reply

Then you probably need to do something like this: http://www.w3schools.com/xsl/xsl_client.asp

 

 
Reply

lol

 

That is precisly the article that made be post this thread. I could not get it to work. I will go back on my steps and try again. Might be a problem with my XSLT.

 

Anyhow, I tried the Content Integration module, but found no option regaing XML and XSLT. Actually we tried the "Integration" module and the "Database Publishing", but neither seemed to strike me as the proper one.

 

Best Regards,

Nuno

 
Reply

I posted a javascript xml/xslt transformation about a year ago in this forum. But unfortunately it seems to be deleted. Anyways, i've lookup the code again and here it is, and u can put it into the html code of a Dynamicweb paragraph:


(replace the XML and XSLT to use in the bottom of this code) *sorry this looks so bad, but couldn't find a nicer way to display the code*

 

<div id="PlaceHolder1">this is replaced by the transformation</div>

<script type="text/javascript" language="javascript">
  function getDomFromFile(filename) {
   // Load XML
   var xml;
   if (typeof ActiveXObject != 'undefined') {// IE
    xml = new ActiveXObject("Microsoft.XMLDOM");
    xml.async = false;
    xml.load(filename);
   }
   else { // others
    var myXMLHTTPRequest = new XMLHttpRequest();
    myXMLHTTPRequest.open("GET", filename, false);
    myXMLHTTPRequest.send(null);
    xml = myXMLHTTPRequest.responseXML;
        
   }
   return xml;
  }
  
  function getDomFromXml(xml) {
   var dom;
   if (typeof ActiveXObject != 'undefined') {
    dom = new ActiveXObject("Microsoft.XMLDOM");
    dom.async = false;
    dom.loadXML(xml);
   }
   else {
    parser = new DOMParser();
    dom = parser.parseFromString(xml, "text/xml");      
   }
   return dom;
  }


  function xslt(xmlDoc,xslDoc) {
   var transform;
   
   if (typeof ActiveXObject != 'undefined') { //IE
    transform = xmlDoc.transformNode(xslDoc);
   }
   else { //mozilla
    var xsl = new XSLTProcessor();
 
    xsl.importStylesheet(xslDoc);

    var fragment=xsl.transformToFragment(xmlDoc, document);
    if( fragment.childNodes.length>0 )
      transform = fragment.childNodes[0].innerHTML;
    else
     return "error during transformation";
   }
   return transform;
  }


   // get the dom of the xml file   
   var xmldoc = getDomFromFile( "/Files/Filer/demo.xml" );
   // get the dom of the xsl file
   var xsldoc = getDomFromFile( "/Files/Filer/demo.xsl" );
   // do the transformation and put response in placeholder
   document.getElementById("PlaceHolder1").innerHTML = xslt(xmldoc, xsldoc);


</script>

 

 
Reply

Hi Emil,

 

Thanks a lot. I actually made it to work just last night, without the http requests, since the files were local. But thanks you. Your code will come in handy in the future, i am sure.

 

Best Regards,

Nuno

 

You must be logged in to post in the forum