I am trying to iterate over XML with this structure:
<Query id="Y120-M2-D1-H8-M42-S12-MS276-6676" name="Transactions_ModelGenerator_v_1.0.0.104">
<Description />
<Columns>
<Column caption="Client Code" sorting="None" sortIndex="-1">
<Expr class="ENTATTR" id="c.Number" />
</Column>
<Column caption="Client Name" sorting="None" sortIndex="-1">
<Expr class="ENTATTR" id="c.Name" />
</Column>
<Column caption="Market Code" sorting="None" sortIndex="-1">
<Expr class="ENTATTR" id="r.Number" />
</Column>
<Column caption="Market Name" sorting="None" sortIndex="-1">
<Expr class="ENTATTR" id="r.Name" />
</Column>
</Columns>
<JustSortedColumns />
<Conditions linking="All">
<Condition class="SMPL" enabled="True" readOnly="False">
<Operator id="Equal" />
<Expressions>
<Expr class="ENTATTR" id="c.Number" />
<Expr class="CONST" type="String" kind="Scalar" value="A1B" text="A1B" />
</Expressions>
</Condition>
<Condition class="SMPL" enabled="True" readOnly="False">
<Operator id="Equal" />
<Expressions>
<Expr class="ENTATTR" id="ConversionCurrency" />
<Expr class="CONST" type="String" kind="Scalar" value="EUR" text="EUR" />
</Expressions>
</Condition>
</Conditions>
</Query>
I want to loop through the Columns, and replace certain keywords, specifically the caption attribute. For example, I want to replace keyword "Client" with "Cedent".
I've tried writing something like this:
update #data
set data.modify('
for $col in /Query/Columns[1]/Column/caption
replace value of $col with fn:replace($col, "Client", "Cedent")
where fn:contains($col, "Client")
')
But of course I'm getting errors I'm not sure how to work around:
XQuery [#data.data.modify()]: Syntax error near 'replace', expected 'where', '(stable) order by' or 'return'.
I'm not very familiar with XQuery. Can somebody help me here?