Re: [Xsltforms-support] getInstanceDocument()
Brought to you by:
alain-couthures
From: Jesper T. <je...@tv...> - 2010-01-03 07:44:44
|
OK Here is my test file: <?xml-stylesheet href="xsltforms/xsltforms.xsl" type="text/xsl"?> <?xsltforms-options debug="yes"?> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> <html xmlns="http://www.w3.org/1999/xhtml" xmlns:xf="http://www.w3.org/2002/xforms" xmlns:ev="http://www.w3.org/2001/xml-events" xmlns:xsd="http://www.w3.org/2001/XMLSchema"> <head> <script type="text/javascript"> //<![CDATA[ function createNew(){ var model = document.getElementById("myModel"); var instance = model.getInstanceDocument("myInstance"); var dataElement = instance.getElementsByTagName("data")[0]; var itemElement0 = dataElement.getElementsByTagName("item")[0]; var itemElement1 = dataElement.getElementsByTagName("item")[1]; itemElement0.childNodes[0].nodeValue = "New content"; //itemElement1.setAttribute("z", "NEW ATT VALUE"); model.rebuild(); model.recalculate(); model.revalidate(); model.refresh(); } //]]> </script> <xf:model id="myModel"> <xf:instance id="myInstance" xmlns=""> <data> <item>Old content</item> <item z="old att value"/> <b/> </data> </xf:instance> <!-- This xf:bind is a trick of mine to get the example working! --> <!-- I would love to delete it ? --> <xf:bind calculate="5 + 5" nodeset="/data/b"/> </xf:model> </head> <body> <p><xf:output ref="/data/item[1]"/></p> <p><xf:output ref="/data/item[2]/@z"/></p> <xf:trigger> <xf:label>Change</xf:label> <xf:load ev:event="DOMActivate" resource="javascript:createNew()"/> </xf:trigger> </body> </html> The file is working, that is, I can change the content of the first item element. I don't know why I need the b element and the binding. This is a trick of mine to get the file working. Please inform me what I can do instead. *** Now, I have not succeeded in changing the z attribute value in the second item element. That is why I have out commented it in the JavaScript like this: //itemElement1.setAttribute("z", "NEW ATT VALUE"); To get the update of the attribute working is my main problem. But it would be nice if I could also be able to make new elements and attributes. I am going to use it all to make a shuffle routine in JavaScript that can annotate the instance document with the proper randomized values so the questions and their options get shuffled each time the user take the test. Cheers, Jesper Tverskov |