which makes a start towards this by combining 'runs'.
I am trying to make this script work within Stylus Studio, and have some problems I hope someone can help me with.
At the bottom of thispost I have pasted my modified version of the script. It currently produces the following error: XPTY0004, at line 103:24, which is the space after '$this' on the return statement of the local:map function.
I'm really just getting started with this, and hope to end up generating java code which can be run over a set of documents whenever needed. I'd appreciate any help anyone can give me.
Subject:Cleaning up Word 2007 xml Author:Minollo I. Date:26 Jan 2009 10:55 AM
I didn't try going through the whole logic of the XQuery; but to make it correct against the static typing checks that DataDirect XQuery does, you need two changes:
declare function local:ml-update-document-xml($doc as element(w:document)) as element(w:document)
{
local:dispatch($doc) treat as element(w:document)
};
[Note the "treat as" to force a cast from node() to element(w:document); in alternative you can change the return type to just node()]
...and...
declare function local:map($r as element(w:r)?) as element(w:r)?
{
if (fn:empty ($r)) then ()
else
let $rToCheck := $r/w:rPr
let $matches := local:descend($r/following-sibling::w:r[1], $rToCheck)
let $count := fn:count($matches)
let $this := if ($count) then
(element w:r{ $rToCheck,
element w:t { fn:string-join(($r/w:t/string(), $matches/w:t/string()),"") } })
else $r
return ($this, local:map( if($count) then ($r/following-sibling::w:r[1 + $count]) else $r/following-sibling::w:r[1]))
};
[Note that the return type can be an empty sequence, which implies you need to add a "?" to the return type; and the explicit use of string() when you use string-join()]