Hi @michaelz ,
Do you mean that a string literal like <p>@Value(insight_id)</p> is stored in a column of a DB record, and FME will read it then should replace with <p>123</p> if "insight_id" attribute stores 123 at run time?
Hi @michaelz ,
Do you mean that a string literal like <p>@Value(insight_id)</p> is stored in a column of a DB record, and FME will read it then should replace with <p>123</p> if "insight_id" attribute stores 123 at run time?
Hi @Takashi Iijima that is precisely what I’m after
Hi @Takashi Iijima that is precisely what I’m after
Thank you for confirmation.
A possible way I can think of is, extract pairs of "@Value(attribute name)" and "attribute name" as list attributes from the string literal with StringSearcher, and replace expression "@Value(attribute name)" with the value of an attribute called "attribute name" using a Python script (PythonCaller).
For example, if the input feature has attributes "html", "client_name", and "insight_id", and the "html" contains an HTML template containing the expressions "@Value(client_name)" and "@Value(insight_id)", the workflow looks like this.
StringSearcher setting:
- Search In: html
- Contains Regular Expression: @Value\((.+?)\)
- Case Sensitive: Yes
- All Matches List Name: _all
- Subexpression Matches List Name: _sub
PythonCaller script setting:
import fme
import fmeobjects
class FeatureProcessor(object):
def __init__(self):
pass
def input(self, feature):
html = feature.getAttribute('html')
expr = feature.getAttribute('_all{}.match')
attr = feature.getAttribute('_sub{}.part')
for e, a in zip(expr, attr):
html = html.replace(e, str(feature.getAttribute(a)))
feature.setAttribute('html', html)
self.pyoutput(feature)
def close(self):
pass
Hi @Takashi Iijima that is precisely what I’m after
Alternatively, this is a nice use case for the AttributeDereferencer.
The StringSearcher uses a regex subexpression to get the attribute name 'insight_id' in _SubResults{0}.part
I tried using StringReplacers or a StringPairReplacer, as it would make the process more clear, but the presence of '@Value' in the literal string makes it difficult to use those transformers.
Hi @Takashi Iijima that is precisely what I’m after
Thanks @Takashi Iijima works perfectly 😁