/** . */ @org.junit.Test public void treeQueriesResultsQ6() { final XQuery query = new XQuery( "\n" + " declare function local:section-summary($book-or-section as element()*) as element()* { \n" + " for $section in $book-or-section \n" + " return <section> { $section/@* } { $section/title } <figcount> { count($section/figure) } </figcount> { local:section-summary($section/section) } </section> \n" + " }; \n" + " <toc> { \n" + " for $s in /book/section \n" + " return local:section-summary($s) \n" + " } </toc>\n" + " ", ctx); try { query.context(node(file("docs/book.xml"))); result = new QT3Result(query.value()); } catch (final Throwable trw) { result = new QT3Result(trw); } finally { query.close(); } test( assertSerialization( "<toc><section id=\"intro\" difficulty=\"easy\"><title>Introduction</title><figcount>0</figcount><section><title>Audience</title><figcount>0</figcount></section><section><title>Web Data and the Two Cultures</title><figcount>1</figcount></section></section><section id=\"syntax\" difficulty=\"medium\"><title>A Syntax For Data</title><figcount>1</figcount><section><title>Base Types</title><figcount>0</figcount></section><section><title>Representing Relational Databases</title><figcount>1</figcount></section><section><title>Representing Object Databases</title><figcount>0</figcount></section></section></toc>", false)); }
/** A more realitic query with a version decl, no encoding. . */ @org.junit.Test public void prologVersion7V3() { final XQuery query = new XQuery( "\n" + " xquery version \"3.0\"; \n" + " declare boundary-space preserve; \n" + " declare default order empty greatest; \n" + " declare namespace ns = \"http://www.example.org/\"; \n" + " for $b in //book stable order by xs:decimal($b/price[1]) empty greatest \n" + " return $b/title", ctx); try { query.context(node(file("op/union/bib2.xml"))); result = new QT3Result(query.value()); } catch (final Throwable trw) { result = new QT3Result(trw); } finally { query.close(); } test( assertSerialization( "<title>Data on the Web</title><title>TCP/IP Illustrated</title><title>Advanced Programming in the Unix environment</title><title>The Economics of Technology and Content for Digital TV</title>", false)); }
/** context item expression where context item used as argumet to fn:sum. . */ @org.junit.Test public void externalcontextitem9() { final XQuery query = new XQuery("for $var in (/works/employee[1]) return $var/fn:sum((hours,hours))", ctx); try { query.context(node(file("docs/works-mod.xml"))); result = new QT3Result(query.value()); } catch (final Throwable trw) { result = new QT3Result(trw); } finally { query.close(); } test(assertEq("80")); }
/** . */ @org.junit.Test public void treeQueriesResultsQ4() { final XQuery query = new XQuery("<top_section_count> { count(/book/section) } </top_section_count>", ctx); try { query.context(node(file("docs/book.xml"))); result = new QT3Result(query.value()); } catch (final Throwable trw) { result = new QT3Result(trw); } finally { query.close(); } test(assertSerialization("<top_section_count>2</top_section_count>", false)); }
/** context item expression where context item is used as string. . */ @org.junit.Test public void externalcontextitem2() { final XQuery query = new XQuery( "for $var in /works/employee[1] return $var/xs:string(exactly-one(empnum))", ctx); try { query.context(node(file("docs/works-mod.xml"))); result = new QT3Result(query.value()); } catch (final Throwable trw) { result = new QT3Result(trw); } finally { query.close(); } test(assertStringValue(false, "E1")); }
/** context item expression where context item is an xs:boolean used with fn:not(). . */ @org.junit.Test public void externalcontextitem8() { final XQuery query = new XQuery( "for $var in (/works/employee[1]) return $var/fn:not(xs:boolean(exactly-one(hours) - 39))", ctx); try { query.context(node(file("docs/works-mod.xml"))); result = new QT3Result(query.value()); } catch (final Throwable trw) { result = new QT3Result(trw); } finally { query.close(); } test(assertBoolean(false)); }
/** Reference to a context item that has not been bound. . */ @org.junit.Test public void externalcontextitem24() { final XQuery query = new XQuery("works/employee[1]", ctx); try { query.context(node(file("docs/works-mod.xml"))); result = new QT3Result(query.value()); } catch (final Throwable trw) { result = new QT3Result(trw); } finally { query.close(); } test( assertSerialization( "<employee name=\"Jane Doe 1\" gender=\"female\">\n <empnum>E1</empnum>\n <pnum>P1</pnum>\n <hours>40</hours>\n </employee>", false)); }
/** * Simple call of "fn:trace" function used numbers manipulation queried from an xml file and the * entire query is given as argument to the function. . */ @org.junit.Test public void fnTrace12() { final XQuery query = new XQuery( "fn:trace((for $var in (/works//hours) return $var + $var) ,\"The Value of the given expression is: \")", ctx); try { query.context(node(file("docs/works-mod.xml"))); result = new QT3Result(query.value()); } catch (final Throwable trw) { result = new QT3Result(trw); } finally { query.close(); } test(assertStringValue(false, "80 140 40 160 40 80 40 60 24 80 160 40 40 40 80 160")); }
/** Simple call of "fn:trace" function used numbers manipulation queried from an xml file. . */ @org.junit.Test public void fnTrace11() { final XQuery query = new XQuery( "for $var in (/works//hours) return fn:trace(($var div 2) ,\"The Value of hours div/2 is: \")", ctx); try { query.context(node(file("docs/works-mod.xml"))); result = new QT3Result(query.value()); } catch (final Throwable trw) { result = new QT3Result(trw); } finally { query.close(); } test(assertStringValue(false, "20 35 10 40 10 20 10 15 6 20 40 10 10 10 20 40")); }
/** . */ @org.junit.Test public void treeQueriesResultsQ5() { final XQuery query = new XQuery( "<section_list> { for $s in //section let $f := $s/figure return <section title=\"{ $s/title/text() }\" figcount=\"{ count($f) }\"/> } </section_list>", ctx); try { query.context(node(file("docs/book.xml"))); result = new QT3Result(query.value()); } catch (final Throwable trw) { result = new QT3Result(trw); } finally { query.close(); } test( assertSerialization( "<section_list><section title=\"Introduction\" figcount=\"0\"/><section title=\"Audience\" figcount=\"0\"/><section title=\"Web Data and the Two Cultures\" figcount=\"1\"/><section title=\"A Syntax For Data\" figcount=\"1\"/><section title=\"Base Types\" figcount=\"0\"/><section title=\"Representing Relational Databases\" figcount=\"1\"/><section title=\"Representing Object Databases\" figcount=\"0\"/></section_list>", false)); }
/** . */ @org.junit.Test public void treeQueriesResultsQ2() { final XQuery query = new XQuery( "<figlist> { for $f in //figure return <figure> { $f/@* } { $f/title } </figure> } </figlist>", ctx); try { query.context(node(file("docs/book.xml"))); result = new QT3Result(query.value()); } catch (final Throwable trw) { result = new QT3Result(trw); } finally { query.close(); } test( assertSerialization( "<figlist><figure height=\"400\" width=\"400\"><title>Traditional client/server architecture</title></figure><figure height=\"200\" width=\"500\"><title>Graph representations of structures</title></figure><figure height=\"250\" width=\"400\"><title>Examples of Relations</title></figure></figlist>", false)); }