Xpath + repeat: noob inside

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

Xpath + repeat: noob inside

StephR
It's terrible how some times the simplest things won't work...

I repeat through all EU-Project and I would like to output the name of the project instead of only the id.

I have the following :

<instance id="profile-instance">
<Involvement>
  <EU-Projects>
    <EU-Project>
      <ProjectId>1</ProjectId>    
    </EU-Project>
    <EU-Project>
      <ProjectId>2</ProjectId>
    </EU-Project>
  </EU-Projects>
</Involvement>

<projects>
  <Project ProjectId="2">
    <ProjectAcronym>ALVIS</ProjectAcronym>
  </Project>
  <Project ProjectId="1">
    <ProjectAcronym>PALETTE</ProjectAcronym>
  </Project>
</projects>
</instance>

<xforms:group ref="instance('profile-instance')">
    <xforms:repeat id="EU-Project-repeat" nodeset="//EU-Projects/EU-Project">
        
    <xforms:output ref="//Project[@ProjectId = //EU-Project[index('EU-Project-repeat')]/ProjectId]/ProjectAcronym" />                                                      
    </xforms:repeat>
</xforms:group>


My ouput will always show the same project name, the first one, i.e. Alvis. How come ? My index is not right ?






--
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
Reply | Threaded
Open this post in threaded view
|

Re: Xpath + repeat: noob inside

Alexander Žaťko
1) I believe the instance must contain a single-rooted XML snippet. Yours has 2 roots.

2) instance needs to be prefixed <xforms:instance>

3) this path:

//Project[@ProjectId = //EU-Project[index('EU-Project-repeat')]/ProjectId]/ProjectAcronym

...is not going to work because the context node is:

instance('profile-instance')//EU-Projects/EU-Project

...and there are no descendants called "Project"

I re-factored your code - see attached.


On Dec 4, 2007, at 5:25 PM, Stephane Ruchet wrote:

It's terrible how some times the simplest things won't work...

I repeat through all EU-Project and I would like to output the name of the project instead of only the id.

I have the following :

<instance id="profile-instance">
<Involvement>
  <EU-Projects>
    <EU-Project>
      <ProjectId>1</ProjectId>&n! bsp;  nt>
    </EU-Project>
    <EU-Project>
      <ProjectId>2</ProjectId>
    </EU-Project>
  </EU-Projects>
</Involvement>

<projects>
  <Project ProjectId="2">
    <ProjectAcronym>ALVIS</ProjectAcronym>
  </Project>
  1">
    <ProjectAcronym>PALETTE</ProjectAcronym>
  </Project>
</projects>
</instance>

<xforms:group ref="instance('profile-instance')">
    <xforms:repeat id="EU-Project-repeat" nodeset="//EU-Projects/EU-Project">
        
    <xforms:output ref="//Project[@ProjectId = //EU-Project[index('EU-Project-repeat')]/ProjectId]/ProjectAcronym" />                                                     &! nbsp;
</xforms:group>


My ouput will always show the same project name, the first one, i.e. Alvis. How come ? My index is not right ?





--
You receive this message as a subscriber of the [hidden email] mailing list.
To unsubscribe: [hidden email]
For general help: [hidden email]
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

view.xhtml (1K) Download Attachment
Reply | Threaded
Open this post in threaded view
|

Re: Xpath + repeat: noob inside

StephR
Thanks Zatko for your response.

1 & 2 : my fault, I just copy-pasted the information that I thought was necessary for you... omitting other nodes. I just wanted to simplify it at a maximum. Sorry.

3 : hmmm at first I thought that I would have a context problem... but I tested with "static" inputs and it seemed working. Strange. Thanks for you code, I'm pretty surprised that this can be done so simply... I did not know that you could right xpath like this ...

Thanks !!!!

Steph



Alexander Zatko a écrit :
1) I believe the instance must contain a single-rooted XML snippet. Yours has 2 roots.

2) instance needs to be prefixed <xforms:instance>

3) this path:

//Project[@ProjectId = //EU-Project[index('EU-Project-repeat')]/ProjectId]/ProjectAcronym

