0

In the below code, $y returns one attribute value that looks like "OK HL DJ FJJ FJ" etc. $l returns attribute values that look like "OK" "HL". The idea, is that I want to see if $l is contained within $y, and if so to print it out. So really the third line of code past /country/ is where I am confused. I am not sure how to include a function past there to do what I described.

  let $g := doc("cars.xml")/cars/honda[@id="hondaCivic"]
  let $y := ($g/@type)
  for $l in doc("cars.xml")/cars/country/[@car_code]????
  return $y

1 Answers1

3

The following tokenize the whitespace-separated code string, and select all country with a code in the resulting sequence:

let $cars  := doc('cars.xml')/cars
let $type  := $cars/honda[@id eq 'hondaCivic']/@type
let $codes := tokenize($type, '\s+')
return
   $cars/country[@car_code = $codes]

Usually it is a good idea to use the XML structure to represent structured information, e.g. using a repeatable type element to represent each of the code independently instead of using a string containing a list of values.

Florent Georges
  • 2,190
  • 1
  • 15
  • 24