In the series XQuery generating multiple XML documents we talk today about splitting a large XML document in several smaller ones. In some scenarios such huge documents are simply unmanageable, requiring the need to split them up.
Consider one of the Shakespeare plays marked up in XML, for example Hamlet. We want to split for this play each speech in a separate XML document.1 2 3 4 5 6 7 8 | for $speech at $i in doc("http://www.andrew.cmu.edu/user/akj/shakespeare/hamlet.xml") /PLAY//SPEECH let $url := concat("C:/SHAKESPEAR/", string-join($speech/SPEAKER,"_"), $i, ".xml") return ddtek:serialize-to-url($speech, $url, "omit-xml-declaration=no,indent=yes") |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 | <html>{ for $speech at $i in doc("http://www.andrew.cmu.edu/user/akj/shakespeare/hamlet.xml") /PLAY//SPEECH let $url := concat("C:/SHAKESPEAR/", string-join($speech/SPEAKER,"_"), $i, ".html") let $htmlspeech := <html> <b>{$speech/SPEAKER/text()}</b>:<br/>{ for $line in $speech/LINE return ($line/text(),<br/>) }</html> return ( ddtek:serialize-to-url($htmlspeech, $url, "method=html"), <a href="{$url}">{ $speech/SPEAKER/text() }</a>, <br/> ) }</html> |