...is not going to work because the context node is:

instance('profile-instance')//EU-Projects/EU-Project

...and there are no descendants called "Project"

I re-factored your code - see attached.






On Dec 4, 2007, at 5:25 PM, Stephane Ruchet wrote:

It's terrible how some times the simplest things won't work...

I repeat through all EU-Project and I would like to output the name of the project instead of only the id.

I have the following :

<instance id="profile-instance">
<Involvement>
  <EU-Projects>
    <EU-Project>
      <ProjectId>1</ProjectId>&n! bsp;  nt>
    </EU-Project>
    <EU-Project>
      <ProjectId>2</ProjectId>
    </EU-Project>
  </EU-Projects>
</Involvement>

<projects>
  <Project ProjectId="2">
    <ProjectAcronym>ALVIS</ProjectAcronym>
  </Project>
  1">
    <ProjectAcronym>PALETTE</ProjectAcronym>
  </Project>
</projects>
</instance>

<xforms:group ref="instance('profile-instance')">
    <xforms:repeat id="EU-Project-repeat" nodeset="//EU-Projects/EU-Project">
        
    <xforms:output ref="//Project[@ProjectId = //EU-Project[index('EU-Project-repeat')]/ProjectId]/ProjectAcronym" />                                                     &! nbsp;

</xforms:group>


My ouput will always show the same project name, the first one, i.e. Alvis. How come ? My index is not right ?





--
You receive this message as a subscriber of the [hidden email] mailing list.
To unsubscribe: [hidden email]
For general help: [hidden email]
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
Reply | Threaded
Open this post in threaded view
|

Re: Xpath + repeat: noob inside

Erik Bruchez
Administrator
Yes, XPath 2.0 is quite powerful. We can't live with it at Orbeon.

-Erik

On Dec 4, 2007, at 5:07 PM, Stephane Ruchet wrote:

> Thanks Zatko for your response.
>
> 1 & 2 : my fault, I just copy-pasted the information that I thought  
> was necessary for you... omitting other nodes. I just wanted to  
> simplify it at a maximum. Sorry.
>
> 3 : hmmm at first I thought that I would have a context problem...  
> but I tested with "static" inputs and it seemed working. Strange.  
> Thanks for you code, I'm pretty surprised that this can be done so  
> simply... I did not know that you could right xpath like this ...
>
> Thanks !!!!
>
> Steph
>
>
>
> Alexander Zatko a écrit :
>>
>> 1) I believe the instance must contain a single-rooted XML snippet.  
>> Yours has 2 roots.
>>
>> 2) instance needs to be prefixed <xforms:instance>
>>
>> 3) this path:
>>
>> //Project[@ProjectId = //EU-Project[index('EU-Project-repeat')]/
>> ProjectId]/ProjectAcronym
>>
>> ...is not going to work because the context node is:
>>
>> instance('profile-instance')//EU-Projects/EU-Project
>>
>> ...and there are no descendants called "Project"
>>
>> I re-factored your code - see attached.
>>
>>
>>
>>
>>
>> On Dec 4, 2007, at 5:25 PM, Stephane Ruchet wrote:
>>
>>> It's terrible how some times the simplest things won't work...
>>>
>>> I repeat through all EU-Project and I would like to output the  
>>> name of the project instead of only the id.
>>>
>>> I have the following :
>>>
>>> <instance id="profile-instance">
>>> <Involvement>
>>>   <EU-Projects>
>>>     <EU-Project>
>>>       <ProjectId>1</ProjectId>&n! bsp;  nt>
>>>     </EU-Project>
>>>     <EU-Project>
>>>       <ProjectId>2</ProjectId>
>>>     </EU-Project>
>>>   </EU-Projects>
>>> </Involvement>
>>>
>>> <projects>
>>>   <Project ProjectId="2">
>>>     <ProjectAcronym>ALVIS</ProjectAcronym>
>>>   </Project>
>>>   1">
>>>     <ProjectAcronym>PALETTE</ProjectAcronym>
>>>   </Project>
>>> </projects>
>>> </instance>
>>>
>>> <xforms:group ref="instance('profile-instance')">
>>>     <xforms:repeat id="EU-Project-repeat" nodeset="//EU-Projects/
>>> EU-Project">
>>>
>>>     <xforms:output ref="//Project[@ProjectId = //EU-
>>> Project[index('EU-Project-repeat')]/ProjectId]/ProjectAcronym" /
>>> >                                                     &! nbsp;
>>>
>>> </xforms:group>
>>>
>>>
>>> My ouput will always show the same project name, the first one,  
>>> i.e. Alvis. How come ? My index is not right ?
>>>
>>>
>>>
>>>
>>>
>>> --
>>> 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
--
Orbeon Forms - Web Forms for the Enterprise Done the Right Way
http://www.orbeon.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
Reply | Threaded
Open this post in threaded view
|

