<p>I have been reading a lot of XQuery tutorials on the website. Almost all of them are teaching me XQuery syntax. Let's say I have understood the XQuery syntax, how am I going to actually implement XQuery on my website?</p>
<p>For example, I have <strong>book.xml</strong>:</p>

<pre><code>&lt;?xml version=&quot;1.0&quot; encoding=&quot;iso-8859-1&quot; ?&gt;
&lt;books&gt;
&lt;book&gt;
   &lt;title&gt;Doraemon&lt;/title&gt;
   &lt;authorid&gt;1&lt;/authorid&gt;
&lt;/book&gt;
&lt;book&gt;
   &lt;title&gt;Ultraman&lt;/title&gt;
   &lt;authorid&gt;2&lt;/authorid&gt;
&lt;/book&gt;
&lt;/books&gt;
</code></pre>
<p>Then, I have <strong>author.xml</strong></p>

<pre><code>&lt;?xml version=&quot;1.0&quot; encoding=&quot;iso-8859-1&quot; ?&gt;
&lt;authors&gt;
&lt;author id=&quot;1&quot;&gt;Mr A&lt;/author&gt;
&lt;author id=&quot;2&quot;&gt;Mr B&lt;/author&gt;
&lt;/authors&gt;
</code></pre>
<p>I want to generate HTML which looks like following:</p>

<pre><code>&lt;table&gt;
    &lt;tr&gt;  &lt;td&gt;Title&lt;/td&gt;     &lt;td&gt;Author&lt;/td&gt; &lt;/tr&gt;
    &lt;tr&gt;  &lt;td&gt;Doraemon&lt;/td&gt;  &lt;td&gt;Mr A&lt;/td&gt;   &lt;/tr&gt;
    &lt;tr&gt;  &lt;td&gt;Ultraman&lt;/td&gt;  &lt;td&gt;Mr B&lt;/td&gt;   &lt;/tr&gt;
&lt;/table&gt;
</code></pre>
<p>Please show me some examples. Or any website that I can do reference. Thanks very much.</p>

