tags:

views:

168

answers:

3

Hi, suppose I have xml inside an html document like

<html>
  <body>
     <xml>
        <foo>
          <bar />
          <baz />
        </foo>
     </xml>
   </body>
 </html>

What is the best way to apply xslt to the xml node?

+1  A: 

You could save the file as an XML file with a separate XSL file in the same directory, and then in the XML file, link it to the XSL file:

<?xml version = '1.0'?>
<?xml-stylesheet href="myfunkystyle.xsl" type="text/xsl"?>
<ROWSET>
   <ROW>
      <!-- etc. -->
    </ROW> 
</ROWSET>

Both IE and Firefox will display the XML file by transforming it.

Daniel Earwicker
A: 

Perhaps that we miss some information on your problem:

  • On which side do you want to do this? client or server?
  • Which technology do you use?
Matthieu BROUILLARD
This is more of a comment than an answer. Should have been a comment added to the user's question.
Shadi Almosri
+1  A: 

Emle - Electronic Mathematics Laboratory Equipment Javascript file emle_lab.js uses parseFromString() to create a document from a string:

  var inputText = '<?xml version="1.0" encoding="UTF-8"?>' +
    '<emle xmlns="http://emle.sf.net/emle02"&gt;' +
    '  <lab refid="' + aLabId + '"></lab>' +
    '</emle>';
  var inputDoc = new DOMParser().parseFromString(inputText, "application/xml"); 
  var xsltDoc = jQuery.ajax({type: "GET", url: 'emle_lab.xsl', async: false}).responseXML; 
  var processor = new XSLTProcessor();
  processor.setParameter(null, 'emleLang',  aLang);
  processor.importStylesheet(xsltDoc);
  var outputDoc = processor.transformToDocument(inputDoc.firstChild);
C.W.Holeman II