Go Back   CodingForums.com > :: Client side development > XML

Before you post, read our: Rules & Posting Guidelines

Reply
 
Thread Tools Rate Thread
Enjoy an ad free experience by logging in. Not a member yet? Register.
Old 12-27-2012, 01:10 PM   PM User | #1
larnott01795
New to the CF scene

 
Join Date: Dec 2012
Posts: 3
Thanks: 0
Thanked 0 Times in 0 Posts
larnott01795 is an unknown quantity at this point
Unhappy XSL Using JavaScript

Hi,

I have a JavaScript function which is embeded in an XSL file, I am using this to try and bring back a list of strings based on a number of rows in an XML file.

The problem I have is that I do not have the url of the XML file as this is created on the fly so I cannot load this in to look at the specific nodes of the file.

I am therefore trying to get some info from the XML file using an XSL tranformation in my javascript code. This works great, apart from one part of the code which I cannot get to use the variable "i". This is the part [@index=1] in the code below.

Code:
function Test()
{
	var xmlDoc = Navigator.CurrentXML;
	//xmlDoc.getElementsById("STAFF");
	var inputList = document.getElementsByTagName("select");
	docList="";
	for (var i = 0; i < inputList.length; i++)
	{
	docList += "GroupSetAttendanceType?documentList="
+"<xsl:value-of select="Data/DataRow[@index=1]/ID" />&amp;attendanceTypeID=" 
+ inputList.item(i)[inputList.item(i).selectedIndex].value 
+ "&amp;attendanceTypeDesc=" 
+ inputList.item(i)[inputList.item(i).selectedIndex].text;
	}

	GetControl("TestLine").innerHTML = docList;
}
Instead of [@index=1] I want it to be [@index=i+1] and use the variable i to determine what row index to use in the code. When I try this however it just brings out a null value.

I have tried things such as trying to split the text

"<xsl:value-of select="Data/DataRow[@index=1]/ID" />"

into

"<xsl:value-of select="Data/DataRow[@index="
+(i+1)+
"]/ID" />"

but this brings up an error saying
"The XSL could not be parsed. The error is Name cannot begin with the '+' character, hexadecimal value 0x2B. Line 16, position 99."

Any help would be greatly appreacted as I am pulling my hair out trying to get this to work.

Many thanks,

Laurence

Last edited by larnott01795; 12-27-2012 at 01:12 PM..
larnott01795 is offline   Reply With Quote
Old 12-28-2012, 05:54 PM   PM User | #2
sunfighter
Senior Coder

 
Join Date: Jan 2011
Location: Missouri
Posts: 2,392
Thanks: 18
Thanked 351 Times in 350 Posts
sunfighter is on a distinguished road
for (var i = 0; i &lt; inputList.length; i++)
Makes me cringe. I'd use
for (var i = 0; i<inputList.length; i++)
and be a lot happier.

Try:
+'<xsl:value-of select="Data/DataRow[@index="+(i+1)+"]/ID"/>'

Enclosing the double quotes inside of singles.
sunfighter is offline   Reply With Quote
Old 01-09-2013, 08:47 PM   PM User | #3
sbhmf
New Coder

 
Join Date: Jan 2013
Location: Sunnyvale, CA
Posts: 40
Thanks: 3
Thanked 1 Time in 1 Post
sbhmf is an unknown quantity at this point
I'm not responding here to the original post, but am commenting on the previous one.

Difficult to distinguish the quotes from the apostrophes (a.k.a. single-quotes) on my display, but it appears that they are not paired properly:

'<xsl:value-of select="Data/DataRow[@index="+(i+1)+"]/ID"/>'

might be intended as

'<xsl:value-of select=\'Data/DataRow[@index="' + (i+1) + '"]/ID\'/>'

wherein the quotes that are adjacent to plus signs, like the initial and final quotes, are all apostrophes, the index attribute's value is wrapped in real double-line quotes, and the value of the select attribute is wrapped in escaped apostrophes (single-quotes). That way, the final will look something like: <xsl:value-of select='Data/DataRow[@index="10"]/ID' />.

My XSLT is somewhat rusty, but I think there's a problem with the /ID after the @index - it should not be there. You might want to make sure that your code correctly builds your querystring. Why not set up an alert and see what the concatenated querystring looks like and make sure it is correctly formatted?

In case you have not yet discovered it, zvon.org is one of the noted sites for xslt documentation and examples. Perhaps you will find what you are looking for there.

Hope it helps.

Last edited by sbhmf; 01-09-2013 at 08:58 PM.. Reason: fixed typo and added a comment
sbhmf is offline   Reply With Quote
Reply

Bookmarks

Tags
javascript, xml, xsl

Jump To Top of Thread


Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 01:09 AM.


Advertisement
Log in to turn off these ads.