Search in sources :

Example 46 with XPathQueryService

use of org.xmldb.api.modules.XPathQueryService in project exist by eXist-db.

the class XQueryTest method predicateMinLast_1665215.

/**
 * @see http://sourceforge.net/support/tracker.php?aid=1665215
 */
@Test
public void predicateMinLast_1665215() throws XMLDBException {
    String query = "declare option exist:serialize 'indent=no';" + "let $data :=<parent><child>1</child><child>2</child><child>3</child><child>4</child></parent>" + "return <result>{$data/child[min((last(),3))]}</result>";
    XPathQueryService service = (XPathQueryService) getTestCollection().getService("XPathQueryService", "1.0");
    ResourceSet result = service.query(query);
    assertEquals(1, result.getSize());
    assertEquals("First", "<result><child>3</child></result>", result.getResource(0).getContent().toString());
}
Also used : XPathQueryService(org.xmldb.api.modules.XPathQueryService) EXistXPathQueryService(org.exist.xmldb.EXistXPathQueryService) ResourceSet(org.xmldb.api.base.ResourceSet)

Example 47 with XPathQueryService

use of org.xmldb.api.modules.XPathQueryService in project exist by eXist-db.

the class XQueryTest method namespaceWithTransform.

@Test
public void namespaceWithTransform() throws XMLDBException {
    XPathQueryService service = (XPathQueryService) getTestCollection().getService("XPathQueryService", "1.0");
    String query = "xquery version \"1.0\";\n" + "declare namespace transform=\"http://exist-db.org/xquery/transform\";\n" + "declare variable $xml {\n" + "	<node>text</node>\n" + "};\n" + "declare variable $xslt {\n" + "	<xsl:stylesheet xmlns=\"http://www.w3.org/1999/xhtml\" xmlns:xsl=\"http://www.w3.org/1999/XSL/Transform\" version=\"2.0\">\n" + "		<xsl:template match=\"node\">\n" + "			<div><xsl:value-of select=\".\"/></div>\n" + "		</xsl:template>\n" + "	</xsl:stylesheet>\n" + "};\n" + "<html xmlns=\"http://www.w3.org/1999/xhtml\">\n" + "	<body>\n" + "		{transform:transform($xml, $xslt, ())}\n" + "	</body>\n" + "</html>";
    ResourceSet result = service.query(query);
    // check there is one result
    assertEquals(1, result.getSize());
    String content = (String) result.getResource(0).getContent();
    // check the namespace
    assertTrue(content.startsWith("<html xmlns=\"http://www.w3.org/1999/xhtml\">"));
    // check the content
    assertTrue(content.indexOf("<div>text</div>") > -1);
}
Also used : XPathQueryService(org.xmldb.api.modules.XPathQueryService) EXistXPathQueryService(org.exist.xmldb.EXistXPathQueryService) ResourceSet(org.xmldb.api.base.ResourceSet)

Example 48 with XPathQueryService

use of org.xmldb.api.modules.XPathQueryService in project exist by eXist-db.

the class XQueryTest method orderBy_1789370.

/**
 * @see http://sourceforge.net/support/tracker.php?aid=1789370
 */
@Test
public void orderBy_1789370() throws XMLDBException {
    String query = "(for $vi in <elem>text</elem> order by $vi return $vi)/text()";
    XPathQueryService service = (XPathQueryService) getTestCollection().getService("XPathQueryService", "1.0");
    ResourceSet result = service.query(query);
    assertEquals(1, result.getSize());
    assertEquals(query, "text", result.getResource(0).getContent().toString());
}
Also used : XPathQueryService(org.xmldb.api.modules.XPathQueryService) EXistXPathQueryService(org.exist.xmldb.EXistXPathQueryService) ResourceSet(org.xmldb.api.base.ResourceSet)

Example 49 with XPathQueryService

use of org.xmldb.api.modules.XPathQueryService in project exist by eXist-db.

the class XQueryTest method currentDateTimeInModules_1894009.

