basex icon indicating copy to clipboard operation
basex copied to clipboard

XQuery: Index access for integers

Open ChristianGruen opened this issue 3 years ago • 0 comments

If the string value of an XML path is always an integer …

index:facets('factbook')//
  element[@name = 'country']/
  attribute[@name = 'population']

… a numeric comparison …

db:open('factbook')//country[@population = 3249136]

… can be rewritten for index access:

db:attribute('factbook', '3249136')/self::attribute(population)/parent::country

Simple range queries could be rewritten as well:

db:open('factbook')//city/population
  [@year >= 82 and @year <= 84]

→ db:attribute('factbook', ('82', '83', '84'))/self::attribute(year)/parent::population[parent::city]

ChristianGruen avatar Feb 19 '22 10:02 ChristianGruen