searchSectionByTitle.hq 1.03 KB
Newer Older
simei.yin's avatar
simei.yin committed
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
(: This script will return a section by searching keyword in its title :)
(: We can assign a Regular Expression to the variable $keyword :)
(: For example, $keyword := '^Objectifs$', to search for sections whose titles are exactly "Objectifs":)
(: For example, $keyword := 'Syntax', to search for sections whose titles containing "Syntax" :)
(: Remark : case and accents in the keyword have been taken care of  :)

declare function local:searchSectionByTitle($keyword as xs:string, $docs as node()*) as node()*
{
  let $keyword_noAcc := translate($keyword, 'áàâäéèêëíìîïóòôöúùûüABCDEFGHIJKLMNOPQRSTUVWXYZ','aaaaeeeeiiiioooouuuuabcdefghijklmnopqrstuvwxyz')
  for $doc in $docs
  return
    for $section in $doc/sections/section
    let $title_noAcc := translate($section/titresection, 'áàâäéèêëíìîïóòôöúùûüABCDEFGHIJKLMNOPQRSTUVWXYZ','aaaaeeeeiiiioooouuuuabcdefghijklmnopqrstuvwxyz')
    where matches($title_noAcc, $keyword_noAcc)
    return $section
};

(: Example :)
local:searchSectionByTitle('contenu', //document)