Something like this might do the trick (it only works if the C
elements have no descendant C elements):
for $f in collection("/mycollection/")
return
copy $e := $f
modify (
for $c in $e//C[text() = "*"]/
(following-sibling::C[matches(., "\p{L}")])[1] return replace value of node $c with upper-case($c)
)
return $e
By collecting all relevant nodes in a single path expression,
duplicates will be filtered out.
On Thu, Sep 15, 2016 at 2:54 PM, Joseph <meumapple@gmail.com> wrote:
> Yes, I mean the XML file. I using a query like the following. There are
> nodes for which the replace updating expression does not work, and I do not
> know how to identify the file(s) where the problem is. I could simply try to
> exclude files from the collection until the query works, but I was wondering
> whether there is a more intelligent way to do that. Thanks!
>
>
> try {
>
> for $f in collection("/mycollection/")
> return
> copy $e := $f
> modify
> (
> for $x in $e//C[text()="*"][./following-sibling::C[matches(., "\p{L}")]]
> let $y := $x/(following-sibling::C[matches(., "\p{L}")])[1]
> return
> replace value of node $y with upper-case($y)
> )
> return $e
> }
> catch * {
> 'Error [' || $err:code || ']: ' || $err:description || ',' || $err:module
> ||',' ||$err:line-number || ','|| $err:column-number
> || ','|| $err:value || ','|| $err:additional
> }
>
>
>
> 2016-09-15 14:11 GMT+02:00 Christian Grün <christian.gruen@gmail.com>:
>>
>> Hi Joseph,
>>
>> > I use all the $err but the line error refers to the one inside my query
>> > not that of the file where the query cannot be applied (more precisely, a
>> > node cannot be replaced more than once, but I do not know where this
>> > problematic node is in my files)
>>
>> With “file”, do you mean an XML document? That’s not possible indeed.
>> Maybe you can show us how your query looks like?
>>
>> Christian
>>
>>
>>
>> > Hi Joseph,
>> >
>> >> or am I missing something here?
>> >
>> > I guess so; Did you check the documentation of the function [1,2]?
>> >
>> > Christian
>> >
>> > [1] http://docs.basex.org/wiki/XQuery_3.0#Try.2FCatch
>> > [2] https://www.w3.org/TR/xquery-31/#id-try-catch
>
>