views:

192

answers:

2

Can I embed an XML file in HTML without using iFrames? I want to show XSL-transformed XML(which, is HTML as a result of transformation) as a part of my HTML document. Hope this makes it clearer.

If my description of problem is unclear, please tell me and I will try to explain it more.

+1  A: 

You will need to use html entities. For example this is how you would write a name tag <name>.

More reading here

redsquare
Hm... Somehow this answers the question, yet somehow it does not.
Tomalak
well it beats your answer!
redsquare
Somehow, yes. :-D
Tomalak
I don't see an answer from Tomalak... maybe he deleted it.
Cerebrus
@cerebrus - exactly, he didnt attempt to answer!
redsquare
+1  A: 

You can easily use browser based XSL transformation routines to convert an XML string into an XMLDocument or HTML output that can then be applied into any page element.

The steps could be briefly summarized as:

  1. Load an XML string from a resource (or as the result of an AJAX hit).
  2. Load the XML document into an Xml document object (code differs for Browsers - IE uses the ActiveXObject MSXML - DOMDocument, while Mozilla uses the built-in implementation to create a Document. Chrome on the other hand uses the built-in XmlHttpRequest object as the only available XML document object.)
  3. Load the XSL document similarly and set its arguments.
  4. Transform the XML and obtain output as a string.
  5. Apply the string output to any page element.

Note that the code differs for each browser so it may be simpler to use a public JS framework such as JQuery or Prototype.

Cerebrus