[XSL-LIST Mailing List Archive Home] [By Thread] [By Date] [Recent Entries] [Reply To This Message]

Accessing embedded XSL islands in Netscape

Subject: Accessing embedded XSL islands in Netscape
From: Maria Amuchastegui <mamuchastegui@xxxxxxxxxxx>
Date: Wed, 15 Sep 2004 09:57:32 -0400
xml island netscape
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>

Current Thread

PURCHASE STYLUS STUDIO ONLINE TODAY!

Purchasing Stylus Studio from our online shop is Easy, Secure and Value Priced!

Buy Stylus Studio Now

Download The World's Best XML IDE!

Accelerate XML development with our award-winning XML IDE - Download a free trial today!

Don't miss another message! Subscribe to this list today.
Email
First Name
Last Name
Company
Subscribe in XML format
RSS 2.0
Atom 0.3
Site Map | Privacy Policy | Terms of Use | Trademarks
Free Stylus Studio XML Training:
W3C Member
Stylus Studio® and DataDirect XQuery ™are products from DataDirect Technologies, is a registered trademark of Progress Software Corporation, in the U.S. and other countries. © 2004-2013 All Rights Reserved.