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

adding elements

Wolfgang Meier wolfgang at exist-db.org
Fri Dec 18 12:16:20 PST 2009


  adding elements
Hi Jens,

as an alternative to using XSLT or XQuery Update, my standard XQuery
solution would be to create a recursive filter function with a
typeswitch statement. Tested with saxon:

declare namespace dc="http://purl.org/dc/elements/1.1/";

declare variable $xml :=
    <object id="O33051">
        <view id="V33052">
            <original filename="374.jpg"
hash="a72ff5300a4e5cba7c6d58d581f7c220"/>
            <img height="141" src="img/V33052.original" use="pict" width="213"/>
            <rdf:RDF xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
                 xmlns:dc="http://purl.org/dc/elements/1.1/">
                <rdf:Description

rdf:about="petal://kjc-fs2.kjc.uni-heidelberg.de:8081/HIEditor_2.0-Service/P67/V33052"
                    xml:lang="en">
                    <dc:title>daṃtahastavināyaka</dc:title>
                    <dc:source/>
                </rdf:Description>
            </rdf:RDF>
        </view>
    </object>;

declare function local:modify($title as element(dc:title)) {
    <dc:title xml:lang="xx">{$title/text()}</dc:title>
};

declare function local:filter($node as node()) {
    typeswitch ($node)
        case element(dc:title) return
            ($node, local:modify($node))
        case element() return
            element { node-name($node) } { $node/@*, for $child in
$node/node() return local:filter($child) }
        default return
            $node
};

local:filter($xml)

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-2011 All Rights Reserved.