Page 1 of 1

How To Execute An XQuery Against Numerous Documents

Posted: Sat Sep 10, 2011 1:06 am
by Jamil
I have created an XQuery to identify erroneous nodes and line numbers they're on for a single document. It looks something like this:

for $name in doc("doc01.xml")//*[@SomeRandomAttribute="SomeRandomValue"]
where fn:count($name/elementThatMustExist)=0
return <match filename="{fn:tokenize(fn:base-uri(), "/")[fn:last()]}" node="{fn:name($name)}" line="{saxon:line-number($name)}"/>

My issue is that I have hundreds of files, and I do not want to edit this hundreds of times. I cannot simply do something like this: doc("*.xml").

Do I have any other options here?

TIA

Re: How To Execute An XQuery Against Numerous Documents

Posted: Sat Sep 10, 2011 3:18 am
by Jamil
I believe I got this partially working now with a minor change as follows:

for $name in collection("file:///c:/Temp?select=*.xml")//*[@SomeRandomAttribute="SomeRandomValue"]
where fn:count($name/elementThatMustExist)=0
return <match filename="{fn:tokenize(fn:base-uri(), "/")[fn:last()]}" node="{fn:name($name)}" line="{saxon:line-number($name)}"/>

The issue I face now is that the fn:base-uri() function is returning the same document and not the current one from the collection. This makes the results I get useless.

Re: How To Execute An XQuery Against Numerous Documents

Posted: Sat Sep 10, 2011 3:35 am
by Jamil
I resolved this on my own.

The solution was the following:

for $name in collection("file:///c:/Temp?select=*.xml")//*[@SomeRandomAttribute="SomeRandomValue"]
where fn:count($name/elementThatMustExist)=0
return <match filename="{fn:document-uri(fn:root($name))}" node="{fn:name($name)}" line="{saxon:line-number($name)}"/>

One last thing that I cannot seem to figure out--

Is there a way that I can expand the line length of the output sequence in oXygen 13? My output from this XQuery is being wrapped at something like 80 characters. There is no need to wrap at all, since I have a wide screen. It makes it difficult to read the results.

Re: How To Execute An XQuery Against Numerous Documents

Posted: Tue Sep 13, 2011 2:10 pm
by Radu
Hi Jamil,

We cannot reproduce the problem with the line width for the result being limited to 80 chars. Probably the XML input files over which you are running the collection query have line widths in their content.

Regards,
Radu

Re: How To Execute An XQuery Against Numerous Documents

Posted: Tue Sep 13, 2011 7:42 pm
by Jamil
Here is a screenshot: http://www.file-shop.com/Images/Misc/oXygen_sc.gif

The unneeded attribute wrapping behavior is consistent with both the standalone editor and the Eclipse plug-in. I can find no way to prevent this from happening. I can find no way to specify a line length for documents created via transformation.

There are work-arounds for this, of course (like saving the transformation results as an XML file). Even then I have to manually format the file to remove the wrapped lines. I do not wish to configure oXygen to format every opened XML document (which would take care of the wrapping in this case), because I do not want all XML docs modified upon opening.

Re: How To Execute An XQuery Against Numerous Documents

Posted: Wed Sep 14, 2011 12:06 pm
by Radu
Hi Jamil,

I reproduced the behavior, line breaks are inserted before long attributes.

The only preference we have for formatting is in the Oxygen Preferences->
XML / XSLT-FO-XQuery / XQuery page.
The checkbox is called Format transformer output.
This setting we set to the Saxon 9 XQuery processor and the indentation (and line breaking) is performed exclusively by it.
Unfortunately if you uncheck the checkbox, everything will be outputted on one line.

From what I've checked in the XQuery processor code, the line break for attributes is hard coded to 80 chars so the only option for you is to automatically save the XQuery result to an XML file, open the file and format and indent it in Oxygen.

Regards,
Radu