Skip to main content
The full answer to this might ba a bit big for here but any tips on what transformers to use and how to get things to group up would be great, I just need to get started then I can probably figure the rest out. I am trying to generate an XML fragment. So far I have got my data in the following format, 14 features with 2 attributes

 

 

Group  Name

 

01       01 - ID prod lights

 

01       01 - ID  prod buoys

 

01       01 - ID prod achare

 

02       02 - ID insert lights

 

02       02 - ID insert buoys

 

03       03 - ID move lights

 

03       03 - ID move buoys

 

03       03 - ID move achare

 

04       04 - ID del lights

 

04       04 - ID del achare

 

05       05 - global deletes

 

06       06 - decide lights

 

06       06 - decide buoys

 

 

The XML I am trying to generate would look like this

 

 

<ApplyActionsTask>

 

    <label>01</label>

 

        <action>01 - ID prod lights</action>

 

        <action>01 - ID prod buoys</action>

 

        <action>01 - ID prod achare</action>

 

</ApplyActionsTask>

 

<ApplyActionsTask>

 

    <label>02</label>

 

        <action>02 - ID insert lights</action>

 

        <action>02 - ID insert buoys</action>

 

</ApplyActionsTask>

 

<ApplyActionsTask>

 

    <label>03</label>

 

        <action>03 - ID move lights</action>

 

        <action>03 - ID move buoys</action>

 

        <action>03 - ID move achare</action>

 

</ApplyActionsTask>

 

<ApplyActionsTask>

 

    <label>04</label>

 

        <action>04 - ID del lights</action>

 

        <action>04 - ID del achare</action>

 

</ApplyActionsTask>

 

<ApplyActionsTask>

 

    <label>05</label>

 

        <action>05 - global deletes</action>

 

</ApplyActionsTask>

 

<ApplyActionsTask>

 

    <label>06</label>

 

        <action>06 - decide lights</action>

 

        <action>06 - decide buoys</action>

 

</ApplyActionsTask>

 

 

I am just struggling with how to get things to group up in the right way and eventually generate a single feature containing the XML above in an attribut so I can insert it into a soap message using XML appender.

 

The number of items in each group is variable and also the number of groups is variable. I think the answer will need some kind of loop and custom transformer but not entirely sure yet.

 

 

Any help much appreciated.

 

 

Jim
Hi Jim,

 

 

It may not be a long story. A possible way is:

 

 

Aggreate the features grouping by "Group" to create a list attribute that contains "Name" values for each group. You can use the ListBuilder or the Aggregator to do that.

 

 

Then, use the XMLTemplater to create "ApplyActionsTask" elements. Assuming that the list name is "_list{}.Name", this template expression works.

 

----

 

<ApplyActionsTask>

 

<label>{fme:get-attribute("Group")}</label>

 

{

 

for $name in fme:get-list-attribute("_list{}.Name")

 

return <action>{$name}</action>

 

}

 

</ApplyActionsTask>

 

----

 

 

Finally, create a complete XML document by collecting the elements. e.g. the XMLAppender can be used.

 

 

Takashi
That worked nicely, thanks Takashi.

 

 

Aggregator was what I was after and the loop in the templater was very usefull, I wasnt familiar with the syntax for that but I will find that most usefull in other areas too.

 

 

Thanks for the help, its really helped me move forward with my project.

 

 

Jim
Hi Jim,

 

 

It may not be a long story. A possible way is:

 

 

Aggreate the features grouping by "Group" to create a list attribute that contains "Name" values for each group. You can use the ListBuilder or the Aggregator to do that.

 

 

Then, use the XMLTemplater to create "ApplyActionsTask" elements. Assuming that the list name is "_list{}.Name", this template expression works.

 

----

 

<ApplyActionsTask>

 

<label>{fme:get-attribute("Group")}</label>

 

{

 

for $name in fme:get-list-attribute("_list{}.Name")

 

return <action>{$name}</action>

 

}

 

</ApplyActionsTask>

 

----

 

 

Finally, create a complete XML document by collecting the elements. e.g. the XMLAppender can be used.

 

 

Takashi
That worked nicely, thanks Takashi.

 

 

Aggregator was what I was after and the loop in the templater was very usefull, I wasnt familiar with the syntax for that but I will find that most usefull in other areas too.

 

 

Thanks for the help, its really helped me move forward with my project.

 

 

Jim

Reply