0
votes

I launched test from SoapUI and I want to figure out an XQuery assert. I am not able to write the XQuery request.

My xml file (answer request SoapUI)

<parent>
  <total1>10.000</total1>
  <total2>15</total2>
  <value1>1</value1>
  <value2>2</value2>
</parent>

Expected answer

I want only nodes starting with total, and the number value of node value

<parent>
  <total1>10.0</total1>
  <total2>15.0</total2>
</parent>

Current not working XQuery request

<parent>
{ for $n in //parent/*[starts-with(name(),'total')]
 return ($n/name() ,$n/number(text()) )
}
</parent>

This is not right because it display only node name. All nodes are on the same line : <parent> total1 10.0 total2 15.0 </parent> I am OK to do it using XQuery or XPath

1
Did you try <parent> { for $n in //parent/*[starts-with(name(),'total')] return ($n)} </parent> ?Andersson
With this pattern I am not able to use function number(). I also get all links xmlns:... that it is not human readable.Flows
Add XML sample similar to your real source file. Provided simplified XML might confuse answerersAndersson
I agree with you, but I am not sure I want to do that because it is from my company WSFlows

1 Answers

3
votes

New element nodes can be created with element constructors:

<parent>{
  for $n in //parent/*[starts-with(name(), 'total')]
  return element { name($n) } { number($n) }
}</parent>

The function call number(<total1>10.000</total1>) yields 10 instead of 10.0. If you need a customized representation of your numeric values, the format-number function can be used:

<parent>{
  for $n in //parent/*[starts-with(name(), 'total')]
  return element { name($n) } { format-number(number($n), '#.0') }
}</parent>