[XQuery Talk Mailing List Archive Home] [By Date] [By Thread] [By Subject] [By Author] [Recent Entries] [Reply To This Message]

Changing the content of an XML document

Wolfgang wolfgang at exist-db.org
Tue Sep 2 11:26:51 PDT 2008


  Changing the content of an XML document
> Actually I can reduce my question to the following: Assuming I have a
> variable which stores a node-tree like that
> 
> let $tree :=
>   <node>
>     <subnode>
>       some text
>     </subnode>
>   </node>
> 
> In reality $tree is the entire XML file which I want to send back to the
> client. Now, depending on some conditions I want to change the content
> of <subnode> "some text" to "some other text", before sending it. I
> don't actually want to alter the file in the database, just the message
> that I'm sending.

Ok, I see. If you just need to filter out or change a few nodes, I would 
probably write a simple transformation function, e.g.:

declare function f:filter-entry($node as node(), $newText as xs:string) {
     typeswitch ($node)
         case $subnode as element(subnode) return
             <subnode>{$newText}</subnode>
         case $elem as element() return
             element { node-name($elem) } {
                 $elem/@*, for $child in $elem/node() return 
f:filter-entry($child, $newText)
             }
         default return
             $node
};

Wolfgang


PURCHASE STYLUS STUDIO ONLINE TODAY!

Purchasing Stylus Studio from our online shop is Easy, Secure and Value Priced!

Buy Stylus Studio Now

Download The World's Best XML IDE!

Accelerate XML development with our award-winning XML IDE - Download a free trial today!

Don't miss another message! Subscribe to this list today.
Email
First Name
Last Name
Company
Subscribe in XML format
RSS 2.0
Atom 0.3
Site Map | Privacy Policy | Terms of Use | Trademarks
Free Stylus Studio XML Training:
W3C Member
Stylus Studio® and DataDirect XQuery™are products from DataDirect Technologies, is a registered trademark of Progress Software Corporation, in the U.S. and other countries. © 2004-2007 All Rights Reserved.