?
Solved

xslt with xsl:include crashes IE6 browser

Posted on 2003-03-01
9
Medium Priority
?
733 Views
Last Modified: 2013-11-18
I am having a problem trying to embed an xsl:stylesheet in an XML data island and then use transformnode to render the page.  The problem seems to be with the xsl:include statement.  If I put the stylesheet into a separate file and use <XML ... src="file.xstl" > it works.  If I embed the xsl:stylesheet in the <XML> tag on the html page, the browser (IE6) crashes when I launch the page from the local file system.  If I use a relative url for the xsl:include, the browser says "The system cannot locate the object specified".  If I use an absolute url (like the example below), the browser crashes when I launch the html file.  I've also tried launching the html file from tomcat using both relative and absolute urls for the included xslt file.  If I comment out the xsl:include and put the TestFrame template directly into the embedded stylesheet, it works.  I really need to use xsl:include because my application is much bigger than this test sample.

I've seen posts that talk about using a fully-qualified URL on the xsl:include.  I haven't been able to get it working using file://..., but this seems to defeat the purpose of having reusable, modular xslt files.

I am attaching the html file that contains the main stylesheet and the included xslt file below.  I appreciate any help.  
Joe Meree

*** this is the contents of the file testInclude2a.htm
<html>
<head>
     <title>Frame</title>    
     <SCRIPT type="text/javascript">
          function myTransform()
          {  myTarget.innerHTML = myFrame.transformNode(myStyle.XMLDocument);  }
     </SCRIPT>

</head>
     <body onload="myTransform()" >
          <DIV id="myTarget"> </DIV>
     </body>
</html>

<XML id="myFrame" >
     <TestFrame id="1" title="Got to TestFrame template">
     </TestFrame>
</XML>

<!-- XML id="myStyle" src="testInclude2a.xslt"  -->
<XML id="myStyle" >
     <xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0" xmlns:data="DataFrame.dtd" exclude-result-prefixes="data">
          <data:DataFrame id="1" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
               <data:DataContent id="3"/>
               <data:Environment>
                    <data:EnvItem name="item1" value="item1Value"/>
                    <data:EnvItem name="item2" value="item2Value"/>
               </data:Environment>
          </data:DataFrame>
          <xsl:include href="E:\mydocs\testInclude2b.xslt"/>
          <xsl:variable name="dataRoot" select="document('')/xsl:stylesheet/data:DataFrame/data:Environment"/>
          <xsl:template match="/">
               dataRoot/item2/name=<xsl:value-of select="$dataRoot/data:EnvItem[2]/@name"/><br/>
               <xsl:apply-templates select="TestFrame"  />
          </xsl:template>
     </xsl:stylesheet>
</XML>

*** The following text is in the file testInclude2b.xslt which is in the same directory as testInclude2a.htm
<?xml version="1.0"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0" xmlns:data="DataFrame.dtd" >
     <xsl:template match="TestFrame">
          <xsl:param name="data"/>
          Frame title:<xsl:value-of select="@title"/><br/>
          dataRoot/item1/value=<xsl:value-of select="$dataRoot/data:EnvItem[1]/@value"/><br/>
     </xsl:template>
</xsl:stylesheet>
0
Comment
Question by:jmeree
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 5
  • 3
9 Comments
 
LVL 27

Expert Comment

by:BigRat
ID: 8056853
I see no problem why one should not use xsl:include, but I'm not happy with data islands.

I personally would have created two MS XML DOM variables and loaded relative URLs into them like :-

var xmlSource,xslSource;

xmlSource = new ActiveXObject("Microsoft.XMLDOM")
xmlSouce.async = false;
xmlSouce.load(file.xml);

xslSource = new ActiveXObject("Microsoft.XMLDOM")
xslSource.async = false;
xslSource.load(file.xsl);

and then everything else is before. The problem might be related to finding the base URL of the XSL for the include.

PS: You might have to change the ActiveX name to get the lastest features of XSL.
0
 
LVL 1

Author Comment

by:jmeree
ID: 8058430
Thanks for the response.  I've seen this way of doing it, but I'm trying to pass data from the web server to the client on the page and not in a separate file.  Data Islands are a good way of doing it, but it seems like there are some flakey thinks going on.  Could you elaborate a bit on "finding the base URL...".  
0
 