[{'answer_id': 82980, 'author': 'Community', 'author_id': -1, 'author_profile': 'https://Stackoverflow.com/users/-1', 'pm_score': 0, 'selected': False, 'text': '<pre><code>&lt;table&gt;\n&lt;tr&gt;&lt;td&gt;Title&lt;td&gt;&lt;td&gt;Author&lt;td&gt;&lt;/tr&gt;\n{\n    let $authordoc := fn:doc("author.xml")\n    for $book in fn:doc("book.xml")/books/book\n    return\n        &lt;tr&gt;\n                &lt;td&gt;{ $book/title }&lt;/td&gt;\n                &lt;td&gt;{ $authordoc/authors/author/[@id eq $book/authorid] }&lt;/td&gt;\n        &lt;/tr&gt;\n}\n&lt;/table&gt;\n</code></pre>\n\n<p>ps: haven\'t tested/executed it, but this is how one solution could look like</p>\n'}, {'answer_id': 89704, 'author': 'frglps', 'author_id': 6015, 'author_profile': 'https://Stackoverflow.com/users/6015', 'pm_score': 3, 'selected': False, 'text': '<pre><code>(: file: titles.xqy :)\n&lt;table&gt;\n&lt;tr&gt;&lt;th&gt;title&lt;/th&gt;&lt;th&gt;author&lt;/th&gt;&lt;/tr&gt;\n{\nlet $books-doc := doc("books.xml")\nlet $authors-doc := doc("authors.xml")\nfor $b in $books-doc//book,\n    $a in $authors-doc//author\nwhere $a/@id = $b/authorid\nreturn \n&lt;tr&gt;\n    &lt;td&gt;{$b/title/text()}&lt;/td&gt;\n    &lt;td&gt;{$a/text()}&lt;/td&gt;\n&lt;/tr&gt;\n}\n</code></pre>\n\n<p></p>\n'}, {'answer_id': 108507, 'author': 'Mattio', 'author_id': 19626, 'author_profile': 'https://Stackoverflow.com/users/19626', 'pm_score': 2, 'selected': False, 'text': "<p>To be completely honest, maybe you don't need to use XQuery at all.  </p>\n\n<p>If you need to transform moderately complex XML documents from XML to HTML, I would recommend using XSL.  Personally, I found XSL easier to learn than XQuery.  There are also a larger number of examples and tutorials available online because XSL has been around longer.</p>\n\n<p>We're currently using XQuery only because it's required as part of a piece of specialized XML software we've licensed.  XQuery is a fantastic tool for selecting pieces of XML from a large repository, but we still use XSL to transform our documents.</p>\n"}, {'answer_id': 109605, 'author': 'Sixty4Bit', 'author_id': 1681, 'author_profile': 'https://Stackoverflow.com/users/1681', 'pm_score': 2, 'selected': False, 'text': "<p>XQuery is similar to SQL in that it allows you to retrieve specific portions of data from a large data repository. SQL is used for relational databases (MS SQL Server, Oracle, Sybase, MySQL, PostreSQL, SQLite, etc...) and XQuery is used for XML databases (MARKLogic, Sedena, Qexo, Qizx/db, etc...).</p>\n\n<p>MARKLogic gives you XDB servers and HTTP servers. You can have a typical web server and connect to MARKLogic through XDB or you can use their HTTP server and mix your XQuery with your HTML directly.</p>\n\n<p>I suggest downloading MARKLogic's developer server (allows for 100MB of documents) and giving it a try.</p>\n"}, {'answer_id': 144305, 'author': 'MattMcKnight', 'author_id': 8136, 'author_profile': 'https://Stackoverflow.com/users/8136', 'pm_score': 2, 'selected': False, 'text': '<p>You need a server or a library to process the xml into html.  In my opinion, XQuery is much better than XSLT at this sort of thing when you are dealing with anything slightly complex. It is a much cleaner language as well. This website has <a href="http://www.sqlsummit.com/XQueryProv.htm" rel="nofollow noreferrer">a nice list of XQuery processors</a>.</p>\n'}, {'answer_id': 7137531, 'author': 'masoud ramezani', 'author_id': 191997, 'author_profile': 'https://Stackoverflow.com/users/191997', 'pm_score': 1, 'selected': False, 'text': '<p>please see the below link :</p>\n\n<p><a href="http://beyondrelational.com/blogs/jacob/archive/2009/08/19/xquery-lab-47-generating-html-table-from-xml-data.aspx" rel="nofollow">http://beyondrelational.com/blogs/jacob/archive/2009/08/19/xquery-lab-47-generating-html-table-from-xml-data.aspx</a></p>\n'}, {'answer_id': 7285610, 'author': 'Basel Shishani', 'author_id': 804138, 'author_profile': 'https://Stackoverflow.com/users/804138', 'pm_score': 1, 'selected': False, 'text': "<p>There can be many scenarios for using XQuery in a website development setting:</p>\n\n<p><strong>Generating pages dynamically:</strong></p>\n\n<p>You would need a library that provides an API that you can call from your server-side code, this would be the case if your XML data is stored say in a conventional database or on the file system. For example: Zorba provides such an API for PHP, and there is the XQuery API for Java etc.</p>\n\n<p>If your XML data is stored in an XML database server that supports XQuery, then you would issue your XQuery queries to the server and get the results back. There are many open source and commercial products in this category. BaseX is an open source example.</p>\n\n<p><strong>Generating pages statically:</strong></p>\n\n<p>You might wish to generate some of the HTML pages statically from XML data. In this case you can run a command line XQuery utility, for example Zorba, Saxon, BaseX and many others provide such CLI tools. Or you can also do it from your own scripts using an API.</p>\n\n<p>Then you would define rules in your build system to execute these commands or scripts whenever your XML data changes.</p>\n\n<p>In both the static and dynamic approaches, you can set your environment so that XQuery plays along with your templating system, for example, instead of generating whole HTML pages by XQuery, you can generate HTML segments based on XML, and then plug them into your templates.</p>\n\n<p><strong>Uses other than transformations:</strong></p>\n\n<p>The above cases are about transforming XML to HTML, but XQuery can be used in other ways in the web development process. One way I find it useful is to modify XML documents. Say you have a long XML document and you would like to modify field values or add fields or attributes - you can use the XQuery Update Facility extension to achieve that.</p>\n\n<p>Hope this helps. I didn't discuss your example because I assume it's just for clarification.</p>\n"}]
['https://Stackoverflow.com/questions/80770', 'https://Stackoverflow.com', 'https://Stackoverflow.com/users/-1/']