Comments and answers for "Update values in xml with conditionals" https://knowledge.亚搏在线safe.com/questions/72774/update-values-in-xml-with-conditionals.html The latest comments and answers for the question "Update values in xml with conditionals" Comment by takashi on takashi's answer https://knowledge.safe.com/comments/72825/view.html Yes, you have to declare namespaces at the top of the expressions if the source XML has elements belonging to a namespace.General syntax is:
declare namespace
        
         = "
         
          ";
         
        
Note that a declare statement should end with a semicolon, unlike expression body.
Then, in the expression body, qualify all element names belonging to the namespace by the prefix.
Wed, 20 Jun 2018 21:33:38 GMT takashi
Comment by djmcdermott on djmcdermott's answer https://knowledge.safe.com/comments/72805/view.html Hi @takashi.Thank you for your response.I said to my colleagues after I posted that you’d be the one with the solution.

In was very close with my own attempt.Sorry to throw this in but the xml has a namespace.Do I have to declare it and therefore prefix the nodes with //x: (for example)
Wed, 20 Jun 2018 17:28:31 GMT djmcdermott
Answer by takashi https://knowledge.safe.com/answers/72794/view.html

Yes, you can do that with an XQuery expression (XMLXQueryUpdater).I think the following example contains every syntax you have to learn for the present.

Source XML

       
        
         X1
         
          aaa
         
        
        
         X2
         
          aaa
         
        
        
         X2
         
          bbb
         
        
        
         Z3
         
          aaa
         
        
       

XQuery Expression (assume that an attribute storing the source XML is set to the XML Attribute parameter in the XMLXQueryUpdater)

for $item in //item let $code := data($item/code) let $desc := data($item/desc) return if (matches($code, '^X.*')) then ( replace value of node $item/code with 'KK', if ($code = 'X1' and $desc = 'aaa') then replace value of node $item/desc with 'foo aaa' else if ($code ='X2' and $desc = 'aaa') then replace value of node $item/desc with 'bar aaa' else () ) else ()

Result

       
        
         KK
         
          foo aaa
         
        
        
         KK
         
          bar aaa
         
        
        
         KK
         
          bbb
         
        
        
         Z3
         
          aaa
         
        
       

If you need more specific solution, please post a small (but valid) sample XML and your desired result corresponding to the sample.

Wed, 20 Jun 2018 16:10:49 GMT takashi