1 / 19

Introduction to XQuery and eXist

Introduction to XQuery and eXist. DSA. XSLT Tutorial Problems. Bad language : No <xsl:annotation ..> ! <xsd:annotation ..> for XML schema Some XSLT engines tolerant of extra tags (permissive), others fail Mime type table on our servers not set up Should be an entry for file suffices

Télécharger la présentation

Introduction to XQuery and eXist

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Introduction to XQuery and eXist DSA

  2. XSLT Tutorial Problems • Bad language : • No <xsl:annotation ..> ! • <xsd:annotation ..> for XML schema • Some XSLT engines tolerant of extra tags (permissive), others fail • Mime type table on our servers not set up • Should be an entry for file suffices • .xsl, .xslt • To set the MIME type • application/xml • Variations in server and browser configurations

  3. Solution: server-side XSLT • Several XSLT engines • Xalan ( a free Java application) • SAXON • The Native XML Database eXists includes a command to apply a stylesheet to an XML file and get the results – uses Xalan

  4. eXist Native XML Database • Open source • Wolfgang Meier is the chief architect • Written in Java • Deployable in different ways • Embedded in a Java application • Part of a Cocoon pipeline • As web application in Apache/Tomcat • With embedded Jetty HTTPserver (as on stocks) • Multiple Interfaces • REST – to Java servlet • SOAP • XML:RPC

  5. Native XML database • Well-formed XML documents can be added to the database • They are stored in an efficient, searchable B+ tree structure • Documents (files) are organised into collections in a filestore • Non-XML resources (XQuery, CSS, JPEG ..), etc can be stored as binary

  6. Executing an XQuery eXist: Server Client Browser User clicks link Get a.xql parameters servlet fetch a.xql parameters a.xql eXist DB html XQuery Engine render

  7. Simple XQuery xquery version "1.0"; <table border='2'> <tr><th>Name</th><th>Address</th></tr> {for $w in doc('/db/whisky/data_raw.xml')/Whisky/Distillery return <tr><td>{data($w/Name)}</td> <td>{data($w/Address)}</td> </tr> } </table> addressList.xql

  8. XQuery as HTML xQuery header xquery version "1.0"; <table border='2'> <tr><th>Name</th><th>Address</th></tr> {for $w in doc('/db/whisky/data_raw.xml')/Whisky/Distillery return <tr><td>{data($w/Name)}</td> <td>{data($w/Address)}</td> </tr> } </table> Xquery inside XML XPath expression to select nodes XQuery ‘variable’ addressList.xql

  9. Executing an XQuery with XSLT eXist: Server Client Browser User clicks link Get a.xql parameters servlet fetch a.xql parameters a.xql eXist DB XQuery Engine .xml xslt html XSLT Engine render

  10. Simplest XQuery -XSLT xquery version "1.0"; declare namespace transform = "http://exist-db.org/xquery/transform"; let $stylesheet := doc('/db/whisky/whisky.xslt'), $whiskySet := doc('/db/whisky/data_raw.xml') return transform:transform($whiskySet,$stylesheet,()) allWhiskys.xql

  11. Simplest XQuery -XSLT Comma separator xquery version "1.0"; declare namespace transform = "http://exist-db.org/xquery/transform"; let $stylesheet := doc('/db/whisky/whisky.xslt'), $whiskySet := doc('/db/whisky/data_raw.xml') return transform:transform($whiskySet,$stylesheet,()) Retrieve this document a FLWOR expression namespace prefix allWhiskys.xql

  12. XQuery with parameter xquery version=“1.0”; declare namespace transform = "http://exist-db.org/xquery/transform"; declare namespace request="http://exist-db.org/xquery/request"; let $whiskyType := request:request-parameter ("whiskyType",""), $stylesheet := doc('/db/whisky/whisky.xslt'), $whiskySet := <Whisky> {doc('/db/whisky/data_raw.xml')/Whisky/Distillery [WhiskyType = $whiskyType]} </Whisky> return transform:transform($whiskySet,$stylesheet,()) selectWhiskys.xql selectWhiskys.xql

  13. XQuery with parameter xquery version=“1.0”; declare namespace transform = "http://exist-db.org/xquery/transform"; declare namespace request="http://exist-db.org/xquery/request"; let $whiskyType := request:request-parameter ("whiskyType",""), $stylesheet := doc('/db/whisky/whisky.xslt'), $whiskySet := <Whisky> {doc('/db/whisky/data_raw.xml')/Whisky/Distillery [WhiskyType = $whiskyType]} </Whisky> return transform:transform($whiskySet,$stylesheet,()) Get the value of the request parameter with this name Create an XML node XPath filter selectWhiskys.xql

  14. XQuery is bi-lingualXML and XQuery • XML node (with a single root) <a> <b> h</b> </a> • XML Sequence of nodes (<a/>, <b/>, <c/>) • XQuery construct variable value $var function evaluation – see Function list concat($var,’.xm’) for loop FLWOR if-then-else if (cond) then expression else expression • Mixed expressions – need { } around XQuery to distinguish • <a> {if .. } {$x}</a> • if (cond) then <a> Fred </a> else ()

  15. FLWOR expression • FLWOR for $x in sequence let $a := expression, $b := expression where condition order by $var return expression • Returns a Sequence of nodes • Compare with SQL select columns from tables where condition order by • Returns a Relation (table)

  16. An XQuery sticky form • The script here has several shifts between XML to XQuery • Whole interface in one script • Equivalent to PHP + MySQL • XSLT revised to process a sequence of Distillery nodes into a sequence of HTML nodes.

  17. Suggested Suffices • XQuery .xql • XSLT .xslt • XML .xml • CSS .css • JPEG .jpg

  18. Tools for XQuery on stocks • Use a text editor (or Dreamweaver) • Use the admin interface with guest/guest login to create a directory and load all the files – including the XQuery files • To run a script, just click on the script in the directory listing – this will run the script (but with no parameters – you can add these in the Browser • This will show you the URL to execute it – you can then use this to link from any HTML outside the eXist database. • Use the test query interface to test small bits of XQuery and XPath

  19. eXist on your own machine • Use the Java client to • load files • move, copy,rename files • edit files in situ (but no Save-as) • execute queries • backup

More Related