Thread: [Xsltforms-support] getInstanceDocument()
Brought to you by:
alain-couthures
From: Jesper T. <je...@tv...> - 2010-01-01 20:30:45
|
I am testing the DOM interface to the instance document using getInstanceDocument(), and I have no problems updating simpleContent of an element. But I have failed so far updating an attribute or creating new attributes and new elements from JavaScript using getInstanceDocument(). Is this failure due to lack of implementation in XSLTForms or haven't I been experimenting hard enough? Cheers, Jesper Tverskov http://www.xmlkurser.dk http://www.xmlplease.com |
From: COUTHURES A. <ala...@ag...> - 2010-01-02 21:57:16
|
Hi Jesper, > I am testing the DOM interface to the instance document using > getInstanceDocument(), and I have no problems updating simpleContent > of an element. > > But I have failed so far updating an attribute or creating new > attributes and new elements from JavaScript using > getInstanceDocument(). > > Is this failure due to lack of implementation in XSLTForms or haven't > I been experimenting hard enough? > Could you please send me a test case ? I think it will be an easy way to show you how to do this. Thanks! -Alain |
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 |
From: Jesper T. <je...@tv...> - 2010-01-06 06:22:33
|
I would very much appreciate if anyone could come with a working example of how to change an attribute value in the instance document using getInstanceDocument(). The DOM interface to the instance document is a must for any but the most trivial use cases of XSLTForms. In my supplied test file I have manage to update element content. My test file is working e.g. in IE (the DTD must be deleted first), Firefox, Opera and Chrome, but I have not been able to update or create attributes or to create a new element. Cheers, Jesper Tverskov http://www.xmlkurser.dk http://www.xmlplease.com |
From: COUTHURES A. <ala...@ag...> - 2010-01-06 21:09:56
|
Jesper, Sorry for the late response. You have to look at XNode class in xsltforms.js to exactly know which methods are implemented. In your test case, you can use "setAttributeNS". Usually, for Javascript instructions, I use a debugger. FireBug has its own bugs but has also some advantages, especially in this case, it can display which methods are available. Cheers, -Alain > I would very much appreciate if anyone could come with a working > example of how to change an attribute value in the instance document > using getInstanceDocument(). > > The DOM interface to the instance document is a must for any but the > most trivial use cases of XSLTForms. > > In my supplied test file I have manage to update element content. My > test file is working e.g. in IE (the DTD must be deleted first), > Firefox, Opera and Chrome, but I have not been able to update or > create attributes or to create a new element. > > Cheers, > Jesper Tverskov > > http://www.xmlkurser.dk > http://www.xmlplease.com > > ------------------------------------------------------------------------------ > This SF.Net email is sponsored by the Verizon Developer Community > Take advantage of Verizon's best-in-class app development support > A streamlined, 14 day to market process makes app distribution fast and easy > Join now and get one step closer to millions of Verizon customers > http://p.sf.net/sfu/verizon-dev2dev > _______________________________________________ > Xsltforms-support mailing list > Xsl...@li... > https://lists.sourceforge.net/lists/listinfo/xsltforms-support > > |
From: Jesper T. <je...@tv...> - 2010-01-06 21:30:01
|
Thanks, it works. Yes, I should look deep into xsltforms.js, and I will try out this FireBug. Cheers, Jesper Tverskov |