Jump to content

trainzebra

Members
  • Posts

    12
  • Joined

  • Last visited

Everything posted by trainzebra

  1. Hey all. I'm attempting to add an attribute to an xml node from within an xsl document, using javascript. My code at the moment looks like this. var worker = window.location.href.split('/'); var file = worker[worker.length-1].split('?'); document.write(file[0]); xmlDoc=new ActiveXObject("Microsoft.XMLDOM"); xmlDoc.async=false; xmlDoc.load(file[0]); var x = xmlDoc.getElementsByTagName('Header'); var newatt; for(i=0; i != x.length; i++){ newatt = xmlDoc.createAttribute("state"); newatt.value = str; x[i].setAttributeNode(newatt); } for(i=0; i != x.length; i++){ document.write(x[i].getAttribute("state")); } File[0] contains the name of the xml document to be loaded. The line document.write(x.getAttribute("state") at the end outputs the correct string (str), but doesn't seem to be actually updating the xml file. This is a problem, as I need the current state actually in the xml file so that xsl can reference it in an if statement later. Does anyone know how I can do this?
  2. That's an extremely good idea. Can you clarify if I'm going about this the right way? Relevant parts of the XML file are as follows. <?xml version="1.0" encoding="utf-8"?><PLMXML <!--lots of attributes--> ><Header id="id1"></Header></PLMXML> I'm attempting to get the Header node and write into it. document.getElementById("id1").write("something")<!-- or -->document.getElementById("Header").write("something") However when I try to output it, nothing comes back. <xsl:value-of select="PLMXML/Header"/> Is my procedure right here? If I need to I can probably get the name of the xml file from window.location and make an ActiveXObject to access the full tree, but if there's a simpler way I'd prefer it =p
  3. Thanks for the help Boen. Forgive me if I'm being slow here, but what do you mean by access the current element and write it? Let me expand my code a little to see if there's anything you can point out to help me understand. Str is a variable that contains the value of a query string appended to my xml file's url on a button press, for reference. At various points in my code, I want to display one of three colored icons based on str's value (I'll probably use a switch statement when finalizing my code). <xsl:for-each select="varname1"> <script type="text/javascript"> if(str == "started"){ document.write("<td><img src="blue1.jpg"></img></td>"); document.write("<td><xsl:value-of select="../@varname2"/></td>"); } else if(str == "completed"){ document.write("<td><img src="green1.jpg"></img></td>"); document.write("<td><xsl:value-of select="../@varname2"/></td>"); } ... </script></xsl:for-each> If my understanding is correct then my xsl for this particular code segment would look like this? <xsl:for-each select="varname1"> <td><img src="blue1.jpg"></img></td> <td><xsl:value-of select="../@varname2/></td></xsl:for-each> Is this also an invalid stylesheet? When simply coded it displays just fine, I just can't seem to get javascript to output this text using write(). Thanks again for the help.
  4. Hey all. I'm running into a small problem while trying to use javascript if statements in an xsl file. I've tried a couple different solutions. I'm just going to go with the simplest example I have here with simply an image and no xsl. I want to display the image blue1.jpg when the variable str = "started".When I attempt it this way, the image is displayed no matter what str is: <script type="text/javascript">if(str == "started"){</script> <td><img src="blue1.jpg"></img></td><script type="text/javascript">}</script> When I attempt it this way, there's a conflict between what javascript and xsl want. If I put a backslash before the quotes in blue1.jpg to suppress their meaning, xsl throws an error because it expects a quote after src=. If I don't put them there, javascript reads the first one as the end of the string and doesn't display anything. <script type="text/javascript">if(str == "started"){ document.write("<td><img src="blue1.jpg"></img></td>")}</script> Does anyone know of any way to work around this?
  5. I tried it in firefox and it gets a parsing an xslt stylesheet failed message. However I am indeed running it locally using IE6. This sounds like a winner, I'll try uploading it first thing in the morning. Thanks much :)EDIT: I uploaded my file onto localhost on my machine and it does indeed get the query string no problem. However, now I'm running into a problem with my if statements functioning.I've tried a couple different solutions. I'm just going to go with the simplest example I have here with simply an image and no xsl. I want to display the image blue1.jpg when the variable str = "started".When I attempt it this way, the image is displayed no matter what str is: <script type="text/javascript">if(str == "started"){</script> <td><img src="blue1.jpg"></img></td><script type="text/javascript">}</script> When I attempt it this way, there's a conflict between what javascript and xsl want. If I put a backslash before the quotes in blue1.jpg to suppress their meaning, xsl throws an error because it expects a quote after src=. If I don't put them there, javascript reads the first one as the end of the string and doesn't display anything. <script type="text/javascript">if(str == "started"){ document.write("<td><img src="blue1.jpg"></img></td>")}</script> Does anyone know of any way to work around this?
  6. I've actually tried that as well, but it runs into the same problem of a query string being displayed in the browser's address bar, but the window.location.search variable that the function references comes back empty.
  7. Thing is that the query string is actually in the url. For example, it might display asfile:///C:/Documents%20and%20Settings/...table.xml?list=allBut if I code var str = Request.QueryString["list"];document.write(str); It returns undefined.
  8. Thanks for the help. However it seems to be doing the same thing, when I output str after running the function it's coming up as undefined. I'm assuming it's because the reference to href within the function is turning up empty. Thanks again though, any other ideas?
  9. Hey all. I'm trying to write an xsl file that uses javascript to get query strings that are appended to the url after a button press (no server side scripting). My understanding is that the general procedure for this is to reference window.location.href or window.location.search to get the query string then parse accordingly. However, after my form submits its value the href variable doesn't seem to be updating. Here's what the code for my form looks like. <form name="filter" method="get" action=""> <select name="list"> <option name="opAll" value="all">All Items</option> <option name="opCompleted" value="completed">Completed</option> <option name="opStarted" value="started">Started</option> <option name="opPending" value="pending">Pending</option> </select> <input type="submit" value="Display" onClick="pageEdit(this.form)"></input></form> After hitting the submit button, my url will look like this for example:file:///C:/Documents%20and%20Settings/...table.xml?list=allIf I script document.write(window.location), it gives the full path to my file, but no query string.file:///C:/Documents%20and%20Settings/...table.xmlIf I output document.write(window.location.href) it's empty. My question is, why is it doing this? Is there any way to simply get the text that's currently displayed in the address bar of my browser? If I need to provide any more code let me know. Thanks for any help.
  10. Hmm so my code is syntactically correct then? My xml's actually fine, I just got sloppy while pasting. Thanks for the help, I'll look into updating some of my software and see if that sorts things out.
  11. Thanks for the response. For the first example, nope, the <tr>s aren't in any sort of loop. Here's the code from start to that point if it helps any. Counter is a variable that's used for table formatting later and pageEdit is a script that's still being worked on, but not relevant at the moment. It's also probably worth noting that I had all of this code and this particular example working with a different version of xsl (http://www.w3.org/TR/WD-xsl) a few days ago, with proper syntax changes of course. <?xml version="1.0" encoding="utf-8"?><xsl:stylesheet version="1.0"xmlns:xsl="http://www.w3.org/1999/XSL/Transform"><xsl:template match="/"> <html> <body> <script type="text/javascript"> var counter=0; </script> <table border="0" cellspacing="10"> <!--get the status report name out of the WorkflowProcess element--> <tr align="center"> <td align="right"><img src="minilogo.jpg"></img></td> <td align="left"><font size="5" color="000000" face="arial"> Job Order Report</font></td> </tr> <tr> <td align="left"><font size="3" color="000000" face="arial">Initiator: <xsl:value-of select="PLMXML/Person/@lastName"/></font></td> </tr> <tr> <td align="left"><font size="3" color="000000" face="arial">Reverse Engineering Process</font></td> </tr> <tr> <td> <form name="filter" method="get" action=""> <select name="list" onChange="pageEdit(this.form)"> <option name="opAll" value="all">All Items</option> <option name="opCompleted" value="completed">Completed</option> <option name="opStarted" value="started">Started</option> <option name="opPending" value="pending">Pending</option> </select> <input type="submit" value="Display" onClick="pageEdit(this.form)"></input> </form> </td> </tr> </table> In reguards to the second example, that would work except that I need to check for three different conditions once I've determined if the element has target refs or not. Specifically completed, started, or pending. So it ends up being: <xsl:when test="@targetRefs"><xsl:if test="@state='started'">...</xsl:if><xsl:if test="@state='completed'">...</xsl:if><xsl:if test="@state='pending'">...</xsl:if></xsl:when> Sorry for not clarifying that sooner. The larger problem with this one is that it doesn't seem to be meeting the when condition to get into the statement. For example if I just hardcode data into the when it won't display. Thanks again for the help.
  12. Both of my files are rather large, so I'm going to attempt and only pull out the relevant information. The involved xml segments look like this. <PLMXML><Person id="id18" lastName="Mike Jones">...<UserData id="id29"></Person></PLMXML> I'm attempting to simply pull the lastName attribute out of the file and display it. The code here is not working, though most examples that I've looked at suggest it should. <?xml version="1.0" encoding="utf-8"?><xsl:stylesheet version="1.0"xmlns:xsl="http://www.w3.org/1999/XSL/Transform"><xsl:template match="/">...<tr> <td align="left"><font size="3" color="000000" face="arial">Initiator: <xsl:value-of select="PLMXML/Person/@lastName"/></font></td></tr> If I make the following change, it displays correctly, but this seems to be a bandaid solution to me. <tr> <td align="left"><font size="3" color="000000" face="arial">Initiator: <xsl:value-of select="//@lastName"/></font></td></tr> Later on in my file I'm attempting to check and see if a node has a targetRefs attribute. The relevant xml is as follows. <PLMXML><WorkflowProcess id="id15" name="A-COC-6-23419"><Task id="id59" name="ReverseEnggProcess" state="pending" targetRefs="#id2 #id60 #id13"></Task></WorkflowProcess></PLMXML> Here is the xsl. My assumption is that it's failing to pass through the xsl:when condition as nothing is being displayed at all. Is this the proper syntax for it? <xsl:for-each select="PLMXML/WorkflowProcess"> <tr> <xsl:for-each select="Task"> <xsl:choose> <xsl:when test="@targetRefs"> <!--if it has targetRefs, then its the top level task, don't display anything--> <xsl:if test="@state='started'"> <td><img src="blue1.jpg"></img></td> <td><font size="2" color="000000" face="arial"><xsl:value-of select="../@name"/></font></td> <td colspan="5"><hr></hr></td> </xsl:if> </xsl:when>... </xsl:choose></xsl:for-each></xsl:for-each> Can anyone see any obvious problems? I hope I've been clear on this one, been staring at the screen a while and it's starting to get to me
×
×
  • Create New...