mappingxqueryosbname-value

Xquery to map the value of a specific name attribute


I am trying to create an xquery in jdeveloper . I am stuck at a small portion of it. It would be great if I get some suggestions. Below is the part I am stuck at

The request is:

`<variables>
  <variable name="StartTime" value="01:00:00"/>
 <variable name= "EndTime" value="05:00:00"/>

The response I want to map is a single element with two values looks like below:

<ns2:time ns2:startTime="01:00:00" ns2:endTime="05:00:00"/>

Below is the xquery I tried. But I get only the start time at both places. I want some way by which I can correctly assign the values looking at the name value in the request.

  if (fn:data($Prefereces/ns1:variables/ns1:variable/@name="StartTime")or fn:data($Prefereces/ns1:variables/ns1:variable/@name="EndTime")) then
                   ( <ns2:time ns2:startTime="{fn:data($Prefereces/ns1:variables/ns1:variable/@value)}" ns2:endTime="{fn:data($Prefereces/ns1:variables/ns1:variable/@value)}">
                    </ns2:time>)
                else
                    ()

Thanks in advance.


Solution

  • You can use this :

    <ns2:time ns2:startTime="{fn:data($Prefereces/variables/variable[@name = 'StartTime']/@value)}" ns2:endTime="{fn:data($Prefereces/variables/variable[@name = 'EndTime']/@value)}"/>
    

    Note that the ns2 prefix has to be defined beforehand.

    XQuery's predicates are specified using brackets ([condition]), which were missing from your tries.