import module namespace ast="lsp/ast" at "../webapp/lsp/ast/ast.xqm"; (: declare variable $file:="sample.docs/pdfbox.xqm"; :) declare variable $file:="sample.docs/simple.xq"; declare variable $A:=doc("sample.docs/parse-pdfbox.xml"); unparsed-text($file) =>ast:build() update{ for $e in descendant-or-self::element() let $len:=string-length($e) let $before:=$e/preceding-sibling::node()/string-length()=>sum() return (insert node attribute len { $len } into $e, insert node attribute before { $before } into $e ) }