xquery:如何更改显示顺序

时间:2015-05-17 00:58:15

标签: xml xquery

- (void)viewDidLoad {
    //location manager set up etc...
    for (Object *object in allObjects){

        CLRegion *region = [self geofenceRegion:object];
        [locationManager startMonitoringForRegion:region];
     }
}

- (void)locationManager:(CLLocationManager *)manager didStartMonitoringForRegion:(CLRegion *)region {

    [self.locationManager performSelector:@selector(requestStateForRegion:) withObject:region afterDelay:5];
}

- (void)locationManager:(CLLocationManager *)manager
  didDetermineState:(CLRegionState)state forRegion:(CLRegion *)region {

    if (state == CLRegionStateInside){

        [self enterGeofence:region];

    } else if (state == CLRegionStateOutside){

        [self exitGeofence:region];

    } else if (state == CLRegionStateUnknown){
        NSLog(@"Unknown state for geofence: %@", region);
        return;
    }
}

- (void)enterGeofence:(CLRegion *)geofence {

    //whatever is required when entered
}

- (void)exitGeofence:(CLRegion *)geofence {

    //whatever is required when exit
}

我正在使用XQuery来搜索这个xml文件 我想一起显示“nom”和“departement”。例如,对于上面的这个xml文件,我想这样显示:

<base>
    <restaurant nom="la tour d'argent" etoile="3" ville="Paris">
        <fermeture>dimanche et lundi</fermeture>  
        <menu nom="buffet" prix="200"/>  
        <menu nom="gourmet" prix="300"/> 
      </restaurant>  
      <ville nom="Paris" departement="75"> 
        <plusBeauMonument nom="tour Eiffel" tarif="30"/> 
      </ville>
</base>

如你所见,“la tour d'Argent”的“ville”是“巴黎”。如果其“nom”也是“巴黎”,我们将采用其“部分”并将其显示为餐厅的“nom”。

这是我的xquery代码:

<restaurant nom="la tour d'argent" departement="75"/>

但是这段代码给了我一个结果:

for $r in //restaurant
for $v in //ville

return if($v/@nom=$r/@ville)
then <restaurant nom="{data($r/@nom)}" departement="{data($v/@departement)}"/>
else()
你看,订单不是我想要的。我想确保首先显示“nom”,但是“离开”现在是第一个。

你能帮帮我吗?

1 个答案:

答案 0 :(得分:0)

这是反直觉的,但是当我在then语句中切换属性时,我得到了正确的结果。

for $r in //restaurant
for $v in //ville

return if($v/@nom=$r/@ville)
then <restaurant departement="{data($v/@departement)}" nom="{data($r/@nom)}" />
else()