Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 4 of 4
  1. #1
    New to the CF scene
    Join Date
    Dec 2012
    Posts
    3
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Unhappy Please help!! JavaScript XSL combine

    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

  • #2
    Senior Coder
    Join Date
    Apr 2011
    Location
    London, England
    Posts
    2,120
    Thanks
    15
    Thanked 354 Times in 353 Posts
    Your use of quotation is incorrect: you cannot nest double quotes within double quotes.

    "This "won't" work"
    "This \"will\" work, using 'escaping'"
    "This 'will also' work, using apostrophes"
    "I'm here to save your life. But if I'm going to do that, I'll need total uninanonynymity." Me Myself & Irene.
    Validate your HTML and CSS

  • #3
    New to the CF scene
    Join Date
    Dec 2012
    Posts
    3
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Quote Originally Posted by AndrewGSW View Post
    Your use of quotation is incorrect: you cannot nest double quotes within double quotes.

    "This "won't" work"
    "This \"will\" work, using 'escaping'"
    "This 'will also' work, using apostrophes"
    Great thanks for your help, I have tried this but with no luck, can you see if the either of the below are correct as these have both produced errors

    Code:
    "<xsl:value-of select=\"Data/DataRow[@index="+(i+1)+"]/ID\" />&amp;attendanceTypeID="
    and

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

  • #4
    Senior Coder
    Join Date
    Apr 2011
    Location
    London, England
    Posts
    2,120
    Thanks
    15
    Thanked 354 Times in 353 Posts
    I'm guessing this
    Code:
    inputList.item(i)[inputList.item(i).selectedIndex].value
    is probably wrong. If inputList is a SELECT then probably:
    Code:
    inputList[inputList.selectedIndex].value
    // or..
    inputList[i].value
    "I'm here to save your life. But if I'm going to do that, I'll need total uninanonynymity." Me Myself & Irene.
    Validate your HTML and CSS


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •