XML Programming
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me
Go Back   Dev Shed ForumsProgramming Languages - MoreXML Programming

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Dev Shed Forums Sponsor:
  #1  
Old August 18th, 2004, 12:54 PM
rguilbault rguilbault is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Aug 2004
Posts: 30 rguilbault User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 1 h 15 m 18 sec
Reputation Power: 5
Post Run javascript func after XSLT transformation

Hello. I've been playing around with XSLT and javascript for a couple weeks now and I am looking for anyone's expertise about a little 'issue' I'm having.

I'm trying to load xml documents into a static html page to create a 'frame' effect. Everything I've hashed out so far has worked pretty stabily until my most daring attempt -- load a javascript function to manipulate the page after an XSL transformation.

I've got my main static html file: sample.htm,
an xml data file: LAB.xml
and a stylesheet: mod.xsl

A snippet of the xsl file follows:
PHP Code:
<xsl:template match="instruments">

  <
h2 class='title'>Instruments</h2>

  <
br />
  <
table id='instruments' class='ScrollTable'>
    <
colgroup>
      <
col width="40" />
      <
col width="325" />
      <
col width="70" />
      <
col width="100" />
      <
col width="100" />
      <
col width="149" />
    </
colgroup>

    <
thead>
      <
tr>
        <
th>Bill</th>
        <
th>Instrument</th>
        <
th>Status</th>
        <
th>Delivered</th>
        <
th>LIVE</th>
        <
th>Group</th>
      </
tr>
    </
thead>

    <
tbody>
      <
tr>
        <
td colspan="6">
          <
div class="scroller">
            <
table>
              <
colgroup>
                <
col width="40" />
                <
col width="325" />
                <
col width="70" />
                <
col width="100" />
                <
col width="100" />
                <
col width="150" />
              </
colgroup>

              <
xsl:for-each select="instrument">
              <
tr>
                <
td style='text-align: center'><xsl:value-of select="billable" /></td>
                <
td style='background: #FFFFCC'><xsl:value-of select="@mnemonic" /></td>
                <
td style='text-align: center'><xsl:value-of select="status" /></td>
                <
td class='date' ><xsl:value-of select="dates/delivery" /></td>
                <
td class='date' style='background: #FFCCFF' ><xsl:value-of select="dates/live" /></td>
                <
td><xsl:value-of select="support" /></td>
              </
tr>
              </
xsl:for-each>
            </
table>
          </
div>
        </
td>
      </
tr>
    </
tbody>
  </
table>

  <
style>
    .
scroller height200pxwidth100%; overflowauto; }
  </
style>

  <
script src='ScrollTable.js'></script>
  <script>
    ScrollTable_initialize();
  </script>

</xsl:template> 


I process the XML/XSLT with IE's XML processor or Mozilla's XSLT processor depending on the browser I'm viewing the page in. The XSL files generate HTML chunks, not full HTML files. For example, after a transformation, I'll have something like:

PHP Code:
<div id='page'>
  <
h1>Title Page</h1>
</
div


In the example above, I have a couple <script> tags which are to load and subsequently call a javascript function. In Mozilla, the function is properly called and life is good. In IE, this is not the case.

I've got 2 questions:

1) Is this bad practice to plop a function to run embeded in an element? I tried to add an event to call the function (a much nice approach, granted), but it wasn't working -- because the appending of the transformed elements to the body do not seem to trigger any events I can find.

2) Does anyone know when IE processes scripts? Is it only on a load of a page? This would explain the issue to me.

Any insights? I appreciate it!

P.S. While working on this, I realized it would probably be helpful to offer the code I'm using for the transformations. For the IE one, it looks like:

PHP Code:
var xml = new Object();
var 
elem oDocument.getElementById(sId);

