
function goback(){ 
  history.go(-1);
}


function c1() 
{
  document.forms[0].english.value ="C1: List books published by Addison-Wesley after 1991, including all their fields.";
  document.forms[0].qry.value ="<bib>{ $bib/book[@year > 1999] }</bib>";
}
function c2() 
{
  document.forms[0].english.value ="C2: List books published by Addison-Wesley after 1991, including their year and title.";
  document.forms[0].qry.value ="<bib>{ \n    for $b in $bib/book \n    where $b/publisher = \"Addison-Wesley\" and $b/@year > 1991 \n    return \n        <book year=\"{$b/@year}\">{$b/title}</book> \n }</bib>";
}
function c3() 
{
  document.forms[0].english.value ="C3: Create a flat list of all the title-author pairs, with each pair enclosed in a result element.";
  document.forms[0].qry.value ="<results>{ \n     for $b in $bib/book, \n         $t in $b/title, \n         $a in $b/author \n     return \n         <result>{$t}{$a}</result> \n }</results> \n ";
}
function c4 () {
  document.forms[0].english.value ="C4: For each book in the bibliography, list the title and authors, grouped inside a result element.";
  document.forms[0].qry.value ="<results>{ \n   for $b in ($bib/book) return ( \n      <result> \n         { $b/title }{ for $a in $b/author return $a } \n      </result> \n   ) \n}</results> ";
}
function c5 () {
  document.forms[0].english.value ="C5: For each book found in bib and in reviews, list the title of the book and its price from each source.";
  document.forms[0].qry.value ="<books-with-prices>{ \n    for $b in $bib//book, $a in $reviews//entry \n    where $b/title = $a/title return \n        <book-with-prices> \n            {$b/title} \n            <price-amazon>{data($a/price)}</price-amazon> \n            <price-bn>{data($b/price)}</price-bn> \n        </book-with-prices> \n }</books-with-prices>";
}

function c6 () {
  document.forms[0].english.value ="C6: List the titles and years of all books published by Addison-Wesley after 1991, in alphabetic order.";
  document.forms[0].qry.value ="<bib> { \n    for $b in $bib/book\n    where $b/publisher = \"Addison-Wesley\" and $b/@year > 1991\n    order by $b/title\n    return\n        <book>\n            { $b/@year }{ $b/title }\n        </book> \n} </bib>";
}

