Hello
I try to use context() in xforms:repeat section to print out a text belonging to a index of the repeated data: <xforms:instance id="text-instance"> <texts> <hellotexts> <hellotext>Hello Nr 1</hellotext> <hellotext>Hello Nr 2</hellotext> <hellotext>Hello Nr 3</hellotext> </hellotexts> </texts> </xforms:instance> <xforms:instance id="test-instance"> <test> <index>1</index> <text>Test 1</text> <index>2</index> <text>Test 2</text> <index>3</index> <text>Test 3</text> </test> </xforms:instance> <xforms:repeat nodeset="instance('test-instance')/a"> ... <xforms:output ref="instance('text-instance')/hellotexts/hellotext[context()/index]" /> ... </xforms:repeat> The output of "context()/index" in the repeat section is 1, 2, 3 like expected, but why does $text/hellotexts/hellotext[context()/index] always print out the text belonging to index 1 like $text/hellotexts/hellotext[1]? I don't know if that is a bug? Thank you very much for your help, Karolin <?xml version="1.0" encoding="ISO-8859-1"?> <xhtml:html xmlns:ev="http://www.w3.org/2001/xml-events" xmlns:f="http://orbeon.org/oxf/xml/formatting" xmlns:xforms="http://www.w3.org/2002/xforms" xmlns:xhtml="http://www.w3.org/1999/xhtml" xmlns:xxforms="http://orbeon.org/oxf/xml/xforms"> <xhtml:head> <xhtml:title /> <xforms:model id="text-model"> <xforms:instance id="text-instance"> <texts> <hellotexts> <hellotext>Hello Nr 1</hellotext> <hellotext>Hello Nr 2</hellotext> <hellotext>Hello Nr 3</hellotext> </hellotexts> </texts> </xforms:instance> </xforms:model> <xforms:model id="test-model"> <xforms:instance id="test-instance"> <test> <index>1</index> <text>Test 1</text> <index>2</index> <text>Test 2</text> <index>3</index> <text>Test 3</text> </test> </xforms:instance> </xforms:model> </xhtml:head> <xhtml:body> <xxforms:variable model="test-model" name="test" select="instance('test-instance')" /> <xxforms:variable model="text-model" name="text" select="instance('text-instance')" /> <xforms:repeat nodeset="$test/a"> <xhtml:table> <xhtml:tr> <xhtml:td> <p> <xforms:output ref="$text/hellotexts/hellotext[context()/index]" /> </p> </xhtml:td> </xhtml:tr> <xhtml:tr> <xhtml:td> <xforms:input ref="context()/index"><xforms:label>index</xforms:label></xforms:input> </xhtml:td> </xhtml:tr> <xhtml:tr> <xhtml:td> <xforms:input ref="text"><xforms:label>text</xforms:label></xforms:input> </xhtml:td> </xhtml:tr> </xhtml:table> </xforms:repeat> Test output all texts: <xhtml:table> <xhtml:tr> <xhtml:td> <p><xforms:output ref="$text/hellotexts/hellotext[1]" /></p> </xhtml:td> </xhtml:tr> <xhtml:tr> <xhtml:td> <p><xforms:output ref="$text/hellotexts/hellotext[2]" /></p> </xhtml:td> </xhtml:tr> <xhtml:tr> <xhtml:td> <p><xforms:output ref="$text/hellotexts/hellotext[3]" /></p> </xhtml:td> </xhtml:tr> </xhtml:table> </xhtml:body> </xhtml:html> |
Administrator
|
Karolin,
This is an easy one. It's due to the 2 types of predicates in XPath: numerical, and boolean. foo[2] returns the second foo element foo[bar = 42] returns the foo elements satisfying the boolean condition Now what does foo[bar] mean? You would think that if bar contains a number, like <bar>2</bar>, it would work as a numerical predicate. But it doesn't: it behaves as a boolean predicate, where the boolean condition is simply "bar", which means "does an element call bar exist". Since yes, the first such element found is returned. To fix this, force the predicate to be numerical: <xforms:output ref="$text/hellotexts/hellotext[xs:integer(context()/index)]"/> -Erik On Wed, Sep 15, 2010 at 9:29 AM, Karolin Krieg <[hidden email]> wrote: > > Hello > > I try to use context() in xforms:repeat section to print out a text > belonging to a index of the repeated data: > > <xforms:instance id="text-instance"> > <texts> > <hellotexts> > <hellotext>Hello Nr 1</hellotext> > <hellotext>Hello Nr 2</hellotext> > <hellotext>Hello Nr 3</hellotext> > </hellotexts> > </texts> > </xforms:instance> > <xforms:instance id="test-instance"> > <test> > > <index>1</index> > <text>Test 1</text> > > > <index>2</index> > <text>Test 2</text> > > > <index>3</index> > <text>Test 3</text> > > </test> > </xforms:instance> > > <xforms:repeat nodeset="instance('test-instance')/a"> > ... > <xforms:output > ref="instance('text-instance')/hellotexts/hellotext[context()/index]" /> > ... > </xforms:repeat> > > The output of "context()/index" in the repeat section is 1, 2, 3 like > expected, but why does $text/hellotexts/hellotext[context()/index] always > print out the text belonging to index 1 like $text/hellotexts/hellotext[1]? > > I don't know if that is a bug? > Thank you very much for your help, > > Karolin > > > > <?xml version="1.0" encoding="ISO-8859-1"?> > <xhtml:html > xmlns:ev="http://www.w3.org/2001/xml-events" > xmlns:f="http://orbeon.org/oxf/xml/formatting" > xmlns:xforms="http://www.w3.org/2002/xforms" > xmlns:xhtml="http://www.w3.org/1999/xhtml" > xmlns:xxforms="http://orbeon.org/oxf/xml/xforms"> > <xhtml:head> > <xhtml:title /> > <xforms:model id="text-model"> > <xforms:instance id="text-instance"> > <texts> > <hellotexts> > <hellotext>Hello Nr 1</hellotext> > <hellotext>Hello Nr 2</hellotext> > <hellotext>Hello Nr 3</hellotext> > </hellotexts> > </texts> > </xforms:instance> > </xforms:model> > <xforms:model id="test-model"> > <xforms:instance id="test-instance"> > <test> > > <index>1</index> > <text>Test 1</text> > > > <index>2</index> > <text>Test 2</text> > > > <index>3</index> > <text>Test 3</text> > > </test> > </xforms:instance> > </xforms:model> > </xhtml:head> > <xhtml:body> > <xxforms:variable model="test-model" name="test" > select="instance('test-instance')" /> > <xxforms:variable model="text-model" name="text" > select="instance('text-instance')" /> > <xforms:repeat nodeset="$test/a"> > <xhtml:table> > <xhtml:tr> > <xhtml:td> > <p> > <xforms:output ref="$text/hellotexts/hellotext[context()/index]" /> > </p> > </xhtml:td> > </xhtml:tr> > <xhtml:tr> > <xhtml:td> > <xforms:input > ref="context()/index"><xforms:label>index</xforms:label></xforms:input> > </xhtml:td> > </xhtml:tr> > <xhtml:tr> > <xhtml:td> > <xforms:input > ref="text"><xforms:label>text</xforms:label></xforms:input> > </xhtml:td> > </xhtml:tr> > </xhtml:table> > </xforms:repeat> > Test output all texts: > <xhtml:table> > <xhtml:tr> > <xhtml:td> > <p><xforms:output ref="$text/hellotexts/hellotext[1]" /></p> > </xhtml:td> > </xhtml:tr> > <xhtml:tr> > <xhtml:td> > <p><xforms:output ref="$text/hellotexts/hellotext[2]" /></p> > </xhtml:td> > </xhtml:tr> > <xhtml:tr> > <xhtml:td> > <p><xforms:output ref="$text/hellotexts/hellotext[3]" /></p> > </xhtml:td> > </xhtml:tr> > </xhtml:table> > </xhtml:body> > </xhtml:html> > -- > View this message in context: http://orbeon-forms-ops-users.24843.n4.nabble.com/Problems-with-context-in-xforms-repeat-tp2540835p2540835.html > Sent from the Orbeon Forms (ops-users) mailing list archive at Nabble.com. > > > -- > 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 > OW2 mailing lists service home page: http://www.ow2.org/wws > > -- 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 OW2 mailing lists service home page: http://www.ow2.org/wws |
Free forum by Nabble | Edit this page |