if (
window.ActiveXObject) {
  
xml = new ActiveXObject("Microsoft.XMLDOM");
  
xml.async false;
  
xml.load(sUrl);

  
//IE returns the HTML as a string...
  
var nodeHTML xml.transformNode(this.xslt);

  
elem.innerHTML nodeHTML;



You will note that I am merely replacing the innerHTML with the string that is returned from xml.transformNode(). For the Mozilla implementation, the transform results in a DOM fragment of the HTML elements, so I call elem.appendChild(node); which I feel is better than replacing innerHTML.

I can't seem to get the other transform methods to work with IE, though.

Again, any insight would be appreciated. Thanks!!

Last edited by rguilbault : August 18th, 2004 at 03:01 PM. Reason: Additional Info

Reply With Quote
  #2  
Old August 18th, 2004, 03:08 PM
NotGoddess's Avatar
NotGoddess NotGoddess is offline
Kung-fu Kitty
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jul 2004
Posts: 350 NotGoddess User rank is Sergeant (500 - 2000 Reputation Level)NotGoddess User rank is Sergeant (500 - 2000 Reputation Level)NotGoddess User rank is Sergeant (500 - 2000 Reputation Level)NotGoddess User rank is Sergeant (500 - 2000 Reputation Level)NotGoddess User rank is Sergeant (500 - 2000 Reputation Level) 
Time spent in forums: 4 Days 6 h 9 m 2 sec
Reputation Power: 10
Send a message via AIM to NotGoddess
Would you be able to provide links/samples of the xml and html as well? I work best when I have enough info to simulate your problem-then it's easier to pinpoint the problem. Thx.

Reply With Quote
  #3  
Old August 18th, 2004, 03:36 PM
NotGoddess's Avatar
NotGoddess NotGoddess is offline
Kung-fu Kitty
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jul 2004
Posts: 350 NotGoddess User rank is Sergeant (500 - 2000 Reputation Level)NotGoddess User rank is Sergeant (500 - 2000 Reputation Level)NotGoddess User rank is Sergeant (500 - 2000 Reputation Level)NotGoddess User rank is Sergeant (500 - 2000 Reputation Level)NotGoddess User rank is Sergeant (500 - 2000 Reputation Level) 
Time spent in forums: 4 Days 6 h 9 m 2 sec
Reputation Power: 10
Send a message via AIM to NotGoddess
Okay, first thanks for the additional info-I see you were thinking/acting upon it even as I was reading/posting
It's not quite enough [for me] to build a working testcase, but I've a suggestion.
-Try adding a simple button/link 'onclick' to manually test your script in each browser to see if it is indeed working. That will help define where the problem lies.
-Try wrapping the script call in CDATA tags: <![CDATA[ ScrollTable_initialize(); ]]>
-Try using a pure xsl/xml translation and see if that has a different effect.
-Use sablotron (or other translator) to turn the files into straight html (xml data included) and actually look to see if maybe something is parsing oddly.

I don't know the answer to 2, and for 1, well sometimes it's the only way I can get things to work (moymmv)

Reply With Quote
  #4  
Old August 18th, 2004, 04:38 PM
rguilbault rguilbault is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Aug 2004
Posts: 30 rguilbault User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 1 h 15 m 18 sec
Reputation Power: 5
files...

Here's the thing, see...I'm working with all of this stuff locally. I don't have a web server to stick the files (how lame, I know).

I'm going to try to attach a .zip file.

Ironically, I came across an issue you were/are having with Mozilla 'crashing' when displaying your Calendar and I've come up with a way to display the info using a similar method to what I'm trying to work with here...I'll update your post shortly...

THanks.

as always, I forgot to mention something important:

when you load up sample.htm, click the link and you will see an 'account summary' deal with a select box with LAB and MIC as the options. you need to click to MIC then back to LAB (I'm an idiot and there are no instruments for MIC) and you should see a table at the bottom of the screen...this table should be sortable by clicking the headers (all but the first column) -- in Mozilla, it seems to work...in IE, I got nothing!
Attached Files
File Type: zip sample.zip (11.0 KB, 281 views)

Last edited by rguilbault : August 18th, 2004 at 04:42 PM. Reason: I'm a dolt

Reply With Quote
  #5  
Old August 18th, 2004, 04:51 PM
NotGoddess's Avatar
NotGoddess NotGoddess is offline
Kung-fu Kitty
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jul 2004
Posts: 350 NotGoddess User rank is Sergeant (500 - 2000 Reputation Level)NotGoddess User rank is Sergeant (500 - 2000 Reputation Level)NotGoddess User rank is Sergeant (500 - 2000 Reputation Level)NotGoddess User rank is Sergeant (500 - 2000 Reputation Level)NotGoddess User rank is Sergeant (500 - 2000 Reputation Level) 
Time spent in forums: 4 Days 6 h 9 m 2 sec
Reputation Power: 10
Send a message via AIM to NotGoddess
Quote:
Originally Posted by rguilbault
Here's the thing, see...I'm working with all of this stuff locally. I don't have a web server to stick the files (how lame, I know).

It's not lame. I deal with client-side only problems as well. I use sablotron's command-line program sabcmd.exe manually to translate the pages (ie: sabcmd file.xsl file.xml newfile.html), then upload the [static] html when browser conflicts arise. Eventually I'll use a perl/php wrapper and do it the fancy way

Quote:
Ironically, I came across an issue you were/are having with Mozilla 'crashing' when displaying your Calendar and I've come up with a way to display the info using a similar method to what I'm trying to work with here...I'll update your post shortly...

*woo!* Thank you I've ended up using sablotron to convert to html, but then have another issue with xsl:sort to deal with I'd love a fix/mod to the original idea.

Reply With Quote
  #6  
Old August 18th, 2004, 05:10 PM
rguilbault rguilbault is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Aug 2004
Posts: 30 rguilbault User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 1 h 15 m 18 sec
Reputation Power: 5
I've never used sablotron...I'll have to look it up. Thanks!

Reply With Quote
  #7  
Old August 18th, 2004, 05:20 PM
NotGoddess's Avatar
NotGoddess NotGoddess is offline
Kung-fu Kitty
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jul 2004
Posts: 350 NotGoddess User rank is Sergeant (500 - 2000 Reputation Level)NotGoddess User rank is Sergeant (500 - 2000 Reputation Level)NotGoddess User rank is Sergeant (500 - 2000 Reputation Level)NotGoddess User rank is Sergeant (500 - 2000 Reputation Level)NotGoddess User rank is Sergeant (500 - 2000 Reputation Level) 
Time spent in forums: 4 Days 6 h 9 m 2 sec
Reputation Power: 10
Send a message via AIM to NotGoddess
No luck yet I have a forced break (aka commuting time) and I'll take another stab at it tonight. With luck you'll get someone to answer in the meantime.

Reply With Quote
  #8  
Old August 19th, 2004, 01:30 AM
NotGoddess's Avatar
NotGoddess NotGoddess is offline
Kung-fu Kitty
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jul 2004
Posts: 350 NotGoddess User rank is Sergeant (500 - 2000 Reputation Level)NotGoddess User rank is Sergeant (500 - 2000 Reputation Level)NotGoddess User rank is Sergeant (500 - 2000 Reputation Level)NotGoddess User rank is Sergeant (500 - 2000 Reputation Level)NotGoddess User rank is Sergeant (500 - 2000 Reputation Level) 
Time spent in forums: 4 Days 6 h 9 m 2 sec
Reputation Power: 10
Send a message via AIM to NotGoddess
Late return, so little time to debug, but I did notice (which I assume you already know) that if you type in the url with the params it works fine (or seems to) in IE6.
e.g. sample2.htm?dir=1940&xml=acct.xml&xsl=acct.xsl

You have default xml/xsl of
aParams["xml"] = "baseball.xml";
aParams["xsl"] = "exampleDoc.xsl";

When I changed those to files which were present (acct.xml/acct.xsl) and loaded the page w/o the params, it worked fine in IE6-it loaded the base 'choose module' set.

I did encounter a problem with FireFox, however. It loaded the base 'choose' just fine, but when you selected MIC/LAB that section loaded, but the entire area was pushed down to the bottom of the page.

Hope that helped.

Reply With Quote
  #9  
Old August 19th, 2004, 10:40 AM
rguilbault rguilbault is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Aug 2004
Posts: 30 rguilbault User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 1 h 15 m 18 sec
Reputation Power: 5
Red face

Quote:
Originally Posted by NotGoddess
Late return, so little time to debug, but I did notice (which I assume you already know) that if you type in the url with the params it works fine (or seems to) in IE6.
e.g. sample2.htm?dir=1940&xml=acct.xml&xsl=acct.xsl


It's actually IE that it's not working in ;-(

Quote:
Originally Posted by NotGoddess
You have default xml/xsl of
aParams["xml"] = "baseball.xml";
aParams["xsl"] = "exampleDoc.xsl";

When I changed those to files which were present (acct.xml/acct.xsl) and loaded the page w/o the params, it worked fine in IE6-it loaded the base 'choose module' set.


Yeah, sorry about that! I have a tendency to work bottom-up and I had a whole bunch of other files for other purpose testing that weren't necessary to upload...I should have made that change though.

Quote:
Originally Posted by NotGoddess
I did encounter a problem with FireFox, however. It loaded the base 'choose' just fine, but when you selected MIC/LAB that section loaded, but the entire area was pushed down to the bottom of the page.

Hope that helped.


I think what you're describing is the way it is intended to work. I just installed Firefox and tested it and it works the way I want (as it did in Mozilla)...

It's kinda convoluted, but here's sorta my goal (now that you've seen the pages it might make a little more sense):

1) The original page is loaded, the last thing on the page is "Choose Module".

2) Select MIC (thus invoking the onchange/change event with a javascript function attached). The content should have a header "Module:", should show a Specialists, Programmers and Dates box. At this point, all is well and good in each browser I've tested in.

3) At this point, you have to select LAB to load the content that breaks my page.

At the bottom of the page you should see a section "Instruments" with a table 6 rows. It looks a little funny, but that's because it's supposed to be a scrollable table.

Alas, the problem is that when you click the Instrument column, the rows should sort in alpabetic order. In Mozilla and Firefox, this is working (for me at least). I'm using version 0.9.2 Firefox and 1.7.1.

Now, in IE, however, the table is not sortable -- hell, the ScrollTable_initialize() function is never even called (as I placed alerts and such in there that never execute -- I don't even give me an error).

I think the issue lies in the XSLProcessor transform method (of my user-defined class) -- you'll noticed that for Mozilla's implementation (the else-if condition), I append a node structure to the container element, whereas for the IE implementation, I merely set the container's innerHTML property to the string returned by IE's transforming function. I have scoured MSDN to find other methods of transforming XML through javascript, but I can't find any that I can get to work. I think that assigning the string only prevents the function within the <script> tags from getting called. I'm not sure though.

What do you think the likelyhood of IE adopting the Gecko engine is?

Reply With Quote
  #10  
Old August 19th, 2004, 12:46 PM
rguilbault rguilbault is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Aug 2004
Posts: 30 rguilbault User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 1 h 15 m 18 sec
Reputation Power: 5
Aha!

http://msdn.microsoft.com/library/d...fxsltanddom.asp

It looks like I am doing things exactly as I need to for IE to be happy...now the question is: why the hell isn't my script running!? ;-)

Reply With Quote
  #11  
Old August 19th, 2004, 12:56 PM
NotGoddess's Avatar
NotGoddess NotGoddess is offline
Kung-fu Kitty
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jul 2004
Posts: 350 NotGoddess User rank is Sergeant (500 - 2000 Reputation Level)NotGoddess User rank is Sergeant (500 - 2000 Reputation Level)NotGoddess User rank is Sergeant (500 - 2000 Reputation Level)NotGoddess User rank is Sergeant (500 - 2000 Reputation Level)NotGoddess User rank is Sergeant (500 - 2000 Reputation Level) 
Time spent in forums: 4 Days 6 h 9 m 2 sec
Reputation Power: 10
Send a message via AIM to NotGoddess
By 'it works in IE' I meant, if you loaded the page passing the params (like the 'click me' link does) the page worked-the initial module loaded, and selecting LAB or MIC created a scrolltable beneath it. Changing the defaults to use those same params (acct.xml and .xsl) then reloading w/o the ?... search text also worked-the inital module loaded, you could select LAB or MIC and the scrolltable appeared.

However I attempt this on IE6 at work and it's broken The initial module will load but selecting LAB or MIC does nothing. I -did- tweak some lines last night, however I don't remember what...I'll attempt to recreate it here, else consult the files when I get home.

In regards to FireFox- when I said 'pushed down' I meant just that. The initial module, which at first loads flush with the 'text manipulations' green header is 'pushed down' when LAB or MIC is selected so you have to vertically scroll the (entire) window down to see anything but the upper edge. This might be a result of my forgotten tweaking, however, if you don't see that. I'll post a screenshot when I get home.

Reply With Quote