0

Following this answer:

cat xquery.txt
declare namespace w = "http://schemas.openxmlformats.org/wordprocessingml/2006/main";
copy $input := doc("/tmp/file.xml")
modify delete node $input//w:rPr
return $input

Input file

<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<root xmlns:w="http://schemas.openxmlformats.org/wordprocessingml/2006/main">
    <w:lvl w:ilvl="0">
      <w:rPr>
          TO REMOVE
      </w:rPr>
      <w:rPx>
        <w:rFonts w:ascii="Symbol" w:hAnsi="Symbol" w:hint="default"/>
      </w:rPx>
    </w:lvl>
</root>
$ java -cp "/path/to/lib/saxon-he-11.4.jar" net.sf.saxon.Query -qversion:3.1 -q:xquery.txt 
Exception in thread "main" java.lang.NoClassDefFoundError: org/xmlresolver/Resolver
    at net.sf.saxon.lib.CatalogResourceResolver.<init>(CatalogResourceResolver.java:46)
    at net.sf.saxon.Configuration.init(Configuration.java:367)
    at net.sf.saxon.Configuration.<init>(Configuration.java:230)
    at java.base/jdk.internal.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
    at java.base/jdk.internal.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:62)
    at java.base/jdk.internal.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
    at java.base/java.lang.reflect.Constructor.newInstance(Constructor.java:490)
    at java.base/java.lang.Class.newInstance(Class.java:584)
    at net.sf.saxon.Configuration.newConfiguration(Configuration.java:246)
    at net.sf.saxon.Query.doQuery(Query.java:265)
    at net.sf.saxon.Query.main(Query.java:103)
Caused by: java.lang.ClassNotFoundException: org.xmlresolver.Resolver
    at java.base/jdk.internal.loader.BuiltinClassLoader.loadClass(BuiltinClassLoader.java:581)
    at java.base/jdk.internal.loader.ClassLoaders$AppClassLoader.loadClass(ClassLoaders.java:178)
    at java.base/java.lang.ClassLoader.loadClass(ClassLoader.java:522)
    ... 11 more

From doc

-q:input

Another try with an older version:

$ java -cp "/path/to/lib/saxon9he.jar" net.sf.saxon.Query -qversion:3.0 -q:xquery.txt
Error on line 2 column 1 of xquery.txt:
  XPST0003 XQuery syntax error near #...rocessingml/2006/main"; copy $#:
    Unexpected token "copy" in path expression
Static error(s) in query
Gilles Quénot
  • 173,512
  • 41
  • 224
  • 223
  • https://www.saxonica.com/html/documentation11/using-xquery/update.html clearly says: "Saxon-EE supports use of the update extensions to XQuery defined in the W3C Recommendation http://www.w3.org/TR/xquery-update-10/" and "Update is available only in Saxon-EE, and is supported only if explicitly requested". The error message about "java.lang.NoClassDefFoundError: org/xmlresolver/Resolver" suggests you don't have it on the classpath, normal installation of the zip from Github should have it on the classpath. – Martin Honnen Apr 24 '23 at 05:57

2 Answers2

1

Based on the Saxon Home Edition (HE) documentation, it supports just the XQuery 3.1 Minimal Conformance. And it doesn't include the following:

Optional features not provided: XQuery 3.1 Schema Aware, XQuery 3.1 Typed Data, XQuery 3.1 Static Typing, XQuery Update 1.0

And you need XQuery Update support for your task.

It seems that you would need to use Saxon PE or EE editions for your objectives.

For the reference: Product Description for SaxonJ-HE (Home Edition)

Yitzhak Khabinsky
  • 18,471
  • 2
  • 15
  • 21
0

There are two separate problems here.

With Saxon-HE 11.4, as others have indicated, the problem is that Saxon-HE does not support XQuery Update.

With the newer version, you haven't got as far as that: here the problem is that org/xmlresolver/Resolver is not on your classpath. Saxon should find the resolver, even if it isn't on the classpath in its own right, provided it is in the same directory as the Saxon jar file itself. For more detail see https://www.saxonica.com/documentation12/#!about/installationjava/prerequisites

Michael Kay
  • 156,231
  • 11
  • 92
  • 164