Skip to main content
Question

XMLTemplater and string manipulations in XQuery ?

  • June 12, 2020
  • 2 replies
  • 26 views

lifalin2016
Supporter
Forum|alt.badge.img+38

Hi list.

When setting expressions in XMLTemplater for ROOT and various sub templates, one uses fme functions like "fme:has-attribute" and fme:get-attribute".

But is it possible to use string functions as well, e.g. to test the first character in a string retrieved by "fme:get-attribute" ? I can't seem to find any documentation about this with Safe.

I've found some string functions documented at Microsoft, e.g. https://docs.microsoft.com/en-us/sql/xquery/functions-on-string-values-substring?view=sql-server-ver15

Here a namespace of "fn" is used, but will that work in FME ?

And how do I wrap multiple function within each other ?

Is it { f1( f2() ) } or is it { f1( { f2() } ) } ?

Any insights will be appriciated.

Cheers.

This post is closed to further activity.
It may be an old question, an answered question, an implemented idea, or a notification-only post.
Please check post dates before relying on any information in a question or answer.
For follow-up or related questions, please post a new question or idea.
If there is a genuine update to be made, please contact us and request that the post is reopened.

2 replies

ebygomm
Influencer
Forum|alt.badge.img+44
  • Influencer
  • 3427 replies
  • June 12, 2020

You can test whether a retrieved value starts with a certain character/string and then return different outcomes dependent on whether this is true or false, e.g.

<data>
{
let $value :={
    fme:get-attribute("test")
    }
return if (fn:starts-with($value,"t"))
then $value
else "somethingelse"
</data>

 


takashi
Celebrity
  • 7843 replies
  • June 13, 2020
Is it { f1( f2() ) } or is it { f1( { f2() } ) } ?

Both are possible. Curly brackets are required to distinguish XQuery expression from literal value, but can be omitted in other cases.

Additionally, "fn:" (the namespace prefix for XQuery built-in functions) can also be omitted.

Try these three expressions, for example.

<data>{ replace({ substring('query', 3) }, 'e', 't') }</data>
<data>{ replace(substring('query', 3), 'e', 't') }</data>
<data>replace(substring('query', 3), 'e', 't')</data>