Skip to main content

I'm constructing an XML query for a WFS service by using an XMLTemplater. The ROOT element is this:

<Filter>
<Or>
{fme:process-features("SUB")}
</Or>
</Filter>

And the SUB element, per feature, is this

<PropertyIsEqualTo><PropertyName>identificatie</PropertyName><Literal>{fme:get-attribute("bag_vbo_id")}</Literal></PropertyIsEqualTo>

Store in an attribute then use that feature to trigger a FeatureReader and use the query attribute. This works fine and results in a working query. Except when there's only one feature, in that case the WFS service seems to bork about the unnecessary <Or> </Or> tags.

My workaround:

  1. StringSearcher to count the number of times </PropertyIsEqualTo> occurs (i.e. the number of sub elements)
  2. ListElementCounter on the list of matches
  3. TestFilter to test for the number of elements
  4. If 1 StringReplacer to replace the <Or> and </Or> with empty strings

I can't help but think there's got to be an easier way to do this... I could combine steps 3 and 4 in one conditional value, saving me one transformer, but it still amounts to the same thing really. Any other suggestions?

Hoi @redgeographics,

Would the BAG API be an option? I usually use that and not the WFS service.


Hoi @redgeographics,

Would the BAG API be an option? I usually use that and not the WFS service.

I am actually using that later on in the process, it's certainly worth looking into but I'm not sure how well it will work when you need to query a few hundred features.

The irony is that the chance of my user ever querying just one feature is very small, but I can't have the workbench fail on that of course.


I am actually using that later on in the process, it's certainly worth looking into but I'm not sure how well it will work when you need to query a few hundred features.

The irony is that the chance of my user ever querying just one feature is very small, but I can't have the workbench fail on that of course.

I don't see the problem with querying a couple of hundred records (just did that for a client with a few thousands queries)


Can you do something like in the root element?

<Filter>
{
let $sub :={
    fme:process-features("SUB")
}
return if (1 < fn:count($sub/Literal))
then <Or>{$sub}</Or>
else {$sub}
}
</Filter>

 

 


Can you do something like in the root element?

<Filter>
{
let $sub :={
    fme:process-features("SUB")
}
return if (1 < fn:count($sub/Literal))
then <Or>{$sub}</Or>
else {$sub}
}
</Filter>

 

 

Yes, that does the trick, thanks!


Reply