Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 738
  • Last Modified:

xslt with xsl:include crashes IE6 browser

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
     <SCRIPT type="text/javascript">
          function myTransform()
          {  myTarget.innerHTML = myFrame.transformNode(myStyle.XMLDocument);  }

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

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

<!-- 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:EnvItem name="item1" value="item1Value"/>
                    <data:EnvItem name="item2" value="item2Value"/>
          <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"  />

*** 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/>
  • 5
  • 3
1 Solution
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;

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

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.
jmereeAuthor Commented:
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...".  
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?


Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

jmereeAuthor Commented:
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?
jmereeAuthor Commented:
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).
"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!

PAQ'd and 250 points refunded


Community Support Moderator
Experts Exchange
jmereeAuthor Commented:
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).
jmereeAuthor Commented:
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...

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

  • 5
  • 3
Tackle projects and never again get stuck behind a technical roadblock.
Join Now