@Test
public void currentDateTimeInModules_1894009() throws XMLDBException {
    String module = "module namespace dt = \"dt\";\n" + "\n" + "declare function dt:fib($n) {\n" + "  if ($n < 2) then $n else dt:fib($n - 1) + dt:fib($n - 2) \n" + "};\n" + "\n" + "declare function dt:dateTime() {\n" + "  (: Do something time consuming first. :)  \n" + "  let $a := dt:fib(25)" + "  return current-dateTime()\n" + "};";
    String module_name = "dt.xqm";
    Resource doc;
    // Store module
    Collection testCollection = getTestCollection();
    doc = testCollection.createResource(module_name, "BinaryResource");
    doc.setContent(module);
    ((EXistResource) doc).setMimeType("application/xquery");
    testCollection.storeResource(doc);
    String query = "import module namespace dt = \"dt\" at" + "  \"xmldb:exist:///db/test/dt.xqm\"; " + "(<this>{current-dateTime()}</this>, <this>{dt:dateTime()}</this>)";
    XPathQueryService service = (XPathQueryService) getTestCollection().getService("XPathQueryService", "1.0");
    ResourceSet result = service.query(query);
    assertEquals(2, result.getSize());
    assertEquals("First", result.getResource(0).getContent().toString(), result.getResource(1).getContent().toString());
}
Also used : EXistResource(org.exist.xmldb.EXistResource) XPathQueryService(org.xmldb.api.modules.XPathQueryService) EXistXPathQueryService(org.exist.xmldb.EXistXPathQueryService) XMLResource(org.xmldb.api.modules.XMLResource) EXistResource(org.exist.xmldb.EXistResource) Resource(org.xmldb.api.base.Resource) Collection(org.xmldb.api.base.Collection) ResourceSet(org.xmldb.api.base.ResourceSet)

Example 50 with XPathQueryService

use of org.xmldb.api.modules.XPathQueryService in project exist by eXist-db.

the class XQueryTest method orderCompareAtomicType_1733265.

@Test
public void orderCompareAtomicType_1733265() throws XMLDBException {
    String query = "( ) = \"A\"";
    XPathQueryService service = (XPathQueryService) getTestCollection().getService("XPathQueryService", "1.0");
    ResourceSet result = service.query(query);
    assertEquals("false", result.getResource(0).getContent().toString());
    query = "\"A\" = ( )";
    result = service.query(query);
    assertEquals("false", result.getResource(0).getContent().toString());
}
Also used : XPathQueryService(org.xmldb.api.modules.XPathQueryService) EXistXPathQueryService(org.exist.xmldb.EXistXPathQueryService) ResourceSet(org.xmldb.api.base.ResourceSet)

Aggregations

XPathQueryService (org.xmldb.api.modules.XPathQueryService)148 ResourceSet (org.xmldb.api.base.ResourceSet)123 EXistXPathQueryService (org.exist.xmldb.EXistXPathQueryService)92 XMLResource (org.xmldb.api.modules.XMLResource)60 Collection (org.xmldb.api.base.Collection)31 Test (org.junit.Test)22 Resource (org.xmldb.api.base.Resource)18 XMLDBException (org.xmldb.api.base.XMLDBException)14 EXistResource (org.exist.xmldb.EXistResource)10 CollectionManagementService (org.xmldb.api.modules.CollectionManagementService)9 XUpdateQueryService (org.xmldb.api.modules.XUpdateQueryService)8 IndexQueryService (org.exist.xmldb.IndexQueryService)6 IOException (java.io.IOException)3 ResourceIterator (org.xmldb.api.base.ResourceIterator)3 BinaryResource (org.xmldb.api.modules.BinaryResource)3 MalformedURLException (java.net.MalformedURLException)2 Path (java.nio.file.Path)2 Node (org.w3c.dom.Node)2 HttpURLConnection (java.net.HttpURLConnection)1 URL (java.net.URL)1