Re: Xpath + repeat: noob inside

StephR
Hé hé ... I see ;)

I'm still trying to understand how index(' ... ') in a repeat works :


<xforms:instance id="profile-instance">
                <EU-Projects>
                    <EU-Project>
                        <ProjectId>1</ProjectId>    
                    </EU-Project>
                    <EU-Project>
                        <ProjectId>2</ProjectId>
                    </EU-Project>
                </EU-Projects>
                <projects>
                    <Project ProjectId="2">
                            <ProjectAcronym>ALVIS</ProjectAcronym>
                            <WPs>
                                        <WP>
                                            <Title>Coordination</Title>
                                        </WP>
                                        <WP>
                                            <Title>Synergy Specification Plan - Participative Design</Title>
                                        </WP>
                                        [...]
                                   </WPs>
                         </Project>
                    <Project ProjectId="1">
                        <ProjectAcronym>PALETTE</ProjectAcronym>
                                   <WPs>
                                        <WP>
                                            <Title>Coordination</Title>
                                        </WP>
                                        <WP>
                                            <Title>Synergy Specification Plan - Participative Design</Title>
                                        </WP>
                                        [...]
                                   </WPs>
                    </Project>
                </projects>
</xforms:instance>

So I repeat on all the EU-Project. In every loop, I want to return the projectAcronym. This is done now successfully thanks to Alexander. Then always inside that loop, I wish to loop through all the WP of that project. So I just repeated what was done for the first repeat.

<xforms:repeat id="EU-Project-repeat" nodeset="//EU-Projects/EU-Project">
    <xforms:output ref="for $v in ProjectId return instance('profile-instance')//Project[@ProjectId = $v]/ProjectAcronym" /></h2>
    <br />
    <xforms:repeat id="WPs-repeat" nodeset="for $v in ProjectId return instance('profile-instance')//Project[@ProjectId = $v]/WPs/WP">
        <xforms:output ref="Title" />
     </xforms:repeat>
</xforms:repeat>


But isn't there a better way to do so ?




--
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
Reply | Threaded
Open this post in threaded view
|

Re: Xpath + repeat: noob inside

StephR
In reply to this post by Erik Bruchez
Mmmm maybe XPath is quite powerful, but it's giving me a headache :)

<xforms:instance id="test">
  <Involvement>
   <EU-Projects>
      <EU-Project>
        <ProjectId>1</ProjectId> 
        <WPs>
          <WP>
            <Number>0</Number> 
            <Tasks>
              <Task>1 3</Task>
            </Tasks>
          </WP>
          <WP>
            <Number>1</Number>
            <Tasks>
              <Task>1 2 3</Task>
            </Tasks>
          </WP>
        </WPs>
      </EU-Project>
    </EU-Projects>
  </Involvement>
 
 
 <Project ProjectId="1">
    <ProjectAcronym>PALETTE</ProjectAcronym>
    <WPs>
      <WP>
        <Number>0</Number>
        <Title>Coordination</Title>
        <Tasks>
          <Task>
            <TaskNo>1</TaskNo>
            <Name>Overall management</Name>
          </Task>
          <Task>
            <TaskNo>2</TaskNo>
            <Name>Management of intellectual property right</Name>
            </Task>
          <Task>
            <TaskNo>3</TaskNo>
            <Name>Assessment and Monitoring</Name>
          </Task>
        </Tasks>
      </WP>
      <WP>
        <Number>1</Number>
        <Title>Synergy Specification Plan - Participative Design</Title>
        <Tasks>
          <Task>
            <TaskNo>1</TaskNo>
            <Name>Establishment of a methodology based on an analysis grid</Name>
          </Task>
          <Task>
            <TaskNo>2</TaskNo>
            <Name>Categorisation of tools</Name>
          </Task>
          <Task>
            <TaskNo>3</TaskNo>
            <Name>Design of services and customisable scenarios</Name>
          </Task>
          <Task>
            <TaskNo>4</TaskNo>
            <Name>Validation</Name>
          </Task>
        </Tasks>
      </WP>
    </WPs>
  </Project>

