How to create a combined xpath expression

Posted by Heinrich Götzger on
URL: https://discuss.orbeon.com/How-to-create-a-combined-xpath-expression-tp3027887.html

Hi,

I try to find a way to build a xpath-expression which will be created
within a repeat-loop dynamically during page creation. But this seems
not working for some reason.

The goal is to get a dynamic data structure displayed in a table.

An example of my xhtml-file is at the end of the mail.

Now I get a table like this (the second column ref is for testing only)
(not OK):

item: 1
label: Label A Label B Label C Label D ref: A value: 10
label: Label A Label B Label C Label D ref: B value: value B
label: Label A Label B Label C Label D ref: C value: C
item: 2
label: Label A Label B Label C Label D ref: A value: 10
label: Label A Label B Label C Label D ref: C value: C
label: Label A Label B Label C Label D ref: D value: value D


But I want a table like this
(OK):

item: 1
label: Label A value: 10
label: Label B value: value B
label: Label C value: C
item: 2
label: Label A value: 10
label: Label C value: C
label: Label D value: value D


I'm not sure how to write the xpath expression to get the desired label
from my labels-instance which matches the value-item in the table.

The construct for the label-column is not working as expected.
Why?

Where can I get more information on how to get this running?

How can I build the xpath from the fixed part 'instance('labels')/item'
and the changing part from the valueTag?

What I get is either _all_ labels at once or just the tag-name, but not
the text of my label-tag.

Thanks for ideas

Cheers

Heinrich

----8< ---- 8< ------
<?xml version="1.0" encoding="UTF-8"?>

<xhtml:html xmlns:xhtml="http://www.w3.org/1999/xhtml"
        xmlns:xf="http://www.w3.org/2002/xforms"
xmlns:xxforms="http://orbeon.org/oxf/xml/xforms">

        <xhtml:head>

                <xf:model id="table-model">

                        <xf:instance id="content">
                                <document>
                                        <items>
                                                <item>
                                                        <A>10</A>
                                                        <B>value B</B>
                                                        <C>C</C>
                                                </item>
                                                <item>
                                                        <A>10</A>
                                                        <C>C</C>
                                                        <D>value D</D>
                                                </item>
                                        </items>
                                </document>
                        </xf:instance>

                        <xf:instance id="labels">
                                <items>
                                        <A>Label A</A>
                                        <B>Label B</B>
                                        <C>Label C</C>
                                        <D>Label D</D>
                                </items>
                        </xf:instance>

                </xf:model>

        </xhtml:head>

        <xhtml:body>

                <xf:group ref="instance('content')">
                        <xf:repeat nodeset="items/item" id="repeat-item">
                                <!-- outer table; contains all items -->
                                <xhtml:table>
                                        <!-- first row, contains the header -->
                                        <xhtml:tr>
                                                <xhtml:td>
                                                        <xf:output value="position()">
                                                                <xf:label>item: </xf:label>
                                                        </xf:output>
                                                </xhtml:td>
                                        </xhtml:tr>

                                        <!-- second row, contains the items -->
                                        <xhtml:tr>
                                                <xhtml:td>
                                                        <!-- inner table; one table per item -->
                                                        <xhtml:table width="600px" style="border: solid black 1px;">
                                                                <xf:repeat nodeset="./*[node()]" id="table-item">
                                                                        <xxforms:variable model="table-model" name="valueTag"
                                                                                select="name(.)" />
                                                                        <xxforms:variable model="table-model" name="labelTag"
                                                                                select="instance('labels')/item" />

                                                                        <xhtml:tr>
                                                                                <xhtml:td>

                                                                                        <xf:group ref="instance('labels')">

                                                                                                <xxforms:variable model="table-model" name="label"
                                                                                                        select="instance('labels')/items/$valueTag" />

                                                                                                <xf:output select="$label/$valueTag">
                                                                                                        <xf:label>label: </xf:label>
                                                                                                </xf:output>

                                                                                                <xf:output ref="$valueTag">
                                                                                                        <xf:label>ref: </xf:label>
                                                                                                </xf:output>

                                                                                        </xf:group>
                                                                                </xhtml:td>

                                                                                <xhtml:td>
                                                                                        <xf:output select="$valueTag">
                                                                                                <xf:label>value: </xf:label>
                                                                                        </xf:output>
                                                                                </xhtml:td>

                                                                        </xhtml:tr>
                                                                </xf:repeat>
                                                        </xhtml:table>

                                                </xhtml:td>
                                        </xhtml:tr>

                                </xhtml:table>
                        </xf:repeat>
                </xf:group>

        </xhtml:body>

</xhtml:html>

----8< ---- 8< ------


--
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