[xsl] transformNode() and innerHTML combo fail to update browser

Subject: [xsl] transformNode() and innerHTML combo fail to update browser
From: "Dale Gillard" <dalegillard@xxxxxxxxxxx>
Date: Mon, 22 Dec 2003 16:01:13 +1000

Please be kind - this is my first post. I have created a HTML page
containing a XML/XSLT document that sorts a list of staff. This works
fine until I use Javascript to change the xsl:sort select attribute. The
transformNode generates the new HTML but it is not inserted into the web
page via the innerHTML method. I suspect the transformNode method is not
generating valid HTML and the browser is therefore failing to update the
web page, knowing it will fail. However, I'd appreciate your expert
comments before resorting to a workaround (ie creating separate XSLT
files for each sort my users may want to do).

The organisation I work for limits our staff to using MS IE 5.5. Chris
Bayes web page tells me I'm using MSXML2 v3.0 in Replace mode.

Cut down versions of the .xml, .xsl and .js files I'm using appear below.
My apologies for the length of this post.

These files show an XSL document that styles the XML document to be a 4
column HTML table. This combination displays and sorts as expected. But
clicking two of the column headings invokes a "sortWithValue()"
javascript method from a linked "xsl.js" file. By adding alert()s to
various points in this script I can see it correctly finds the @select
attribute, changes it, and transforms the XML document using the XSL
file. However, the HTML the XSL file generates via transformNode() seems
to be missing tags like a starting <td> tag. And the generated HTML does
not appear in the <div> as I'd expect.

Thanks in advance for your help.

Dale Gillard
file listing - aro.xml 
<?xml version="1.0"?>
<?xml-stylesheet type="text/xsl" href="aro.xsl"?> 
  <name> <first>Dale</first> <last>Gillard</last> </name>
  <area>Pacific Central</area>
  <location>Coffs Harbour</location>
    <office> <name>Area North Australia</name> <code></code> </office>

file listing - xsl.js
function sortWithValue(aSortValue) 
  theXMLDoc = document.XMLDocument;
  theXSLDoc = document.XSLDocument;
  var node = theXSLDoc.selectSingleNode( "//xsl:sort/@select" );
  node.nodeValue = aSortValue;
  var html = theXMLDoc.documentElement.transformNode(theXSLDoc)
  // The following line fails to update the document, 
  // even though alert() methods show transformNode() returned the
  expected HTML.
  aroListing.innerHTML = html;

file listing - aro.xsl
<?xml version="1.0"?> 
<xsl:stylesheet version="1.0"
<xsl:output method="html" />
<xsl:template match="/">
<title>ARONET - ARO Contacts</title>
<link rel="stylesheet" href="/stylesheets/corp.css" />
<script type="text/javascript" src="/stylesheets/keystroke.js"></script>
<!-- The externally linked Javascript file used to change the XSLT
sort/@select attribute. -->
<script type="text/javascript" src="../javascript/xsl.js"></script>
<table summary="Page Body" cellspacing="0" cellpadding="0" width="100%"
<td valign="top"><a name="body"></a>
<h1 title="Authorised Review Officer Contacts">ARO Contacts</h1>
<table width="95%" border="0" align="center" cellpadding="5"
<td class="euc40">
<div id="areaCell" style="cursor:hand" onClick="sortWithValue('area')">
<td class="euc40">
<div id="nameCell" style="cursor:hand"
<td class="euc40"><strong>Location</strong></td>
<td class="euc40"><strong>Does reviews for</strong></td>
<!-- The following div is referenced by the Javascript. -->
<div id="aroListing">
  <xsl:apply-templates />
<xsl:template match="arolist">
  <xsl:apply-templates select="aro">
    <xsl:sort select="area" order="ascending"/>

<xsl:template match="aro">
  <xsl:apply-templates select="area"/>
  <xsl:apply-templates select="name"/>
  <td valign="top" class="euc20" style="white-space:nowrap"><xsl:value-of
  <xsl:apply-templates select="offices"/>

<xsl:template match="area">
  <td valign="top" class="euc20" style="white-space:nowrap">
  <xsl:value-of select="."/><br />
  <xsl:apply-templates select="../areaGroup"/>

<xsl:template match="areaGroup">
  <div style="font:0.75em;color:gray" title="Area Group or Cluster.">
  <xsl:value-of select="."/>

<xsl:template match="name">
  <td valign="top" class="euc20" style="white-space:nowrap">
  <a title="Link to Centrelink Phone Book entry.">
  <xsl:attribute name="href">
    <xsl:value-of select="../phBookURL"/>
  <xsl:value-of select="."/>

<xsl:template match="offices">
  <td valign="top" class="euc20">
  <xsl:for-each select="office">
    <xsl:sort select="name" order="ascending"/>
    <xsl:value-of select="name"/>
    <xsl:if test="string(code)">
      (<xsl:value-of select="code"/>)<br/>

  Dale Gillard

http://www.fastmail.fm - Consolidate POP email and Hotmail in one place

 XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list

Current Thread