Login  Register

Re: Re: Generating table cells based on a "columns" attribute

Posted by Philip.Cantin on Oct 27, 2009; 8:53pm
URL: https://discuss.orbeon.com/Generating-table-cells-based-on-a-columns-attribute-tp277051p277323.html

Ethan,

If my hunch is correct...


'Dummy' is just an arbitrary element returned by xxforms:iterate. Since the value of the xxforms:iterate attribute must be a node/nodeset, the statement:


<xf:action xxforms:iterate="for $i in 1 to 4 return xxforms:element('dummy')">
...
</xf:action>


will return four <dummy/> elements for the xxforms:iterate attribute to iterate over. This is the same as doing:


<xf:instance id="test">
   <data>
      <dummy/>
      <dummy/>
      <dummy/>
      <dummy/>
   </data>
</xf:instance>

...

<xf:group ref="instance('test')">
   <xf:action xxforms:iterate="dummy">
      ...
   </xf:action>
<xf:group>


Hope this helps,

Philip


Ethan Gruber wrote
Thanks, Alex

I understand the logic now, but there is probably something wrong with my
syntax since it is still not working properly.  Here's a clip of what I have
(current context is tgroup)
                       <div>
                            <xforms:trigger appearance="minimal">
                                <xforms:label>
                                    Add
Table
                                    Header</xforms:label>

                             
                                <xforms:insert ev:event="DOMActivate"
context="thead"
                                    origin="instance('row-template')"/>

                             
                                <xforms:action
                                    xxforms:iterate="for $i in 1 to @cols
return
                                    xxforms:element('dummy')">
                                    <xforms:insert context="thead/row"
origin="instance('entry-template')"/>
                                </xforms:action>
                            </xforms:trigger>
                        </xforms:group>
                    </div>

                    <xforms:input ref="@cols">
                        <xforms:label>Columns</xforms:label>
                        <xforms:alert>Required</xforms:alert>
                        <xforms:hint>This must be an integer</xforms:hint>
                    </xforms:input>

                    <xforms:group ref="thead/row">
                        <div class="subsection">
                         
                           

Table Header

                            <xforms:trigger appearance="minimal">
                                <xforms:delete ev:event="DOMActivate"
nodeset="."/>
                                <xforms:label>
                                   
                                </xforms:label>
                            </xforms:trigger>

                           
                            <xforms:repeat nodeset="entry">
                                <div>
                                    <xforms:input ref=".">
                                        <xforms:label>Cell</xforms:label>
                                    </xforms:input>
                                </div>
                            </xforms:repeat>
                        </div>
                    </xforms:group>

---

What exactly is xxforms:element('dummy')?  Why does something need to be
returned?

Thanks,
Ethan

On Mon, Oct 26, 2009 at 9:58 PM, Alessandro Vernet <avernet@orbeon.com>wrote:

> Ethan,
>
> On Mon, Oct 26, 2009 at 11:40 AM, Ethan Gruber <ewg4xuva@gmail.com> wrote:
> > For example, I would like to create an "Add Row" trigger that inserts a
> > <row> into .  If I define @cols as 4, I'd like "Add Row" to insert
> > <row><entry/><entry/><entry/><entry/></row>, with an input for each
> <entry/>
>
> It looks like you need a way to execute an action a given number of
> times. In pseudo-code, you could do something like:
>
> <xforms:action xxforms:iterate="for $i in 1 to tgroup/@cols return
> xxforms:element('dummy')">
>    <xforms:insert context="row" origin="xxforms:element('entry')"/>
> </xforms:action>
>
> The 1 to tgroup/@cols returns a sequence of (1, 2, 3, 4) if you have 4
> columns, and the xxforms:element() creates an element for each one, as
> the context for XPath evaluation is expected to be a node.
>
> Alex
> --
> Orbeon Forms - Web forms, open-source, for the Enterprise
> Orbeon's Blog: http://www.orbeon.com/blog/
> My Twitter: http://twitter.com/avernet
>
>
> --
> You receive this message as a subscriber of the ops-users@ow2.org mailing
> list.
> To unsubscribe: mailto:ops-users-unsubscribe@ow2.org
> For general help: mailto:sympa@ow2.org?subject=help
> OW2 mailing lists service home page: http://www.ow2.org/wws
>
>


--
You receive this message as a subscriber of the ops-users@ow2.org mailing list.
To unsubscribe: mailto:ops-users-unsubscribe@ow2.org
For general help: mailto:sympa@ow2.org?subject=help
OW2 mailing lists service home page: http://www.ow2.org/wws