function q1() 
{
  document.forms[0].english.value ="Q1: Select all b child elements";
  document.forms[0].qry.value ="<a><b>b</b><b>c</b></a>/b";
}
function q2() 
{
  document.forms[0].english.value ="Q2: Select all b descendant elements";
  document.forms[0].qry.value ="<a><b>b</b><b>c</b></a>//b";
}
function q3 () {
  document.forms[0].english.value ="Q3: Select all child nodes of the current node";
  document.forms[0].qry.value ="<a><b>b</b><b>c</b></a>/child::node()";
}
function q4()
{
  document.forms[0].english.value ="Q4: Select the current node and all of its decendants";
  document.forms[0].qry.value ="<a><b>b</b><b>c</b></a>/descendant-or-self::node() \n";
}
function q5 () {
  document.forms[0].english.value ="Q5: If 1 = 1 then \"a\" else true";
  document.forms[0].qry.value ="if (1 = 1) then 1 else \"a\"";
}
function q6 () {
  document.forms[0].english.value ="Q6: For each item in (1, 2, 3) expand the return clause";
  document.forms[0].qry.value ="for $a in (1, 2, 3)\n   return <a>{$a}</a>";
}
function q7 () {
  document.forms[0].english.value ="Q7: Treat <a>1</a> as an instance of zero or more text() elements";
  document.forms[0].qry.value ="<a>1</a> treat as element(a, text())*";
}
function q8 () {
  document.forms[0].english.value ="Q8: Select the second element in list d";
  document.forms[0].qry.value ="<d><a>dog</a><a>cat</a><a>horse</a></d>/a[2]";
}
function q9() {
  document.forms[0].english.value ="Q9: Selects the name attribute of the context node";
  document.forms[0].qry.value ="<a name=\"john\">run</a>/@name";
}
function q10 () {
  document.forms[0].english.value ="Q10: Select the chapter children that have one or more title children containing \"Introduction\"";
  document.forms[0].qry.value ="<a><chapter><title>Introduction</title></chapter></a>/chapter\n[title=\"Introduction\"]";
}
function q11 () {
  document.forms[0].english.value ="Q11: XQuery provides the usual arithmetic operators";
  document.forms[0].qry.value ="let $m := .5, $x := 2, $b := -2 \nreturn $m * $x + $b";
}
function q12 () {
  document.forms[0].english.value ="Q12: Define a recursive function that computes the factorial of a positive integer.";
  document.forms[0].qry.value ="declare function fact($n as xs:integer) as xs:integer \n{ \n    if ($n = 1) then 1 else $n * fact($n - 1)\n};\nfor $i in 1 to 5 return fact($i)";
}
function q13 () {
  document.forms[0].english.value ="Q13: Use a typeswitch statement to reformat data based on its type.";
  document.forms[0].qry.value ="let $list := (<a>{1}</a>, <a>{1.1}</a>, <a>{1.5E1}</a>) return\nfor $i in $list return\n    typeswitch ($i) \n    case element(a, xs:integer) return <int>{data($i)}</int>\n    case element(a, xs:decimal) return <dec>{data($i)}</dec>\n    case element(a, xs:double)  return <dbl>{data($i)}</dbl>\n    default return \"error\"";
}
function t1() 
{
  document.forms[0].english.value ="T1: the static type of an \"if\" statement is the union of the types of its two alternatives";
  document.forms[0].qry.value ="if (true()) then 1 else true()";
}
function t2() 
{
  document.forms[0].english.value ="T2: The static type of a sequence is a sequence of types";
  document.forms[0].qry.value ="(1, true(), 2)";
}
function t3() 
{
  document.forms[0].english.value = "T3: Check if an element matches a specific type.";
  document.forms[0].qry.value = "<a><b>c</b><c>d</c></a> instance of\n   element(a, (element(b, text()), element(c, text())))";
}
function t4() 
{
  document.forms[0].english.value ="T4: Check if a sequence is an instance of a repetition type";
  document.forms[0].qry.value ="(1, 2, 3) instance of xs:integer*";
}
function t5() 
{
  document.forms[0].english.value ="T5: An example of a static typing error";
  document.forms[0].qry.value ="substring(\"abc\", if (true()) then () else 2)";
}
function t6() 
{
  document.forms[0].english.value ="T6: One type is a subtype of another if every instance of the first is an instance of the second";
  document.forms[0].qry.value ="subtype(element(a, xs:string), element(a, xs:anyAtomicType)*)";
}
function t7() 
{
  document.forms[0].english.value ="T7: Define a recursive type for a sequence of one or more trees made of f elements and xs:string leaves";
  document.forms[0].qry.value ="declare type F := element(f, (F | xs:string))+;\n\n<f><f>a</f><f>b</f></f> validate as F";
}
function t8() 
{
  document.forms[0].english.value ="T8: Compare two recursive types in various ways";
  document.forms[0].qry.value ="declare type F := element(f, (F | xs:string))+; \ndeclare type G := element(f, (G+ | xs:string)); \n\n(subtype(G, F), subtype(F, G), subtype(F, G+))";
}
function t9() 
{
  document.forms[0].english.value ="T9: Statically check if the expression is an instance of the specified type and change its static type";
  document.forms[0].qry.value ="(<a>01</a>, <b>02</b>) assert as element(*, text())*";
}
function t10() 
{
  document.forms[0].english.value ="T10: Dynamically treat an expression as the specified type.  The dynamic type must be a subtype of the specified type.";
  document.forms[0].qry.value ="<a><b>c</b></a>//b treat as element(b, text())";
}
function t11() 
{
  document.forms[0].english.value ="T11: Dynamically validate the expression against the specified type changing both its static and dynamic types";
  document.forms[0].qry.value ="(<a>01</a>, <b>02</b>) validate as element(*, xs:integer)*";
}
function t12() 
{
  document.forms[0].english.value ="T12: Dynamically cast the expression to the new type possibly changing its value";
  document.forms[0].qry.value ="<a>1.1</a> cast as xs:double";
}
function t13() 
{
  document.forms[0].english.value ="T13: Check if the expression is an instance of the specified type and return true or false";
  document.forms[0].qry.value ="<a x=\"1\" y=\"2\"/>/@* instance of attribute(*, xs:untypedAtomic)+ ";
}
function t14() 
{
  document.forms[0].english.value ="T14: An example of a union type used with a formal parameter.";
  document.forms[0].qry.value ="declare type T := (element(a, text()?) | element(b, text()?));\n\ndeclare function fix($list as T*) as element(a, text()?)*\n{\n    for $i in $list return <a>{$i/text()}</a>\n};\nfix((<a>1</a>, <b>2</b>))\n";
}
function t15() 
{
  document.forms[0].english.value ="T15: An example of type promotion and atomization used with function arguments.";
  document.forms[0].qry.value ="declare function half($x as xs:double) as xs:double\n{\n    $x div 2 \n};\nhalf(1), half(1.1), half(1.2E1), half(<a>1.5</a>)";
}
function t16() 
{
  document.forms[0].english.value ="T16: Examples of type promotion and atomization used with arithmetic operators.";
  document.forms[0].qry.value ="1.5 + 2.5E1,  <a>1.5</a> + 2.5E1,  <b x=\"1.5\"/>/@x + 2.5E1";
}
function t17() 
{
  document.forms[0].english.value ="T17: For completeness promotion must work with unions of simple types as well as simple types.";
  document.forms[0].qry.value ="declare function str($x as (xs:decimal|xs:boolean)) as xs:string\n{\n    string($x)\n};\nstr(1 treat as (xs:integer|xs:boolean))";
}

