Is it possible to make a XPath query in BuildRowsetFromXml function like this?

'concat(//xpath1/text(), " ", //xpath2/text())'

Using subfunctions of xpath for concatenating nodes?

Thank you!


My XML is

               <nombre>BNUR                </nombre>
               <apellido1>SNPSZVYR:           </apellido1>
               <apellido2>ORSR:               </apellido2>
                  <nombreVia> OKSQYR ÑRJWSKF             </nombreVia>
                  <numeroVia>TOR2 </numeroVia>
                  <piso>b7Ñ                      </piso>
                  <poblacion>FKU OKFHKU PR VSKJ ÑKJKSZK</poblacion>
               <phone>                </phone>
               <email>                                                  </email>

I'm testing this code

SET @complejo = 'concat(//Envelope/Body/GetClaimDetailResponse/claimDetailResult/holder/nombre/text(), " ", //Envelope/Body/GetClaimDetailResponse/claimDetailResult/holder/nombre/text())'
SET @res = BuildRowsetFromXml(@xml, @complejo, 1)
SET @row = row(@res, 1)
SET @valueTmp = field(@row, "Value")

This is working in tester... but It doens't in ampscript


AMPScript under the hood is built on DotNet. It supports XSLT 1.0 and the concat function was part of that standard and supported by Microsoft. As you point out, AMPScript does not seem to be able to utilise the XSL/XPATH "concat" function in the BuildRowSetFromXML function.

It's not particulary satisfactory, but my suggestion would be to use the BuildRowSetFromXML AMPScript function to pull out your data using XPATH and then concatenate the values using AMPScript's own Concat function.

    SET @xml = HttpGet("https://www.dropbox.com/s/7o18r4tdt76h5b4/GetClaimResponse.xml?dl=0&raw=1")

    SET @complejo1 = '//Envelope/Body/GetClaimDetailResponse/claimDetailResult/holder/nombre'
    SET @complejo2 = '//Envelope/Body/GetClaimDetailResponse/claimDetailResult/holder/nombre'

    SET @complejo = 'concat(hello, world)'
    SET @res1 = BuildRowsetFromXml(@xml, @complejo1, 1)
    SET @res2 = BuildRowsetFromXml(@xml, @complejo2, 1)

    SET @row = row(@res, 1)
    SET @valueTmp = concat(field(row(@res1,1), "Value")," ",field(row(@res2,1), "Value"))

This outputs the same result as you would get using the XPATH concat function...

BNUR                 BNUR                
| improve this answer | |
  • Thank you for your answer. But, before I wrote here, I already checked my xml and my xpath in that webtool... but my code throws a 500 error code... I think that this xpath does not work with ampscript... so bad... – MrViSiOn Jun 2 '17 at 14:10
  • Can you share the XML in your question, please? – Macca Jun 2 '17 at 14:14
  • I edited my question – MrViSiOn Jun 2 '17 at 14:22
  • I see your point. It looks like AMPScript BuildRowSetFromXML cannot handle the Concat function in XPATH. I've updated my answer with a workaround, but I cannot see anything you are doing incorrectly. It looks like it's and AMPScript limitation. – Macca Jun 3 '17 at 1:47

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.