declare default element namespace "http://www.tei-c.org/ns/1.0"; declare namespace tei = "http://www.tei-c.org/ns/1.0"; declare namespace abv = "http://ossetic-studies.org/ns/abaevdict"; declare function local:genLookupEntry($doc as document-node()) as element()? { let $node := $doc/tei:TEI/tei:text/tei:body/tei:entry let $phon := $node/tei:form[1]/tei:orth[1]/text()[1] return element entry { attribute xml:id { $node/@xml:id }, attribute filename { db:path($doc) }, if ($node/@n) then attribute n {$node/@n} else (), text { $phon } } }; let $tbl :=