Types, methods and variables used in the X-script you may declare in the auxiliary element "xd:declaration":
<xd:declaration> type isbn int(10000000, 999999999); type published gYear(); Date today = now(); void message(String s) { outln(s); } </xd:declaration> <Book xd:script="init message('Started ' + today); finally message('Process finished');" ISBN="isbn();" published="optional published();" > <Author xd:script="occurs *" > string() </Author> <Title> string() </Title> </Book>