Initializing Global Variables XSLT Source Code
page 178 var topmainover=new Image77,15;
var topmainout=new Image77,15; var bottommainover=new Image77,15;
var bottommainout=new Image77,15; var topsectionover=new Image98,15;
var topsectionout=new Image98,15; var bottomsectionover=new Image98,15;
var bottomsectionout=new Image98,15; var topfeedbackover=new Image80,15;
var topfeedbackout=new Image80,15; var bottomfeedbackover=new Image80,15;
var bottomfeedbackout=new Image80,15; var toppreviousover=new Image77,15;
var toppreviousout=new Image77,15; var bottompreviousover=new Image77,15;
var bottompreviousout=new Image77,15; var topnextover=new Image60,15;
var topnextout=new Image60,15; var bottomnextover=new Image60,15;
var bottomnextout=new Image60,15; var topnextsectionover=new Image108,15;
var topnextsectionout=new Image108,15; var bottomnextsectionover=new Image108,15;
var bottomnextsectionout=new Image108,15; menu1over.src=imagemasterhimenu1.jpg;
menu1out.src=imagemastermenu1.jpg; menu2over.src=imagemasterhimenu2.jpg;
menu2out.src=imagemastermenu2.jpg; menu3over.src=imagemasterhimenu3.jpg;
menu3out.src=imagemastermenu3.jpg; ...
var mainblurb=Main menu; var sectionblurb=Section menu;
var feedbackblurb=Give feedback on this tutorial; var previousblurb=Go to previous panel;
var nextblurb=Go to next panel; var nextsectionblurb=Go to next section;
topmainover.src=..ih-main.gif; topmainout.src=..imain.gif;
... }
function iOutimage {
if browser==N3document[image].src=evalimage + out.src; }
function iOverimage {
if browser==N3document[image].src=evalimage + over.src; }
--
This JavaScript code is used for the mouseover effects on the HTML panels. To streamline processing, we generate this code as a variable. Weve removed roughly half the code here to
keep the listing short; most of this code deals with initializing a number of variables. Whenever we create a new HTML page, we simply insert this variable into the output
document:
script language=javascript xsl:value-of select=mouse-effects
script
As in traditional programming, storing frequently used values in a variable instead of calculating them each time simplifies the code and improves performance. Notice in the code
listing that a significant amount of JavaScript code is generated from the XML source
page 179
document. This fragment is the XSLT that generates a set of JavaScript variables that contain the titles of all the sections:
xsl:for-each select=tutorialsection xsl:textvar menuxsl:text
xsl:value-of select=position xsl:textblurb=xsl:text
xsl:value-of select=title xsl:text; xsl:text
xsl:value-of select=newline xsl:for-each
The code generates seven new variables, one for each
section
element in our tutorial:
var menu1blurb=Installing and configuring Toot-O-Matic; var menu2blurb=Creating your first tutorial;
var menu3blurb=developerWorks editorial guidelines; var menu4blurb=Toot-O-Matic tag guide;
var menu5blurb=Toot-O-Matic tag reference; var menu6blurb=Troubleshooting;
var menu7blurb=Feedback;
This is one of many cases when a naming convention is invaluable. If we want the JavaScript variable that contains the title of the fifth
section, we know that variable is named
menu5blurb
. This technique is useful in many other places, as well. If were creating HTML files for
the third
section
, and were currently processing the fourth
panel
in that
section
, and the root filename were using is tootomatic, the newly created HTML file will be named tootomatic-3-4.html. Similarly,
if we want to create a link to the previous and next HTML files, those files are named tootomatic-3-3.html and tootomatic-3-5.html,
respectively. Youll see this technique used throughout this case study.