[xsl] setting and returning variable values from the source file using javascript

Subject: [xsl] setting and returning variable values from the source file using javascript
From: "M. David Peterson" <conners_dad@xxxxxxx>
Date: Thu, 4 Sep 2003 03:07:40 -0600
Hello All,

My forehead is bruised and bleeding from the brick wall ive been using and 
its time to call on the army.  PLEASE, someone, PLEASE point out the error 
of my ways and save me from yet another 8 hours of forced self mutilation... 
I apologize for the length of this post, but without the proper information 
this may not make any sense.

A long story short... I am setting javscript variables to the values of tags 
named 'loc', 'subloc', and 'id' during each loop through a for-each.  The 
java script looks like this...

<msxsl:script language="jscript" implements-prefix="my">

        var lid;
        var loc = "home";
        var subloc = "main";
        var count = 0;

        function setLid(value){

            lid = value;
            return 0;

        function setPath(n_loc, n_subloc){

            loc = n_loc;
            subloc = n_subloc;
            return 0;


        function returnPath(){

            var s = loc.concat(subloc);

        function returnLid(){

            return lid;


To ensure that the variables are reset during every loop I use xsl:choose 
and xsl:when and proceed into the when block when I get a return value of 0 
from the set functions...  Ive got two keys set, one to match 'link' and use 
'@id'  and one to match 'link' and use a concat of '@loc' and '@subloc' from 
the master file to compare against the source file (the master file is a 
representation of all the links on the site, the source file is a 
representation of each page a person has visited on the site).

The master file is set to a param as such...

<xsl:param name="FTR_Links" 

The keys looks like...

<xsl:key name="linkMatch" match="link" use="@id"/>
<xsl:key name="loc_subloc_Match="link" use="concat(@loc, @subloc)"/>

The master list looks like this...

    <link id="AAA001" loc="home" subloc="main">Home</link>

The source looks like this...

      <date>9/3/2003 10:26:57 PM</date>
      <date>9/3/2003 10:26:06 PM</date>
Genealogy&amp;click=English Genealogy</referrer>

Using just the linkMatch key the following works perfectly, but does have 
one snag.  The first link returned has both 'loc' and 'subloc' of the 
querystring set to 'NaN'...  This is of course extremely annoying and needs 
to be fixed but it doesn't break anything...  Heres the snippet...


    <xsl:when test="my:setLid(lid) = 0">


            <xsl:when test="my:setPath(loc, subloc) = 0">

                <xsl:for-each select="$FTR_Links">

                    <xsl:for-each select="key('linkMatch', my:returnLid())">

                        <a class="menu" href="?loc={concat(@loc, 
'&amp;subloc=', @subloc, '&amp;', 'lid=', @id, '&amp;sid=', $sid)}" 
select="."/></a> ::







The problem becomes even more of a problem when I take the above one step 
further and try to use the 'loc_subloc_Match' key to compare against the 
master list.  When I use the my:returnPath() function to return a concat of 
the loc and subloc of the source file to compare against the master it 
breaks due to the fact im trying to concat two 'NaN' instead of two string 
values. To verify the problem (and to make sure the string comparison of the 
concat strings works) I hardcoded the value of string 's' in the returnPath 
function to 'ftrihist'.  It works PERFECTLY!  Of course the results are 
useless, but none-the-less the comparison works.


Can someone PLEASE explain to me why the first time through the for-each 
loop the loc and subloc values are being set to 'NaN'?  Solving this problem 
with solve the rest of my problems and I can finally get some much needed 
rest!!! :) :) ;)

MUCH thanks and appreciation in advance to the brilliant soul that saves me 
from one more headbangwall session!!!

BEST Regards,


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

Current Thread