Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 523
  • Last Modified:

Insert an "XML-XSLT block" into a web page ?

Hi all.
I'm newbie to XML, I've just get acquainted with XML cause it gave me to a convinient way displaying data from my web to client : combination of XML & XSL.
I wonder how I can save some "xml-xsl couple of file" as a block and then embed them in my web page.  Something like :

<html>
<body>

This is all our products :

<xml src="Product_Block.xml" id="Product_Part"></xml>

Go to home page >>

</body>
</html>

Could you give me some features of XML that lead to what I'm looking for ?
Thanks for all suggestions !
<html>
<body>
 
This is all our products :
 
<xml src="Product_Block.xml" id="Product_Part"></xml>
 
Go to home page >>
 
</body>
</html>

Open in new window

0
gadapchetvoi
Asked:
gadapchetvoi
  • 2
1 Solution
 
Geert BormansCommented:
You can embed your XML and XSLT using JavaScript.
Here is a Internet Explorer only solution.
If you download Sarissa library, you can make this work for all browsers

First try this and see if it comes close to what you need


<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
	"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
	
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>Select Transform</title>
    <script language="javascript">
      function transF()
      {
         var oXML = new ActiveXObject("Msxml2.DOMDocument");
         var oXSL = new ActiveXObject("Msxml2.FreeThreadedDOMDocument");
         var oTmpl= new ActiveXObject("Msxml2.XSLTemplate");
         var oProc ;
 
	       oXML.async = false;
         oXML.resolveExternals = false;
	       oXML.load("your_xml.xml"); 
	       
         oXSL.async = false;
         oXSL.resolveExternals = false;
         oXSL.load("your_xsl.xsl");
 
         oTmpl.stylesheet = oXSL;
 
         oProc = oTmpl.createProcessor();
         oProc.input = oXML;
				 oProc.transform();
         var resHTM = oProc.output;
         document.getElementById("prod-block").innerHTML = resHTM;
      }
    </script>
</head>
 
<body onload="transF();">
This is all our products :
 
<div id="prod-block"></div>
 
Go to home page >>
 
</body>
</html>

Open in new window

0
 
gadapchetvoiAuthor Commented:

Thanks Gertone.

So, your solution is to use some Javascript & innerHTML attribute. Could I know why you said that it works for IE only ?  Other browser doesn't support XML-XSLT or the way you pull data from XML & apply XSLT templates works with IE only ?
BTW, you gave me the example XSL file but the XML?
0
 
Geert BormansCommented:
- Yes, the solution is to use JavaScript to pull in the XML and XSL and execute the transform. Replace the innerhtml of the empty div with the transform result
- This is IE only because of the way the XML and XSL objects are created. Sarissa is a JavaScript library that takes away the browser dependency. Most browsers support XSLT
- What I gave is the html page that drives all this. You need to reference your own XML and XSLT
0

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now