Solved

Seperate a single field values into two xml elements??

  • 12 September 2017
  • 3 replies
  • 2 views

Badge

Hello Everyone, I have a field which contains table and column name together for Foreignkey using (,) and (#) seperators. I have created also List on this field already, now i am not understanding how I can make another list for getting those values.

Now my result XML is looking like :

bnr:table > element is getting all the table and column names now, but i want to see my XML as follows:

A partial coding of my XML template is as follows:

<bnr:MD_DataSchema>

 

{

 

let $n := xs:integer(fme:get-attribute("_element_count")) - 1

 

for $i in (0 to $n)

 

 

let $aname := "_list_name{"||$i||"}.Spalte"

 

let $atype := "_list_name{"||$i||"}.Datentyp"

 

let $descrip := "_list_name{"||$i||"}.Beschreibung"

 

let $fkey := "_list_name{"||$i||"}.Tabellenbeziehung"

 

let $mval := "_list_name{"||$i||"}.Fehlende_Werte"

 

 

return

 

{

 

if (not(fme:get-attribute($aname) eq "")) then

 

<bnr:column>

 

<bnr:MD_Column>

 

<bnr:tableName>

 

<gco:CharacterString>v140_mun.dbo.{fme:get-attribute("Tabelle")}</gco:CharacterString>

 

</bnr:tableName>

 

 

<bnr:name>

 

 

<gco:CharacterString>{fme:get-attribute($aname)}</gco:CharacterString>

 

</bnr:name>

 

{

 

if (not(fme:get-attribute($descrip) eq "")) then

 

<bnr:description>

 

<gco:CharacterString>{fme:get-attribute($descrip)}</gco:CharacterString>

 

 

</bnr:description>

 

else(<bnr:description>

 

<gco:CharacterString>No description</gco:CharacterString>

 

 

</bnr:description>

 

)

 

 

}

 

<bnr:dataType>

 

<gco:CharacterString>{fme:get-attribute($atype)}</gco:CharacterString>

 

</bnr:dataType>

 

{

 

if (not(fme:get-attribute($mval) eq "")) then

 

<bnr:missingValue>

 

<gco:CharacterString>{fme:get-attribute($mval)}</gco:CharacterString>

 

</bnr:missingValue>

 

else(<bnr:missingValue>

 

<gco:CharacterString>No Missing Value</gco:CharacterString>

 

</bnr:missingValue>

 

)

 

}

 

{

 

if (not(fme:get-attribute($fkey)eq "")) then

 

 

<bnr:foreignKey>

 

<bnr:MD_ForeignKey>

 

<bnr:identifier>

 

<gmd:MD_Identifier>

 

<gmd:code>

 

<gco:CharacterString></gco:CharacterString>

 

</gmd:code>

 

</gmd:MD_Identifier>

 

</bnr:identifier>

 

 

 

<bnr:table>

 

<gco:CharacterString>{fme:get-attribute($fkey)}</gco:CharacterString>

 

</bnr:table>

 

 

 

<bnr:column>

 

<gco:CharacterString></gco:CharacterString>

 

</bnr:column>

 

</bnr:MD_ForeignKey>

 

</bnr:foreignKey>

 

else ()

 

}

 

</bnr:MD_Column>

 

</bnr:column>

 

 

else ()

 

}

 

}
icon

Best answer by takashi 12 September 2017, 16:03

View original

3 replies

Badge
@takashi

 

 

Userlevel 2
Badge +17

Hi @mjoarder_pln, you can use the XQuery "fn:tokenize" function to split a string. For example, the partial expression that creates <bnr:foreignKey> elements can be replaced with this expression. Note: <bnr:foreignKey> elements would not be created if fme:get-attribute($fkey) was empty.

{
    for $k in fn:tokenize(fme:get-attribute($fkey), '#')
    let $s := fn:tokenize($k, ',')
    return
    <bnr:foreignKey>
        <bnr:MD_ForeignKey>
            <bnr:identifier>
                <gmd:MD_Identifier>
                    <gmd:code>
                        <gco:CharacterString></gco:CharacterString>
                    </gmd:code>
                </gmd:MD_Identifier>
            </bnr:identifier>
            <bnr:table>
                <gco:CharacterString>{$s[1]}</gco:CharacterString>
            </bnr:table>
            <bnr:column>
                <gco:CharacterString>{$s[2]}</gco:CharacterString>
            </bnr:column>
        </bnr:MD_ForeignKey>
    </bnr:foreignKey>
}

Hope this helps.

Badge

Hi @mjoarder_pln, you can use the XQuery "fn:tokenize" function to split a string. For example, the partial expression that creates <bnr:foreignKey> elements can be replaced with this expression. Note: <bnr:foreignKey> elements would not be created if fme:get-attribute($fkey) was empty.

{
    for $k in fn:tokenize(fme:get-attribute($fkey), '#')
    let $s := fn:tokenize($k, ',')
    return
    <bnr:foreignKey>
        <bnr:MD_ForeignKey>
            <bnr:identifier>
                <gmd:MD_Identifier>
                    <gmd:code>
                        <gco:CharacterString></gco:CharacterString>
                    </gmd:code>
                </gmd:MD_Identifier>
            </bnr:identifier>
            <bnr:table>
                <gco:CharacterString>{$s[1]}</gco:CharacterString>
            </bnr:table>
            <bnr:column>
                <gco:CharacterString>{$s[2]}</gco:CharacterString>
            </bnr:column>
        </bnr:MD_ForeignKey>
    </bnr:foreignKey>
}

Hope this helps.

Hi , Takashi, it works ! great, thanks a lot !

 

 

 

Reply