[XSL-LIST Mailing List Archive Home] [By Thread] [By Date]

[xsl] JavaScript and XSL Problems


Subject: [xsl] JavaScript and XSL Problems
From: "Railan, Puneet Mr., RCI - Vienna" <prailan@xxxxxxxxxxxxxxxxxxxxxxx>
Date: Thu, 18 Jul 2002 14:27:00 -0400

> Hi, I'm working on a project that will have a JavaScript menu generate along the side of the screen through XSL.  The way the JavaScript was written was so that it would have a list of fixed values.  Through XSL I'm attempting to make it generate specific to each XML document, to allow for easy navigation.  These documents are rather lengthy, which is why I'd like to put it in there.  My first attempts focused upon creating variables and passing them into the JavaScript, but after repeated attempts it didn't work.  So next, I used the <xsl:for-each> command (as it's based on a hierarchical structure, basically a Table of Contents) within JavaScript to go through the Table of Contents the right way.  After this, what I did was I created a function that would accept the proper values, and display it in the menu like how it's supposed to be.  The problem I'm getting is that it doesn't populate correctly, as I get some funky errors saying that it's missing a ")" in the javascript text embedded into the XSL file, and a "]" in one of the javascript files (there are two).  I'm going to paste in the code segment that I have in the XSL file, and the corresponding code in the javascript file where it's supposed to read it in.
> 
> XSL Code Fragment:
> 
> <xsl:template match="//sectiontitle" mode="toc">
> 	<script type="text/javascript">
> 			collectData(<xsl:value-of select="count(//sectiontitle)+count(//title)+count(//subtitle)"/>, l, <xsl:value-of select="normalize-space(.)"/>);
> 			l++;
> 	<xsl:for-each select="..//title">
> 			collectData(<xsl:value-of select="count(//sectiontitle)+count(//title)+count(//subtitle)"/>, l, <xsl:value-of select="normalize-space(.)"/>);
> 			l++;
> 		<xsl:for-each select="..//subtitle">
> 			collectData(<xsl:value-of select="count(//sectiontitle)+count(//title)+count(//subtitle)"/>, l, <xsl:value-of select="normalize-space(.)"/>);
> 			l++;
> 		</xsl:for-each>
> 	</xsl:for-each>
> 	</script>
> </xsl:template>
> 
> JavaScript Code Fragment:
> 
> // ssmItems[...]=[name, link, target, colspan, endrow?] - leave 'link' and 'target' blank to make a header   
> ssmItems[0]=["Menu"] //create header
> function collectData(counter, a, link)
> {
> 	var i=1
> 	do
> 	{
> 		ssmItems[a]=["\"" + link + "\", \"#" + link "\", \"\""]
> 		i++;
> 	}while(i <= counter)
> 	buildMenu();
> }
> 
> 
The way the list is supposed to be populated is by having a string in this format:

ssmItems[1]=["CNN", "http://www.cnn.com", ""]

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



Current Thread
Keywords