RE: [xsl] Load XSL dynamically

Subject: RE: [xsl] Load XSL dynamically
From: Maria Amuchastegui <mamuchastegui@xxxxxxxxxxx>
Date: Wed, 13 Apr 2005 09:17:24 -0400
I'm not sure if this is what you had in mind. The following HTML file
contains links to two external XSL stylesheets, each of which provides a
different view of the same data:

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<script language="JavaScript">
function transformIsland(xmlIsland,xslFile) {

     if (document.implementation && document.implementation.createDocument)
// Netscape
          {
          var xsltProcessor = new XSLTProcessor();

          // Load the xsl file using synchronous XMLHttpRequest
          var myXMLHTTPRequest = new XMLHttpRequest();
          myXMLHTTPRequest.open("GET", xslFile, false);
          myXMLHTTPRequest.send(null);
          var xslRef = myXMLHTTPRequest.responseXML;
          xsltProcessor.importStylesheet(xslRef);

          // create a new XML document in memory
          var xmlRef = document.implementation.createDocument("", "", null);
          var myNode = document.getElementById(xmlIsland);
          var clonedNode = xmlRef.importNode(myNode.childNodes.item(1),
true);
          xmlRef.appendChild(clonedNode);

          // do the transform
          var fragment = xsltProcessor.transformToFragment(xmlRef,
document);
          var divNode=document.getElementById("divResults");
          divNode.innerHTML="";
          divNode.appendChild(fragment);

          }
     else if (window.ActiveXObject) // Internet Explorer
          {
          xslRef = new ActiveXObject("Microsoft.XMLDOM");
          xslRef.load(xslFile);
          var xmlRef = document.getElementById(xmlIsland);
          divResults.innerHTML = xmlRef.transformNode(xslRef);

          }
     else
          {
          alert('Your browser can\'t handle this script'); // unsupported
browser
          }

}
</script>
</head>
<body>

<a href="javascript:transformIsland('XMLData','xslStyle1.xsl');">View
1</a><br>
<a href="javascript:transformIsland('XMLData','xslStyle2.xsl');">View
2</a><br>
<br><br>
<div id="divResults">
</div>

<xml id="XMLData" style="display:none;">
<catalog>
     <cd>
          <header>Empire Burlesque</header>
          <artist>Bob Dylan</artist>
          <country>USA</country>
          <company>Columbia</company>
          <price>10.90</price>
          <year>1985</year>
     </cd>
     <cd>
          <header>Hide your heart</header>
          <artist>Bonnie Tyler</artist>
          <country>UK</country>
          <company>CBS Records</company>
          <price>9.90</price>
          <year>1988</year>
     </cd>
     <cd>
          <header>Greatest Hits</header>
          <artist>Rod Stewart</artist>
          <country>USA</country>
          <company>RCA</company>
          <price>9.90</price>
          <year>1982</year>
     </cd>
</catalog>

</xml>

</body>
</html>

-----Original Message-----
From: Camalesn [mailto:noelamac@xxxxxxxxx]
Sent: Wednesday, April 13, 2005 7:26 AM
To: XSL list
Subject: [xsl] Load XSL dynamically

Hello,

I'm not sure about how to achieve this or even if it's an XSL related
question:

I have one XML file (sample):

-<book>
--<section>
----<chapter>Chapter 1</chapter>
----<notes>Some notes on this chapter</notes> --</section> --<section>
----<chapter>Chapter 2</chapter> ----<notes>Some notes on this
chapter</notes> --</section> --<section> ----<chapter>Chapter 3</chapter>
----<notes>Some notes on this chapter</notes> --</section> -</book>

As <notes> are very long (some of them cannot be printed on standard
sheet) I would like to make a link in order to render the content of this
node in a new XHTML page. For example:

Section 1 (<a href="#">see notes</a>)
Chapter  1 (...)

Section 2 (<a href="#">see notes</a>)
Chapter  2 (...)

Is it possible? How could this be done? How can I store the node value in a
param and then get its content to display in a new transformation? Can I
dynamically perform another transform with a new XSL file on the same XML?

Greetings.

Current Thread