Wrox Programmer Forums
Go Back   Wrox Programmer Forums > XML > XSLT
|
XSLT General questions and answers about XSLT. For issues strictly specific to the book XSLT 1.1 Programmers Reference, please post to that forum instead.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the XSLT section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old March 16th, 2004, 05:14 PM
Registered User
 
Join Date: Mar 2004
Posts: 4
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via MSN to lynchnco
Default do xsl file have to be loaded on server?

Good afternoon,

I have an xsl (XSLT) file with an associated xml file. When I view them, using the xsl editor xselerator, the created html is displayed properly on my IE 6.0 browser.

However, if I open the xsl file, using the IE 6.0 browser directly, the xml code in the xsl file is displayed only (the generated html is not).

Do I have to store the xsl file on the server in order for it to work directly from the browser?

I'm very confused.

Thanks,
Pat

Pat
 
Old March 17th, 2004, 06:11 AM
joefawcett's Avatar
Wrox Author
 
Join Date: Jun 2003
Posts: 3,074
Thanks: 1
Thanked 38 Times in 37 Posts
Default

You have three options if you wish to do client side transformations, let's assume your files are called source.xml and style.xsl and are in the same folder:
* You can have an XML file with an associated XSLT file. You need to add the following processing instruction to the xml file
Code:
<?xml-stylesheet type="text/xsl" href="style.xsl" ?>
just after the prologue if there is one or as the top line.
* You can use client side script to load the two files into instances of the Dom (Msxml2.DomDocument.3.0 or Msxml2.DomDocument.4.0 would be best, below this transforms are unreliable) and transform. A simple web page for testing is here:
Code:
<html>
<head>
<title>Simple Transformer</title>

<script type="text/javascript">

var oSource = null;
var oStyle = null;

function showParseError(Err, Path)
{
  var sError = "An error occurred loading '" + Path + "'"
             + "\nReason: " + Err.reason
             + "\nLine: " + Err.line
             + "\nsource: " + Err.srcText;
  alert(sError);
}

function getDomDoc()
{
  var oDom =  new ActiveXObject("Msxml2.DomDocument.4.0");
  /* If you have version 3 only use these line instead:
  var oDom =  new ActiveXObject("Msxml2.DomDocument.3.0");
  oDom.setProperty("SelectionLanguage", "XPath");*/
  oDom.async = false;
  return oDom
}

function getTransform(XmlFile, XslFile)
{
  var bLoaded = oSource.load(XmlFile);
  if (!bLoaded)
  {
    showParseError(oSource.parseError, XmlFile);
    return null;
  }
  bLoaded = oStyle.load(XslFile);
  if (!bLoaded)
  {
    showParseError(oStyle.parseError, XslFile);
    return null;   
  }
  return oSource.transformNode(oStyle);
}

function doTransform(Output)
{
  var sXmlPath = document.getElementById("txtSource").value;
  var sXslPath = document.getElementById("txtStyle").value;
  var sOutput = getTransform(sXmlPath, sXslPath);
  if (sOutput == null)
  {
    return;    
  }
  var oOutput; 
  if (Output == "textarea")
  {
    oOutput = document.getElementById("txtOutput");
    oOutput.value = sOutput;
  }
  else
  {
    oOutput = window.frames["fraOutput"].document;
    oOutput.open();
    oOutput.write(sOutput);
    oOutput.close();
  }
}

function init()
{
  oSource = getDomDoc();
  oStyle = oSource.cloneNode(false);
}
</script>
</head>

<body bgcolor="#FFFFFF" onload="init();">
<table border="0" width="80%" align="center">
<tr>
<td>Xml file:<input type="file" id="txtSource" size="40"></td>
<td>Xsl file:<input type="file" id="txtStyle" size="40"></td>
</tr>
<tr>
<td align="center"><input type="button" onclick="doTransform('frame');" value="Transform to Frame"></td>
<td align="center"><input type="button" onclick="doTransform('textarea');" value="Transform to Textarea"></td>
</tr>
<tr>
<td>&nbsp;</td>
<td>&nbsp;</td>
</tr>
<tr>
<td><iframe width="400px" height="480px" name="fraOutput"></iframe></td>
<td><textarea cols="50" rows="30" id="txtOutput"></textarea></td>
</tr>
</body>
</html>
* You can use xml data islands for a similar effect.

Joe (MVP - xml)
 
Old March 17th, 2004, 12:20 PM
Registered User
 
Join Date: Mar 2004
Posts: 4
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via MSN to lynchnco
Default

Good morning,
Problem solved...
Thank you,
Pat

Pat





Similar Threads
Thread Thread Starter Forum Replies Last Post
Need help with xsl file creation WBIRZD XSLT 2 February 23rd, 2007 06:05 PM
problems with determnining when a file has loaded Stevie Flash (all versions) 0 June 22nd, 2005 05:54 AM
The VB Rules Server could not be loaded sush_blr VB Components 0 December 7th, 2004 05:26 AM
SOS:.dll file couldn't be loaded! LuckyChanceMore BOOK: ASP.NET Website Programming Problem-Design-Solution 0 January 3rd, 2004 02:37 PM
XSL Transform with xsl string NOT xsl file skin XSLT 0 June 16th, 2003 07:30 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.