[Xsltforms-support] setvalue in XForm
Brought to you by:
alain-couthures
From: <mcu...@co...> - 2011-09-30 00:57:09
|
Hello all: I am attempting to create an Xform (using XSLTForms and MarkLogic) where the instance initially contains no data, like this: <xf:model> <xf:instance xmlns="" id="i1"> <table> <row> <column></column> </row> </table> </xf:instance> </xf:model> I would like to set the value of the column element to "default" upon loading the form in a browser but have not been able to do so. My stab at it is the xquery below but it does not work as hoped. Can anyone tell me a correct way to do this? Thanks, Morgan ---------------------------------- xquery version "1.0-ml"; declare namespace xdmp=" http://marklogic.com/xdmp "; let $page := (xdmp:set-response-content-type("application/xml"), <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 "> <head> <xf:model> <xf:instance xmlns="" id="i1"> <table> <row> <column></column> </row> </table> </xf:instance> </xf:model> <xf:action ev:event="xforms-ready"> <xf:action xf:if="string(instance('i1')/row/column) != 'default'"> <xf:setvalue ref="instance('i1')/row/column" value="'default'" /> </xf:action> </xf:action> </head> <body> <h3>Datafield</h3> <xf:group nodeset="/table"> <xf:repeat id="repeat-row" nodeset="row"> <xf:input ref="column"/> </xf:repeat> <xf:trigger> <xf:label>Add Row</xf:label> <xf:action ev:event="DOMActivate" if="index('repeat-row') != (count(row))"> <xf:insert nodeset="row" at="index('repeat-row')" position="after" /> <xf:setvalue ref="row[index('repeat-row')]/column" value="/table/row/column" /> </xf:action> <xf:action ev:event="DOMActivate" if="index('repeat-row') = (count(row))"> <xf:insert nodeset="row[last()]" position="after" at="last()"/> <xf:setvalue ref="row[last()]/column" value="/table/row/column"/> </xf:action> </xf:trigger> </xf:group> </body> </html> ) let $xslt-pi := processing-instruction xml-stylesheet {'type="text/xsl" href="xsltforms/xsltforms.xsl"'} return ($xslt-pi, $page) |