function f1() 
{
  document.forms[0].english.value ="Q1: List the titles of all of Shakespeare's plays";
  document.forms[0].qry.value ="<PLAYS>{\n    doc(\"plays.xml\")/PLAYS/PLAY/TITLE\n}</PLAYS>";
}
function f2() 
{
  document.forms[0].english.value ="Q2: How many plays did Shakespeare write";
  document.forms[0].qry.value ="<COUNT>{ count(doc(\"plays.xml\")/PLAYS/PLAY) }</COUNT>";
}
function f3() 
{
  document.forms[0].english.value ="Q3: List the full title of Hamlet and list all of its players";
  document.forms[0].qry.value ="<RESULT>{\n    let $play := doc(\"plays.xml\")/PLAYS/PLAY\n    [TITLE ftcontains \"Hamlet\"] \n    return\n        ($play/TITLE, <PARTS>{ $play//PERSONA }</PARTS>)\n}</RESULT>";
}
function f4() 
{
  document.forms[0].english.value ="Q4: What play, act, scene and speech contains the quote\n \"to be, or not to be\"";
  document.forms[0].qry.value ="for $speech in doc(\"plays.xml\")//\nSPEECH[. ftcontains \"to be, or not to be\"]\nreturn (   \n    $speech/../../../TITLE, \n    $speech/../../TITLE, \n    $speech/../TITLE,\n    $speech )";
}
function f5() 
{
  document.forms[0].english.value ="Q5: Where does the phrase \"there are more things\" occur";
  document.forms[0].qry.value ="for $speech in doc(\"plays.xml\")//\nSPEECH[. ftcontains \"there are more things\"]\nreturn (   \n    $speech/../../../TITLE, \n    $speech/../../TITLE, \n    $speech/../TITLE,\n    $speech )";
}
function f6() 
{
  document.forms[0].english.value ="Q6: List all the speeches that contain the words \"there are more things\" in any location";
  document.forms[0].qry.value ="for $speech in doc(\"plays.xml\")//\nSPEECH[. ftcontains \"there are more things\" all words]\nreturn (   \n    $speech/../../../TITLE, \n    $speech/../../TITLE, \n    $speech/../TITLE,\n    $speech )";
}
function f7() 
{
  document.forms[0].english.value ="Q7: List the lines that contain any of the words \"saturn\" or \"neptune\"";
  document.forms[0].qry.value ="doc(\"plays.xml\")//LINE\n[.ftcontains \"saturn neptune\" any word]";
}
function f8() 
{
  document.forms[0].english.value ="Q8 What's the last thing Juliet said in Act V of \nRomeo and Juliet";
  document.forms[0].qry.value ="(doc(\"plays.xml\")//PLAY\n[TITLE ftcontains \"Romeo and Juliet\" all words]//\nACT[TITLE ftcontains \"Act V\" all words]//\nSPEECH[SPEAKER ftcontains \"Juliet\"])[position() = last()] ";
}
function f9() 
{
  document.forms[0].english.value ="Q9 List the speech where variations of the words \"she teaches the torch\" are all used in the same line";
  document.forms[0].qry.value ="doc(\"plays.xml\")//SPEECH\n[LINE ftcontains \"she teaches the torch\" all words with stemming]";
}
function f10() 
{
  document.forms[0].english.value ="Q10: List all the speeches that contain derivations of the words \"holy\" and \"palm\" and list them in reverse order by their relevancy score.";
  document.forms[0].qry.value ="for $p in doc(\"plays.xml\")//SPEECH\nlet score $s := $p ftcontains \"holy palm\" all words with stemming\nwhere $s > 0\norder by $s descending\nreturn ($p, <SCORE>{$s}</SCORE>)";
}