Maybe complicated at first sight. There can be several projects, each projects is defined with serveral WPs. Every WPs can be then defined again with tasks (2nd part). The first part tells me what user is part of what project, and more specifically,  what tasks in what  WPs  he participates!

The following will give me for one project the list of WPs, and in it the list of all the tasks. The problem is that now I would like to recuperate the information concerning the user to see in what tasks he linked to. I showed below where I have a problem :

<xforms:group ref="instance('test')">
    <xforms:repeat id="EU-Project-repeat" nodeset="//EU-Projects/EU-Project">                       
       <h2><xforms:output ref="for $v in ProjectId return instance('test')//Project[@ProjectId = $v]/ProjectAcronym" /></h2>
       <br />
       <xforms:repeat id="WPs-repeat" nodeset="for $v in ProjectId return instance('test')//Project[@ProjectId = $v]/WPs/WP"> 
           <xforms:group appearance="xxforms:fieldset">
                <xforms:label ref="Title" />
                <xforms:select ref="." appearance="full">
<!-- Problem here -->
                    <xforms:itemset nodeset=".">
                        <xforms:label ref="Name"/>
                        <xforms:value ref="TaskNo"/>
                    </xforms:itemset>
                </xforms:select>
            </xforms:group>      
        </xforms:repeat>
    </xforms:repeat>
</xforms:group>

When I do the xforms:select, i'm in the context of Project/WPs/WP ... so I have to "get out" of it to go to Involvement/EU-Projects/EU-Project/WPs/WP/Tasks/Task. But how do I link the proper one with the actual context ? And once that is ok, I have to again reference to the proper label & value which is not in the same context of the ref just above. It's driving me nuts :). Any hints ?



--
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
Reply | Threaded
Open this post in threaded view
|

Re: Xpath + repeat: noob inside

StephR
Mmm XPath is powerful :)

This seems to work :

<xforms:repeat id="WPs-repeat" nodeset="for $v in ProjectId return instance('test')//Project[@ProjectId = $v]/WPs/WP">
  <div id="tasks">
    <xforms:group appearance="xxforms:fieldset">
      <xforms:label ref="Title" />
        <xforms:select ref="for $v in ../../@ProjectId, $z in Number return instance('test')//EU-Projects/EU-Project[ProjectId = $v]/WPs/WP[Number = $z]/Tasks/Task" appearance="full">
          <xforms:itemset nodeset="for $v in ../../../../ProjectId, $z in ../../Number return instance('test')//Project[@ProjectId = $v]/WPs/WP[Number = $z]/Tasks/Task">
            <xforms:label ref="Name"/>
            <xforms:value ref="TaskNo"/>
          </xforms:itemset>
        </xforms:select>
 
    </xforms:group>
  </div>       
</xforms:repeat>

So at least now I understand how to manage contexts... I have two last goals : try to find something nicer than "../../../../ProjectId" ... , and figure out how to do the following : as the ref in bold references a WP that has been declare in a user profile, if the user has nothing defined for it yet, he will not be able to add some tasks! Mmmm not very clear :

