Last active
October 5, 2015 17:28
-
-
Save caschwartz/2844864 to your computer and use it in GitHub Desktop.
Query xml and split into separate files
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
xquery version "1.0-ml"; | |
(: 6/8/11 Query Endnote xml and split into separate files :) | |
declare namespace functx = "http://www.functx.com"; | |
declare function functx:pad-integer-to-length | |
( $integerToPad as xs:anyAtomicType? , | |
$length as xs:integer ) as xs:string { | |
if ($length < string-length(string($integerToPad))) | |
then error(xs:QName('functx:Integer_Longer_Than_Length')) | |
else concat | |
(functx:repeat-string( | |
'0',$length - string-length(string($integerToPad))), | |
string($integerToPad)) | |
} ; | |
declare function functx:repeat-string | |
( $stringToRepeat as xs:string? , | |
$count as xs:integer ) as xs:string { | |
string-join((for $i in 1 to $count return $stringToRepeat), | |
'') | |
} ; | |
for $record in xdmp:directory("/endnote/") | |
let $documents := $record/xml/records/record | |
return for $doc at $count in $documents | |
let $file-name := fn:concat("/endnote/", "kuyper-bib", functx:pad-integer-to-length($count, 4), ".xml") | |
return xdmp:document-insert($file-name, $doc) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment