Thread: [Xsltforms-support] Nested repeat with different instances
Brought to you by:
alain-couthures
From: Elias M. <eli...@gm...> - 2013-02-20 20:41:32
|
Hi. I'm trying to create a spreadsheet where the rows and columns are in separate instances, something like: <xf:instance id="rows"> <data xmlns=""> <row> <rowdata>stuff</rowdata> </row> <row> <rowdata>more stuff</rowdata> </row> ... ... </data> </xf:instance> <xf:instance id="cols"> <data xmlns=""> <col> <coldata>stuff</coldata> </col> <col> <coldata>more stuff</coldata> </col> ... ... </data> </xf:instance> <xf:repeat id="rows" nodeset="instance('rows')/row"> <div><xf:output value="./rowdata"/></div> <xf:repeat id="cols" nodeset="instance('cols')/col"> <div><xf:output value="./coldata"/> <xf:output value="index('rows')"/><br/> <xf:output value="index('cols')"/> </div> </xf:repeat> </xf:repeat> As you can see I'm using a nested repeat. Start with the repeat for the rows and inside the repeat for the cols. Works fine and displays fine, BUT the index gets lost when moving from one cell to another. It should show 1,1 if I click on the first cell, 1,2 in the second, 2,1 in the second row, 2,2 etc.. It does show correctly for the first few clicks, but then is gets lost if I click on cells in the same row it does not update. I do need the index to perform some actions on the cell. Any help is appreciated. Thanks Elias |
From: Alain C. <ala...@ag...> - 2013-02-24 21:42:12
|
Hello Elias, > I'm trying to create a spreadsheet where the rows and columns are in > separate instances, something like: > > <xf:instance id="rows"> > <data xmlns=""> > <row> > <rowdata>stuff</rowdata> > </row> > <row> > <rowdata>more stuff</rowdata> > </row> > ... > ... > </data> > </xf:instance> > > <xf:instance id="cols"> > <data xmlns=""> > <col> > <coldata>stuff</coldata> > </col> > <col> > <coldata>more stuff</coldata> > </col> > ... > ... > </data> > </xf:instance> > > <xf:repeat id="rows" nodeset="instance('rows')/row"> > <div><xf:output value="./rowdata"/></div> > <xf:repeat id="cols" nodeset="instance('cols')/col"> > <div><xf:output value="./coldata"/> > <xf:output value="index('rows')"/><br/> > <xf:output value="index('cols')"/> > </div> > </xf:repeat> > </xf:repeat> > > There are duplicate ids for instances and repeats and I have rewritten this test case like this: <html xmlns:xforms="http://www.w3.org/2002/xforms" xmlns="http://www.w3.org/1999/xhtml" xmlns:xhtml="http://www.w3.org/1999/xhtml" xmlns:ev="http://www.w3.org/2001/xml-events" xmlns:xsd="http://www.w3.org/2001/XMLSchema"> <head> <title>Indexes</title> <xforms:model> <xforms:instance id="irows"> <data xmlns=""> <row> <rowdata>datar1</rowdata> </row> <row> <rowdata>datar2</rowdata> </row> </data> </xforms:instance> <xforms:instance id="icols"> <data xmlns=""> <col> <coldata>datac1</coldata> </col> <col> <coldata>datac2</coldata> </col> </data> </xforms:instance> </xforms:model> </head> <body> <xforms:repeat id="rows" nodeset="instance('irows')/row"> <div><xforms:output value="./rowdata"/></div> <xforms:repeat id="cols" nodeset="instance('icols')/col"> <div><xforms:output value="./coldata"/> <br/> Current row:<xforms:output value="index('rows')"/><br/> Current col:<xforms:output value="index('cols')"/> </div> </xforms:repeat> </xforms:repeat> </body> </html> I can see an issue with the index() function for the cols repeat because clicking on the last column item in the second row does not have any effect on this index. I think that it is because it is a cloned node and I can surely fix this. Are you in a hurry? -Alain |
From: Elias M. <eli...@gm...> - 2013-02-25 01:17:56
|
Hi Alain. Thanks for the feedback. Actually, I found a small quirk with this code. In the code you have below, instead of 2 xf:output, if you use just one with a concat, it works fine. Looks like after the first xf:output it looses the cols index. Anyway, with this problem kind of solved I have another one that maybe you can help me: As I display the matrix I need to highlight a cell that matches a condition for both the row and col. For example, let's say I want to highlight in green the cell that has both the row and col with the word "test". That means that I need to rely on the position() function to check the contents of the row and cell, not the index which is updated every time a node becomes current. But, position() only applies to the current context. So in the inside repeat for the cols I need to check the content of the row in the outside repeat, but position() does not work. So the question is: how can I reference the position of the outside repeat while it's happening so I can manipulate the display of the cell? I tried instance('irows')/row/position() but it fails. Hope this makes sense :-) Thanks Elias On Sun, Feb 24, 2013 at 4:35 PM, Alain Couthures < ala...@ag...> wrote: > Hello Elias, > > I'm trying to create a spreadsheet where the rows and columns are in >> separate instances, something like: >> >> <xf:instance id="rows"> >> <data xmlns=""> >> <row> >> <rowdata>stuff</rowdata> >> </row> >> <row> >> <rowdata>more stuff</rowdata> >> </row> >> ... >> ... >> </data> >> </xf:instance> >> >> <xf:instance id="cols"> >> <data xmlns=""> >> <col> >> <coldata>stuff</coldata> >> </col> >> <col> >> <coldata>more stuff</coldata> >> </col> >> ... >> ... >> </data> >> </xf:instance> >> >> <xf:repeat id="rows" nodeset="instance('rows')/row"> >> <div><xf:output value="./rowdata"/></div> >> <xf:repeat id="cols" nodeset="instance('cols')/col"> >> <div><xf:output value="./coldata"/> >> <xf:output value="index('rows')"/><br/> >> <xf:output value="index('cols')"/> >> </div> >> </xf:repeat> >> </xf:repeat> >> >> >> There are duplicate ids for instances and repeats and I have rewritten > this test case like this: > > <html xmlns:xforms="http://www.w3.org/2002/xforms" xmlns=" > http://www.w3.org/1999/xhtml" xmlns:xhtml="http://www.w3.org/1999/xhtml" > xmlns:ev="http://www.w3.org/2001/xml-events" xmlns:xsd=" > http://www.w3.org/2001/XMLSchema"> > <head> > <title>Indexes</title> > <xforms:model> > <xforms:instance id="irows"> > <data xmlns=""> > <row> > <rowdata>datar1</rowdata> > </row> > <row> > <rowdata>datar2</rowdata> > </row> > </data> > </xforms:instance> > <xforms:instance id="icols"> > <data xmlns=""> > <col> > <coldata>datac1</coldata> > </col> > <col> > <coldata>datac2</coldata> > </col> > </data> > </xforms:instance> > </xforms:model> > </head> > <body> > <xforms:repeat id="rows" nodeset="instance('irows')/row"> > <div><xforms:output value="./rowdata"/></div> > <xforms:repeat id="cols" nodeset="instance('icols')/col"> > <div><xforms:output value="./coldata"/> > <br/> > Current row:<xforms:output value="index('rows')"/><br/> > Current col:<xforms:output value="index('cols')"/> > </div> > </xforms:repeat> > </xforms:repeat> > </body> > </html> > > I can see an issue with the index() function for the cols repeat because > clicking on the last column item in the second row does not have any effect > on this index. > > I think that it is because it is a cloned node and I can surely fix this. > > Are you in a hurry? > > -Alain > > |
From: Elias M. <eli...@gm...> - 2013-03-18 19:42:42
|
Alain and all. Related to my earlier posting for saving a value within a repeat...if you look at the code below, let's say that row and cols data are number and I want to display in red the cells in which the sum of the row and col is larger than 10 for example. For that I need to store the row value as I display the columns so I can add and check if it's greater than 10. How to do it? Thanks. Elias On Sun, Feb 24, 2013 at 4:35 PM, Alain Couthures < ala...@ag...> wrote: > Hello Elias, > > I'm trying to create a spreadsheet where the rows and columns are in >> separate instances, something like: >> >> <xf:instance id="rows"> >> <data xmlns=""> >> <row> >> <rowdata>stuff</rowdata> >> </row> >> <row> >> <rowdata>more stuff</rowdata> >> </row> >> ... >> ... >> </data> >> </xf:instance> >> >> <xf:instance id="cols"> >> <data xmlns=""> >> <col> >> <coldata>stuff</coldata> >> </col> >> <col> >> <coldata>more stuff</coldata> >> </col> >> ... >> ... >> </data> >> </xf:instance> >> >> <xf:repeat id="rows" nodeset="instance('rows')/row"> >> <div><xf:output value="./rowdata"/></div> >> <xf:repeat id="cols" nodeset="instance('cols')/col"> >> <div><xf:output value="./coldata"/> >> <xf:output value="index('rows')"/><br/> >> <xf:output value="index('cols')"/> >> </div> >> </xf:repeat> >> </xf:repeat> >> >> >> There are duplicate ids for instances and repeats and I have rewritten > this test case like this: > > <html xmlns:xforms="http://www.w3.org/2002/xforms" xmlns=" > http://www.w3.org/1999/xhtml" xmlns:xhtml="http://www.w3.org/1999/xhtml" > xmlns:ev="http://www.w3.org/2001/xml-events" xmlns:xsd=" > http://www.w3.org/2001/XMLSchema"> > <head> > <title>Indexes</title> > <xforms:model> > <xforms:instance id="irows"> > <data xmlns=""> > <row> > <rowdata>datar1</rowdata> > </row> > <row> > <rowdata>datar2</rowdata> > </row> > </data> > </xforms:instance> > <xforms:instance id="icols"> > <data xmlns=""> > <col> > <coldata>datac1</coldata> > </col> > <col> > <coldata>datac2</coldata> > </col> > </data> > </xforms:instance> > </xforms:model> > </head> > <body> > <xforms:repeat id="rows" nodeset="instance('irows')/row"> > <div><xforms:output value="./rowdata"/></div> > <xforms:repeat id="cols" nodeset="instance('icols')/col"> > <div><xforms:output value="./coldata"/> > <br/> > Current row:<xforms:output value="index('rows')"/><br/> > Current col:<xforms:output value="index('cols')"/> > </div> > </xforms:repeat> > </xforms:repeat> > </body> > </html> > > I can see an issue with the index() function for the cols repeat because > clicking on the last column item in the second row does not have any effect > on this index. > > I think that it is because it is a cloned node and I can surely fix this. > > Are you in a hurry? > > -Alain > > |