xsl-list
[Top] [All Lists]

Accessing embedded XSL islands in Netscape

2004-09-15 06:57:32
I am trying to create a single HTML file with an embedded XML island and two
embedded XSL stylesheets. The user would then be able to switch between
different views of the same data. This works well in IE, but I am having
trouble properly loading the XSL in Netscape. I know that the XML data is
being properly loaded because the code works in another context. It is the
embedded XSL that is not working in Netscape. How can I access the XSL in
Netscape?

Maria

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

if (document.implementation && document.implementation.createDocument) //
Netscape
        {
        var xsltProcessor = new XSLTProcessor();
        
        // create a new XSL document in memory

        var xslRef = document.implementation.createDocument("", "", null);
        var xslNode = document.getElementById(xslIland);
        var xslClonedNode = xslRef.importNode(xslNode.childNodes.item(0),
true);        
        xslRef.appendChild(xslClonedNode);                
        
        xsltProcessor.importStylesheet(xslRef);
        
        // create a new XML document in memory
        var xmlRef = document.implementation.createDocument("", "", null);
        var xmlNode = document.getElementById(xmlIsland);
        var xmlClonedNode = xmlRef.importNode(xmlNode.childNodes.item(1),
true);          
        xmlRef.appendChild(xmlClonedNode);         
        
        // 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
        {
        var xslRef = document.getElementById(xslIland);           
        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');">View 1</a><br>
<a href="javascript:transformIsland('XMLData','xslStyle2');">View 2</a><br>
<br><br>
<div id="divResults">
</div>

<xml id="XMLData" style="visibility:hidden;">
<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>Dolly Parton</artist>
          <country>USA</country>
          <company>RCA</company>
          <price>9.90</price>
          <year>1982</year>
     </cd>
</catalog>
</xml>

<div style="visibility:hidden;">
<xml id="xslStyle1">
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform";>
<xsl:template match="/">
  <html>
  <body>
  <h2>My CD Collection</h2>
    <table border="1">
      <tr bgcolor="#9acd32">
        <th align="left">Title</th>
        <th align="left">Price</th>
      </tr>
      <xsl:for-each select="catalog/cd">
      <tr>
        <td><xsl:value-of select="header"/></td>
        <td><xsl:value-of select="price"/></td>
      </tr>
      </xsl:for-each>
    </table>
  </body>
  </html>
</xsl:template>
</xsl:stylesheet>
</xml>
</div>

<div style="visibility:hidden;">
<xml id="xslStyle2">
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform";>
<xsl:template match="/">
  <html>
  <body>
  <h2>My CD Collection</h2>
    <table border="1">
      <tr bgcolor="#9acd32">
        <th align="left">Title</th>
        <th align="left">Artist</th>
      </tr>
      <xsl:for-each select="catalog/cd">
      <tr>
        <td><xsl:value-of select="header"/></td>
        <td><xsl:value-of select="artist"/></td>
      </tr>
      </xsl:for-each>
    </table>
  </body>
  </html>
</xsl:template>
</xsl:stylesheet>
</xml>
</div>

</body>
</html>


<Prev in Thread] Current Thread [Next in Thread>