<ProjectId>1</ProjectId> 
        <WPs>
          <WP>
            <Number>0</Number> 
            <Tasks>
              <Task>1 3</Task>
            </Tasks>
          </WP>
          <WP>
            <Number>1</Number>
            <Tasks>
              <Task>1 2 3</Task>
            </Tasks>
          </WP>
        </WPs>

The user has only declared tasks for WP 0 et 1... so he will not see any WP 2 & 3 even though they are defined in the project (for example).  How can I  find a work around ?


Stephane Ruchet a écrit :
Mmmm maybe XPath is quite powerful, but it's giving me a headache :)

<xforms:instance id="test">
  <Involvement>
   <EU-Projects>
      <EU-Project>
        <ProjectId>1</ProjectId> 
        <WPs>
          <WP>
            <Number>0</Number> 
            <Tasks>
              <Task>1 3</Task>
            </Tasks>
          </WP>
          <WP>
            <Number>1</Number>
            <Tasks>
              <Task>1 2 3</Task>
            </Tasks>
          </WP>
        </WPs>
      </EU-Project>
    </EU-Projects>
  </Involvement>
 
 
 <Project ProjectId="1">
    <ProjectAcronym>PALETTE</ProjectAcronym>
    <WPs>
      <WP>
        <Number>0</Number>
        <Title>Coordination</Title>
        <Tasks>
          <Task>
            <TaskNo>1</TaskNo>
            <Name>Overall management</Name>
          </Task>
          <Task>
            <TaskNo>2</TaskNo>
            <Name>Management of intellectual property right</Name>
            </Task>
          <Task>
            <TaskNo>3</TaskNo>
            <Name>Assessment and Monitoring</Name>
          </Task>
        </Tasks>
      </WP>
      <WP>
        <Number>1</Number>
        <Title>Synergy Specification Plan - Participative Design</Title>
        <Tasks>
          <Task>
            <TaskNo>1</TaskNo>
            <Name>Establishment of a methodology based on an analysis grid</Name>
          </Task>
          <Task>
            <TaskNo>2</TaskNo>
            <Name>Categorisation of tools</Name>
          </Task>
          <Task>
            <TaskNo>3</TaskNo>
            <Name>Design of services and customisable scenarios</Name>
          </Task>
          <Task>
            <TaskNo>4</TaskNo>
            <Name>Validation</Name>
          </Task>
        </Tasks>
      </WP>
    </WPs>
  </Project>

Maybe complicated at first sight. There can be several projects, each projects is defined with serveral WPs. Every WPs can be then defined again with tasks (2nd part). The first part tells me what user is part of what project, and more specifically,  what tasks in what  WPs  he participates!

The following will give me for one project the list of WPs, and in it the list of all the tasks. The problem is that now I would like to recuperate the information concerning the user to see in what tasks he linked to. I showed below where I have a problem :

<xforms:group ref="instance('test')">
    <xforms:repeat id="EU-Project-repeat" nodeset="//EU-Projects/EU-Project">                       
       <h2><xforms:output ref="for $v in ProjectId return instance('test')//Project[@ProjectId = $v]/ProjectAcronym" /></h2>
       <br />
       <xforms:repeat id="WPs-repeat" nodeset="for $v in ProjectId return instance('test')//Project[@ProjectId = $v]/WPs/WP"> 
           <xforms:group appearance="xxforms:fieldset">
                <xforms:label ref="Title" />
                <xforms:select ref="." appearance="full">
<!-- Problem here -->
                    <xforms:itemset nodeset=".">
                        <xforms:label ref="Name"/>
                        <xforms:value ref="TaskNo"/>
                    </xforms:itemset>
                </xforms:select>
            </xforms:group>      
        </xforms:repeat>
    </xforms:repeat>
</xforms:group>

When I do the xforms:select, i'm in the context of Project/WPs/WP ... so I have to "get out" of it to go to Involvement/EU-Projects/EU-Project/WPs/WP/Tasks/Task. But how do I link the proper one with the actual context ? And once that is ok, I have to again reference to the proper label & value which is not in the same context of the ref just above. It's driving me nuts :). Any hints ?



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