Re: [Xsltforms-support] getInstanceDocument
Brought to you by:
alain-couthures
From: Mark S. <m_s...@ma...> - 2009-10-06 13:55:33
|
Hi Alain, Just had time to begin experimenting with the new methods you added. I have tried: <?xml-stylesheet href="xsltforms/xsltforms.xsl" type="text/xsl"?> <html xmlns="http://www.w3.org/1999/xhtml" xmlns:ev="http://www.w3.org/2001/xml-events" xmlns:xf="http://www.w3.org/2002/xforms"> <head> <title>4.8.1.a getInstanceDocument() method (non-normative)</ title> <xf:model id="my_model1"> <xf:instance id="my_data1"> <car xmlns=""> <color>navy blue</color> <new-color>pink</new-color> </car> </xf:instance> </xf:model> </head> <body onload="f();"> <div id="xformControl"> <span> <input type="checkbox" onclick="$('console').style.display = this.checked? 'block' : 'none';" checked="checked"/> Debug </span> </div> <xf:group> <xf:label class="title">4.8.1.a getInstanceDocument() method (non-normative)</xf:label> </xf:group> <xf:group> <xf:label> This test case uses Javascript to execute the getInstanceDocument() method. You may have seen a message box with the value "<xf:output value="color"/>". </xf:label> <xf:input ref="color"> <xf:label>Colour</xf:label> </xf:input> </xf:group> <script type="text/javascript"> function f() { try { var model = document.getElementById('my_model1'); var inst1 = model.getInstanceDocument('my_data1'); var my_color = inst1.getElementsByTagName('color')[0]; var new_color = inst1.getElementsByTagName('new-color')[0]; var old_node = my_color.firstChild var new_node = new_color.firstChild; alert(my_color.getTextContent()); my_color.removeChild(old_node); my_color.appendChild(new_node); alert(my_color.getTextContent()); model.rebuild(); model.recalculate(); model.revalidate(); model.refresh(); } catch(DOMException) { alert('DOMException'); } } </script> <div id="console" style="display: block"/> </body> </html> which attempts to replace one text value with another for the color element. The values I get in the alerts suggest that removeChild and appendChild work, but the input bound to color continues to display the old value. I also notice from the debug that the events raised by rebuild, recalculate, revalidate and refresh don't look right. I get: Dispatching event xforms-recalculate on <SPAN class="xforms-model" id="my_model1"/> 0 -> Dispatching event xforms-revalidate on <SPAN class="xforms-model" id="my_model1"/> 2 -> Dispatching event xforms-refresh on <SPAN class="xforms-model" id="my_model1"/> 0 -> Dispatching event xforms-revalidate on <SPAN class="xforms-model" id="my_model1"/> 1 -> Dispatching event xforms-refresh on <SPAN class="xforms-model" id="my_model1"/> 0 -> Dispatching event xforms-refresh on <SPAN class="xforms-model" id="my_model1"/> I am using build 241. Here's hoping that I am just doing something wrong :-) All the best Mark On 1 Oct 2009, at 20:04, COUTHURES Alain wrote: > Hi Mark, >> >> Well, rebuild, recalculate, revalidate and refresh methods on model >> would be really nice, obviously. > I just added these methods! >> >> Individual instances just needs to be accessible as a bog-standard >> XML document objects. > Here is an extract from the wiki developer documentation of > XSLTForms : > XNode Class > > constructor function : initializes specific properties > getElementsByTagName method : gets an array of all elements with a > given tag name for this XNode object > getTextContent method : gets the text context for this XNode object > appendChild method : appends a new child at this XNode object > replaceChild method : replaces a child of this XNode object > insertBefore method : inserts a child before another one of this > XNode object > removeChild method : removes a child of this XNode object > setAttributeNS method : sets an attribute of this XNode object after > creating it if necessary. "xsd:type" is interpreted to associate the > corresponding type to this XNode object. > getAttributeNS method : gets the value of an attribute of this XNode > object > removeAttributeNS method : removes an attribute of this XNode object > cloneNode method : clones this XNode object > init function : sets properties of this XNode object > recycle function : clears every properties of this XNode object and > of its child XNode objects > create function : reuses a previously recycled XNode object or > creates a new XNode object > Cheers, > > -Alain |