Skip to main content

I have an xml with the following structure:

 

<?xml version="1.0" encoding="UTF-16"?>
<Report>
<Category>
<Category Empty="10" Name="T" Type="Filter"></Category>
<Category Empty="30" Name="S" Type="Filter"></Category>
</Category>
<Fase>
<Fase Empty="1" Name="AO" Type="Filter"></Fase>
<Fase Empty="2" Name="VO" Type="Filter"></Fase>
<Fase Empty="3" Name="DO" Type="Filter"></Fase>
<Fase Empty="4" Name="UO" Type="Filter"></Fase>
</Fase>
<Imago>
<Imago Empty="1" Effect="Low risk" Score="1" Type="Quantifier"></Imago>
<Imago Empty="2" Effect="Moderate risk" Score="2" Type="Quantifier"></Imago>
<Imago Empty="3" Effect="High risk" Score="3" Type="Quantifier"></Imago>
<Imago Empty="4" Effect="Extreme risk" Score="4" Type="Quantifier"></Imago>
<Imago Empty="5" Effect="None" Score="0" Type="Quantifier"></Imago>
<Imago Empty="6" Effect="Little chance" Score="-1" Type="Quantifier"></Imago>
<Imago Empty="7" Effect="Moderate chance" Score="-2" Type="Quantifier"></Imago>
<Imago Empty="8" Effect="High chance" Score="-3" Type="Quantifier"></Imago>
<Imago Empty="9" Effect="Extreme chance" Score="-4" Type="Quantifier"></Imago>
</Imago>
<Chance>
<Chance Empty="1" Effect="None" Score="0" Type="Likelihood">
<_max_ Max_="6"></_max_>
</Chance>
<Chance Empty="2" Effect="Less" Score="1" Type="Likelihood">
<_max_ Max_="7"></_max_>
</Chance>
<Chance Empty="3" Effect="Moderate" Score="2" Type="Likelihood">
<_max_ Max_="8"></_max_>
</Chance>
<Chance Empty="4" Effect="Most" Score="3" Type="Likelihood">
<_max_ Max_="6"></_max_>
</Chance>
</Chance>
</Report>

I wan't to transform this to a table like this:

Type|Name|Value
Filter|Category|T
Filter|Category|S
Filter|Category|AO
Filter|Category|VO
Filter|Category|DO
Filter|Category|UO
Quantifier|Category|Low risk
Quantifier|Category|Moderate risk
Quantifier|Category|High risk
Quantifier|Category|Extreme risk
Quantifier|Category|None
Quantifier|Category|Little chance
Quantifier|Category|Moderate change
Quantifier|Category|High chance
Quantifier|Category|Extreme chance
Likelihood|Category|None
Likelihood|Category|Less
Likelihood|Category|Moderate
Likelihood|Category|Most

But the problem is I don't know the names of all the filters and all the quantifiers on forehand.

 

So I don't know the names of the elements in the xml. I only know they have an attribute Type with a value 'Filter/Quantifier/Likelihood'

 

I expect that I need to use a XMLXQueryExtractor with this setting:

 

for $x in /Report
return $x/*/*/@Type

Or something like that

 

Can someone help me with my workbench?

 

I'm a little confused by why all the names are Category in your example output. In the example below the Name field is populated by the node name

Type Name Value

Filter Category T

Filter Category S

Filter Fase AO

Filter Fase VO

Filter Fase DO

Filter Fase UO

Quantifier Imago Low risk

Quantifier Imago Moderate risk

Quantifier Imago High risk

Quantifier Imago Extreme risk

Quantifier Imago None

Quantifier Imago Little chance

Quantifier Imago Moderate chance

Quantifier Imago High chance

Quantifier Imago Extreme chance

Likelihood Chance None

Likelihood Chance Less

Likelihood Chance Moderate

Likelihood Chance Most

 

 

I tried to do this in an single XMLXQueryExploder but it populated the last element in all the attributes. Separating it into an exploder followed by an extractor worked.

XMLXQueryExploder: /Report/*/*

XMLXQueryExtractor: let $r:= /*

return {fme:set-attribute("Type", data($r/@Type)),fme:set-attribute("Name", name($r)),fme:set-attribute("Value", data($r/@*@2]))}

 

See attached workspace.

 


Thanks, it was my copy paste sloppyness. Indeed I wanted the Name Field to be filled by the Node Name. I noticed you filled the value field with the value of the second attribute. Nice example. I rewrote this so it set the value with the value of the Name Attribute and another attribute with the value of the Filter attribute. But your example made it very clear that the other option was also possible.


Thanks, it was my copy paste sloppyness. Indeed I wanted the Name Field to be filled by the Node Name. I noticed you filled the value field with the value of the second attribute. Nice example. I rewrote this so it set the value with the value of the Name Attribute and another attribute with the value of the Filter attribute. But your example made it very clear that the other option was also possible.

I did that because on the filter type nodes the value was in the name attribute, whereas the other nodes the value was in the effect attribute, and I didn't want to bother with conditionals.


Reply