docs: def xpath(request):
      """View for the route. Determines UUID and version from input request
      and determines the type of UUID (collection or module) and executes
      the corresponding method."""
      ident_hash = request.params.get('id')
      xpath_string = request.params.get('q')
  
      if not ident_hash or not xpath_string:
          exc = httpexceptions.HTTPBadRequest
          exc.explanation = 'You must supply both a UUID and an xpath'
          raise exc
  
      try:
          uuid, version = split_ident_hash(ident_hash)
      except IdentHashShortId as e:
          uuid = get_uuid(e.id)
          version = e.version
      except IdentHashMissingVersion as e:
          uuid = e.id
          version = get_latest_version(e.id)
      except IdentHashSyntaxError:
          raise httpexceptions.HTTPBadRequest
  
      settings = get_current_registry().settings
      with db_connect() as db_connection:
          with db_connection.cursor() as cursor:
              result = get_content_metadata(uuid, version, cursor)
  
      resp = request.response
  
      if result['mediaType'] == COLLECTION_MIMETYPE:
          matched_route = request.matched_route.name
          results = xpath_book(request, uuid, version,
                               return_json=matched_route.endswith('json'))
          if matched_route.endswith('json'):
              results = {'results': list(results)}
              resp.body = json.dumps(results)
              resp.content_type = 'application/json'
          else:
              resp.body = results
              resp.content_type = 'application/xhtml+xml'
      else:
          results = {'results': list(xpath_page(request, uuid, version))}
          resp.body = json.dumps(results)
          resp.content_type = 'application/json'
  
      resp.status = "200 OK"
      return resp