- From: <bugzilla@wiggum.w3.org>
- Date: Tue, 13 Feb 2007 15:44:01 +0000
- To: public-qt-comments@w3.org
- CC:
http://www.w3.org/Bugs/Public/show_bug.cgi?id=4285
------- Comment #6 from andrew.eisenberg@us.ibm.com 2007-02-13 15:44 -------
Just thinbking out loud on this topic. The "do fold $children into $parent"
seems to be a shorthand for the following (considering only element nodes):
let $matching := $children[name(.) = $parent/*/name()]
let $nonmatching := $children except $matching
return
( for $m in $matching
return do replace ($parent/*[name() = name($m)]) with $m,
do insert $nonmatching into $parent
)
As Michael Kay pointed out, this will cause an error if one of the elements
being has a sibling with the same name (caught by one of the executions of
replace). I suppose that we could delete the 2nd and subsequent duplicates of
the matching nodes and execute the replace only on the first copy.
let $matching := $children[name(.) = $parent/*/name()]
let $nonmatching := $children except $matching
return
( for $m in $matching
return
( let $matched := $parent/*[name() = name($m)]
return
( do delete $matched[position() >= 2],
do replace $matched[1] with $m
)
),
do insert $nonmatching into $parent
)
Hmmm. Getting a bit complicated.
As Don has suggested, it could be extended to allow "do fold $children as first
into $parent":
let $matching := $children[name() = $parent/*/name()]
let $nonmatching := $children except $matching
return
( for $m in $matching
return do replace ($parent/*[name() = name($m)]) with $m,
do insert $nonmatching as first into $parent
)
It could be extended to allow the non-matching nodes to be placed before or
after an existing node, using "do fold $children after $node":
let $parent := $node/..
let $matching := $children[name() = $parent/*/name()]
let $nonmatching := $children except $matching
return
( for $m in $matching
return do replace ($parent/*[name() = name($m)]) with $m,
do insert $nonmatching after $node
)
Received on Tuesday, 13 February 2007 15:44:14 UTC