Can index() Return Row Position Info of xforms:repeat-populated Table?

classic Classic list List threaded Threaded
3 messages Options
Reply | Threaded
Open this post in threaded view
|

Can index() Return Row Position Info of xforms:repeat-populated Table?

Spenser Kao

Hi,

 

In the test code attached below, I tried to create a table by xforms:repeat with the first column showing row position number.

 

Knowing that XPath index() function can be used as the “at” attribute of xforms:insert and xformst:delete actions, I thought I might be able to use the same function for the purpose of row position, but I received following message: A reference to a node (such as text, element, or attribute) is required in a binding. Attempted to bind to the invalid item type: class java.lang.String

 

If used xsl:for-each and position(), I could produce the expected effect without problem, but I am curious if I can archive the same with xforms:repeat and index()?

 

Regards,

 

Spenser

 

Here is the snippet of test code:

 

<head>

  <title>SQL Server Query Result - Application IDs</title>

   <xforms:model>                          

     <xforms:instance id="app-ids-instance">    

            <Application_IDs>

                        <Application_ID>

                                    <ID>A1234</ID>

            </Application_ID> 

                        <Application_ID>

                                    <ID>B1234</ID>

            </Application_ID>

                        <Application_ID>

                                    <ID>C234</ID>

                        </Application_ID>

                        <Application_ID>

                                    <ID>D1234</ID>

                        </Application_ID>                                                                                                                                                                                                                                 

            </Application_IDs>

    </xforms:instance>

  </xforms:model>

</head>

<body>

<table class="gridtable">

            <tr>

                        <th>Item</th>

<th>Application ID</th>                         

            </tr>                

            <xforms:repeat nodeset="//Application_ID" id="app-id-repeat">

                        <tr>

                                    <td align="right"><xforms:output ref="index('app-id-repeat')"/></td>                      

                                    <td align="center"><xforms:output ref="ID"/></td>         

                        </tr>                

            </xforms:repeat>

            </table>

</body>

</html>

 



--
You receive this message as a subscriber of the [hidden email] mailing list.
To unsubscribe: mailto:[hidden email]
For general help: mailto:[hidden email]?subject=help
ObjectWeb mailing lists service home page: http://www.objectweb.org/wws
Reply | Threaded
Open this post in threaded view
|

Re: Can index() Return Row Position Info of xforms:repeat-populated Table?

Erik Bruchez
Administrator
Spenser,

 > In the test code attached below, I tried to create a table by
 > *xforms:repeat* with the first column showing row position number.
 >
 > Knowing that XPath *index()* function can be used as the "at"
 > attribute of xforms:insert and xformst:delete actions, I thought I
 > might be able to use the same function for the purpose of row
 > position, but I received following message: */A reference to a node
 > (such as text, element, or attribute) is required in a
 > binding. Attempted to bind to the invalid item type: class
 > java.lang.String/*

 > If used *xsl:for-each* and *position()*, I could produce the expected
 > effect without problem, but I am curious if I can archive the same with
 > *xforms:repeat* and *index()*?

The @ref attribute must *always* point to a node (or a node-set,
possibly empty, and then the first node of the node-set only is taken
into account). The index() function returns a number, so you get that
error if your @ref attribute only contains a call to index().

But xforms:output also has a @value attribute which is not subject to
this condition. So write intead:

   <xforms:output value="index('app-id-repeat')"/>

But this won't produce the expected result, because the index()
function returns the currently *selected* repeat iteration. So you
would get all 1's, or all 2's, etc., instead of what you are
expecting. Use the position() function instead. Compare:

     <xforms:repeat nodeset="my-nodes" id="test-repeat">
       <xhtml:div>
           Index: <xforms:output value="index('test-repeat')"/>
           <xhtml:br/>
           Position: <xforms:output value="position()"/>
       </xhtml:div>
     </xforms:repeat>

-Erik

--
Orbeon - XForms Everywhere:
http://www.orbeon.com/blog/



--
You receive this message as a subscriber of the [hidden email] mailing list.
To unsubscribe: mailto:[hidden email]
For general help: mailto:[hidden email]?subject=help
ObjectWeb mailing lists service home page: http://www.objectweb.org/wws
Reply | Threaded
Open this post in threaded view
|

RE: Can index() Return Row Position Info of xforms:repeat-populated Table?

Spenser Kao
Hi Erik,

The @value does the trick - with position() for table row number, and with
index() for the selected (clicked) row number.

Thank you.
 
Spenser Kao
Lending Technology Services Pty Ltd
117 Ferrars Street
South Melbourne VIC 3205
Ph: +61 3 8699 7900
Fax: +61 3 9682 8753
Email: [hidden email]
Web: www.lendtech.com.au
-----Original Message-----
From: Erik Bruchez [mailto:[hidden email]] On Behalf Of Erik Bruchez
Sent: Tuesday, 19 September 2006 7:14 PM
To: [hidden email]
Subject: Re: [ops-users] Can index() Return Row Position Info of
xforms:repeat-populated Table?

Spenser,

 > In the test code attached below, I tried to create a table by
 > *xforms:repeat* with the first column showing row position number.
 >
 > Knowing that XPath *index()* function can be used as the "at"
 > attribute of xforms:insert and xformst:delete actions, I thought I
 > might be able to use the same function for the purpose of row
 > position, but I received following message: */A reference to a node
 > (such as text, element, or attribute) is required in a
 > binding. Attempted to bind to the invalid item type: class
 > java.lang.String/*

 > If used *xsl:for-each* and *position()*, I could produce the expected
 > effect without problem, but I am curious if I can archive the same with
 > *xforms:repeat* and *index()*?

The @ref attribute must *always* point to a node (or a node-set,
possibly empty, and then the first node of the node-set only is taken
into account). The index() function returns a number, so you get that
error if your @ref attribute only contains a call to index().

But xforms:output also has a @value attribute which is not subject to
this condition. So write intead:

   <xforms:output value="index('app-id-repeat')"/>

But this won't produce the expected result, because the index()
function returns the currently *selected* repeat iteration. So you
would get all 1's, or all 2's, etc., instead of what you are
expecting. Use the position() function instead. Compare:

     <xforms:repeat nodeset="my-nodes" id="test-repeat">
       <xhtml:div>
           Index: <xforms:output value="index('test-repeat')"/>
           <xhtml:br/>
           Position: <xforms:output value="position()"/>
       </xhtml:div>
     </xforms:repeat>

-Erik

--
Orbeon - XForms Everywhere:
http://www.orbeon.com/blog/






--
You receive this message as a subscriber of the [hidden email] mailing list.
To unsubscribe: mailto:[hidden email]
For general help: mailto:[hidden email]?subject=help
ObjectWeb mailing lists service home page: http://www.objectweb.org/wws