LVL 27

Expert Comment

by:BigRat
ID: 8063812
When referencing a jpeg, gif or some other file from an HTML page only by filename (eg: scripts.js) we have to construct an absolute URL (ie: protocol,host,path like http://www.someone.org/url/scripts.js) and for this purpose we need a base URL, which equals the URL used to load the page less the "file bit". In your case I'd leave the URI on the include relative, ie: just testInclude2b.xslt

There are also problems of accessing local filestore from the browser, changing the page to .hta might help out, but I suppose in real operation it will all come from the server, so relative URLs are better.

One minor point is that xsl:include MUST be a direct child of the stylesheet element, and in this respect I don't quite understand what the <data:DataFrame/> is doing there?

0
Why Off-Site Backups Are The Only Way To Go

You are probably backing up your data—but how and where? Ransomware is on the rise and there are variants that specifically target backups. Read on to discover why off-site is the way to go.

 
LVL 1

Author Comment

by:jmeree
ID: 8066753
I'm familiar with the issues in your UML discussion.  The problem is that IE crashes when the relative URL is in an xsl:include statement in a data island (if the relative URL is in "file.xslt", ( <xml id="xx" src="file.xslt"> ), it works...  THIS IS THE PROBLEM.  

I'm using the data island to pass the data needed to render the page.  The code is sort of complex, and I'm using the "xml" island for something else, so I'm passing the data into the "xsl" island as a namespace and using document('') to access it.

Have you tried to run my code?
Joe
0
 
LVL 1

Author Comment

by:jmeree
ID: 8070713
This ends up being a bug or shortcoming in MS xsl processor.  I've reworked my code to remove the xsl code from the MS data island, put my data into a data island by itself and used the document() function.  This is working better.  Lesson1: Microsoft IE6 doesn't seem to handle mixing data and xml in the xsl island when using transformnode.   Lesson 2: There is a bug in the xml spy 5.0 xsl processor.  My new solution is to apply-templates to a document(file).  The xml spy debugger would transform the first node and then crash.  I spent a day trying to get it to work thinking to myself the whole time "... what am I doing wrong? ...".  The 5.3 release fixed the bug.  (I'm actually very happy with xml spy).
Joe
0
 
LVL 27

Expert Comment

by:BigRat
ID: 8071280
"Have you tried to run my code?"

Yes, I get a crash on

<xsl:include href="c:\test\testInclude2b.xslt"/>

and a script error (system cannot find object) with

<xsl:include href="testInclude2b.xslt"/>


The crash offered to send MS a bug report, so I did. I tested it with .hta and got the same so it is not a security issue.

I'm glad you've solved the problem. Making the html reference a separate xsl file is better. I don't use XML Spy, but what a lot of hassle you've had!




0
 

Accepted Solution

by:
modulo earned 0 total points
ID: 8225313
PAQ'd and 250 points refunded

modulo

Community Support Moderator
Experts Exchange
0
 
LVL 1

Author Comment

by:jmeree
ID: 8418961
The real problem here was trying to use a form button that called transformNode().  It seems that the visual "pressing" action that the button makes interferes with the transformation.  I changed to a link (which doesn't do anything when it's clicked and it works fine now).
0
 
LVL 1

Author Comment

by:jmeree
ID: 8418972
Sorry, wrong problem.  I fixes this one by restructuring my code so there were no xsl:include or xsl:import statements in the html file.  They work ok when they are inside an xslt file...
0

Featured Post

Interactive Way of Training for the AWS CSA Exam

An interactive way of learning that will help you visualize core concepts so that you can be more effective when taking your AWS certification exam.  Built for students by a student to help them understand the concepts that they are being taught.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction Knockoutjs (Knockout) is a JavaScript framework (Model View ViewModel or MVVM framework).   The main ideology behind Knockout is to control from JavaScript how a page looks whilst creating an engaging user experience in the least …
Styling your websites can become very complex. Here I'll show how SASS can help you better organize, maintain and reuse your CSS code.
Viewers will learn about if statements in Java and their use The if statement: The condition required to create an if statement: Variations of if statements: An example using if statements:
The viewer will the learn the benefit of plain text editors and code an HTML5 based template for use in further tutorials.
Suggested Courses

777 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question