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());
}
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);
}
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());
}
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());
}
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());
}
Aggregations