function displayCases(select)
{
    index = select.selectedIndex;
    if (index == "1") {
        c1();
    } else if (index == "2") {
        c2();
    } else if (index == "3") {
        c3();
    } else if (index == "4") {
        c4();
    } else if (index == "5") {
        c5();
    } else if (index == "6") {
        c6();
    }
}
function displayQuery(select)
{
    index = select.selectedIndex;
    if (index == "1") {
        q1();
    } else if (index == "2") {
        q2();
    } else if (index == "3") {
        q3();
    } else if (index == "4") {
        q4();
    } else if (index == "5") {
        q5();
    } else if (index == "6") {
        q6();
    } else if (index == "7") {
        q7();
    } else if (index == "8") {
        q8();
    } else if (index == "9") {
        q9();
    } else if (index == "10") {
        q10();
    } else if (index == "11") {
        q11();
    } else if (index == "12") {
        q12();
    } else if (index == "13") {
        q13();
    }
}
function displayTypeQuery(select)
{
    index = select.selectedIndex;
    if (index == "1") {
        t1();
    } else if (index == "2") {
        t2();
    } else if (index == "3") {
        t3();
    } else if (index == "4") {
        t4();
    } else if (index == "5") {
		t5();
    } else if (index == "6") {
		t6();
    } else if (index == "7") {
		t7();
    } else if (index == "8") {
		t8();
    } else if (index == "9") {
		t9();
    } else if (index == "10") {
		t10();
    } else if (index == "11") {
		t11();
    } else if (index == "12") {
		t12();
    } else if (index == "13") {
		t13();
    } else if (index == "14") {
		t14();
    } else if (index == "15") {
		t15();
    } else if (index == "16") {
		t16();
    } else if (index == "17") {
		t17();
    }
}
function chooseFulltext(select)
{
    index = select.selectedIndex;
    if (index == "1") {
        f1();
    } else if (index == "2") {
        f2();
    } else if (index == "3") {
        f3();
    } else if (index == "4") {
        f4();
    } else if (index == "5") {
        f5();
    } else if (index == "6") {
        f6();
    } else if (index == "7") {
        f7();
    } else if (index == "8") {
        f8();
    } else if (index == "9") {
        f9();
    } else if (index == "10") {
        f10();
    }
}


