Assuming that you're using XQuery 1.0 add: declare boundary-space preserve;
if you're using 0.9, add: declare xmlspace = preserve Cheers, Mark _____ From: [email protected] [mailto:[email protected]] On Behalf Of Tim Meagher Sent: Tuesday, March 31, 2009 2:26 PM To: 'General Mark Logic Developer Discussion' Cc: 'Crewdson, Andrew'; Paul Rooney Subject: [MarkLogic Dev General] Problem preserving whitespace in anXML-to-XML xquery transform Importance: High Hi Folks, I have written an xquery transform whose purpose is to convert mixed content that marked up in Schema A into the same mixed content but marked up using Schema B. It's not just a simple matter of renaming elements - so I have implemented a recursive node-by-node approach using an algorithm similar to the following: declare function cxtn:format-source-by-node($node as node) as node()* { ( typeswitch ($node) case text() return ( $node, if (exists($node/following-sibling::node()[1])) then cxtn:format-source-by-node($node/following-sibling::node()[1]) else text {""} ) case element (t) (: Title :) return ( element title {string($node)}, if (exists($node/following-sibling::node()[1])) then cxtn:format-source-by-node($node/following-sibling::node()[1]) else text {""} ) case element (v) (: Volume :) return ( element volume {string($node)}, if (exists($node/following-sibling::node()[1])) then cxtn:format-source-by-node($node/following-sibling::node()[1]) else text {""} ) case element () (: Unexpected element - tag it as text and process the next node in the list :) return ( text {string($node)}, if (exists($node/following-sibling::node()[1])) then cxtn:format-source-by-node($node/following-sibling::node()[1]} else text {""} ) (: No other node types need to be processed here, so if encountered just return a text node :) default return text {""} ) }; What I'm left with is a node list that is attached to another nodelist and eventually wrapped in a parent element, e.g., element node-list { cxtn:format-source-by-node( $some-starting-node) } The results work as expected, except that when a text node is encountered that contains only a space character, it is stripped away. This is not boundary space, it is space between elements, so the input: <t>Title</t> <v>Volume</v> is converted to: <title>Title</title><volume>Volume</volume> where the space between the 2 elements has been removed. Can someone tell me how to preserve this space? Thank you! Tim
_______________________________________________ General mailing list [email protected] http://xqzone.com/mailman/listinfo/general
