I have the following xml document:
<customers>
<continent>NA</continent>
<Type>Regular<Type>
<customer>
<name>John Smith</name>
<address>123 Oak St.</address>
<state>WA</state>
<phone>(206) 123-4567</phone>
</customer>
<customer>
<name>Zack Zwyker</name>
<address>368 Elm St.</address>
<state>WA</state>
<phone>(206) 423-4537</phone>
</customer>
<customers>
I am trying to construct a map for each customer as follows:
for $customer in //customers
return
map {
'continent': //continent/string(),
'type': //Type/string(),
'name': $customer/name/string(),
'address': $customer/address/string(),
'state': $customer/state/string(),
'phone': $customer/phone/string()
}
but for each iteration i am using the same continent and type which are same for each customer.
how can i construct my xpath so that the continent and type elements are generated only once, and can be accessed in each map.