xquery version "3.0"; (: IMPORTED MODULES :) import module namespace http = "http://www.zorba-xquery.com/modules/http-client"; import module namespace file = "http://expath.org/ns/file"; import module namespace parsexml = "http://www.zorba-xquery.com/modules/xml"; import schema namespace parseoptions = "http://www.zorba-xquery.com/modules/xml-options"; (: NAMESPACES :) declare namespace marcxml = "http://www.loc.gov/MARC21/slim"; declare namespace output = "http://www.w3.org/2010/xslt-xquery-serialization"; declare option output:omit-xml-declaration "yes"; let $raw-data as xs:string := file:read-text("bad.xml") let $records := parsexml:parse( $raw-data, ) let $lines := for $r at $pos in $records return $r/marcxml:controlfield[@tag="001"] return fn:count($lines)