|
[XQuery Talk Mailing List Archive Home] [By Date] [By Thread] [By Subject] [By Author] [Recent Entries] [Reply To This Message] Re: replacing a node in in-memory XMLHans-Juergen Rennau hrennau at yahoo.deTue Nov 6 22:13:39 PST 2007
Hello Wolfgang,
let me add a remark about the situation when the nodes to be modified cannot be identified by type *ALONE*. For example, the document might contain many community groups, and the services element is to be replaced only in the groups (2, 31, 32, 40). In such situations, I suggest to combine the "typeswitch recursion pattern" with a "node marking pattern": a) before starting the recursion, "mark" the modification targets by collecting them in a variable, b) within the relevant typeswitch branch use a node identity-based if/else. This approach scales rather well when things get more complicated (several element types are to be partially and heterogeneously modified).
a)
declare variable $targetNodes_services :=
($doc//communitygroup)[position() = (2, 31, 32, 40)]/group/services
b)
typeswitch ($node)
case $elem as element(services) return
if ($elem intersect $targetNodes_services) then <services>...</services>
else
element {node-name($elem)} {$elem/@*, $elem/node()/local:replace(.)}
...
The approach helped me when I had to modify WordML documents, highly repetitive as they are in terms of element names!
With kind regards,
Hans-Juergen
__________________________________ Ihr erstes Fernweh? Wo gibt es den schönsten Strand? www.yahoo.de/clever
|
PURCHASE STYLUS STUDIO ONLINE TODAY!Purchasing Stylus Studio from our online shop is Easy, Secure and Value Priced! Download The World's Best XML IDE!Accelerate XML development with our award-winning XML IDE - Download a free trial today! Subscribe in XML format
|






