On Tue, Sep 9, 2014 at 1:13 PM, Dinesh <[email protected]> wrote:
> Hi,
>
>
>
> I have issue finding text and replace text with hyper link tag using XQuery.
> e.g. get the xHTML files from MarkLogic and use the XQUERY to pattern match
> reference text, query to find the URI in MarkLogic and add the link element
> with URI in XHTML content.
>
>
>
> The following sample code, the problem with the loop is that instead of
> overwriting with updated data, it creates multiple copies of it.
>
>
>
> Is there any best approach to scan and link the link content on-fly? Please
> advise.
>
>
>
> let $citationlist := $internallink//citation/text()
>
> let $hreflist := $internallink//href
>
> let $urilist := $internallink//uri
>
> return
>
> <Content>
>
> {
>
> (:
>
> Here we replace the html with the reference links
>
> The problem with this loop here is that instead of overwriting with
> updated data, it creates multiple copies of it
>
> :)
>
> let $content := xdmp:quote($doc)
> let $contentReplace :=
> (
> for $citation at $pos in $citationlist
> return
> replace($content, $citation,$hreflist[$pos])
> )
> return xdmp:unquote($contentReplace)
> }
>
> </Content>
>
>
What is happening is that for each citation you are returning a
(possibly changed) version of the content. So $contentReplace is a
sequence of versions of $content.
If you want to use side effects in a loop like this you could try
replacing the return in the loop so that the value of $content is set
each time through. Something like:
for $citation at $pos in $citationlist
return
xdmp:set ($content, replace($content, $citation,$hreflist[$pos]))
_______________________________________________
General mailing list
[email protected]
http://developer.marklogic.com/mailman/listinfo/general