{"id":23,"date":"2012-08-10T01:42:20","date_gmt":"2012-08-10T01:42:20","guid":{"rendered":"http:\/\/tregner.com\/flare-blog\/?p=23"},"modified":"2012-08-10T22:50:52","modified_gmt":"2012-08-10T22:50:52","slug":"use-xquery-with-flare-files","status":"publish","type":"post","link":"https:\/\/tregner.com\/flare-blog\/use-xquery-with-flare-files\/","title":{"rendered":"Use XQuery with Flare Files"},"content":{"rendered":"<p>XQuery is another XML query language. XQuery uses XPath expressions, so XPath 2.0 is included with XQuery 1.0. The World Wide Web Consortium (W3C) published XQuery 1.0: An XML Query Language as recommendation in 2007 and edited to XQuery 1.0: An XML Query Language (Second Edition) in 2010. The W3C recommendation is posted at:<\/p>\n<p><a href=\"http:\/\/www.w3.org\/TR\/xquery\/\" target=\"_blank\">http:\/\/www.w3.org\/TR\/xquery\/<\/a><\/p>\n<p>To use XQuery, you need an XQuery implementation. W3C lists implementations known to W3C at:<\/p>\n<p><a href=\"http:\/\/www.w3.org\/XML\/Query#implementations\" target=\"_blank\">http:\/\/www.w3.org\/XML\/Query\/#implementations<\/a><\/p>\n<p>To demonstrate XQuery, we will use a freely available technology. As of writing this, Microsoft SQL Server 2012 Express has an implementation of XQuery. You can download the database, tools, or both. But don&#8217;t feel limited to using the SQL\u00a0Server implementation to learn about XQuery.<\/p>\n<p>In the <a title=\"XPath post\" href=\"https:\/\/tregner.com\/flare-blog\/use-xpath-with-flare-files\" target=\"_blank\">XPath post<\/a>, we queried a Flare TOC for the Link attribute nodes for every TocEntry element. But we retrieved the attribute node. We could not filter for just the attribute value. With XQuery, we can accomplish that. Here is an XQuery code executed with Transact-SQL\u00a0to create hyperlinks for every TOC entry in a generated Flare TOC in the Data folder of an HTML5 output.<\/p>\n<div class=\"CodeIndent\">\n<pre xml:space=\"preserve\">DECLARE @FLTOC XML\r\n\r\nSET @FLTOC =\r\n'&lt;?xml version=\"1.0\" encoding=\"utf-8\"?&gt;\r\n&lt;CatapultToc\r\n  Version=\"1\"&gt;\r\n  &lt;TocEntry\r\n    Title=\"Test Topic 1\"\r\n    Link=\"\/Content\/TestTopic1.htm\" \/&gt;\r\n  &lt;TocEntry\r\n    Title=\"Test Topic 2\"\r\n    Link=\"\/Content\/TestTopic2.htm\" \/&gt;\r\n  &lt;TocEntry\r\n    Title=\"Test Topic 3\"\r\n    Link=\"\/Content\/TestTopic3.htm\" \/&gt;\r\n&lt;\/CatapultToc&gt;'\r\n\r\nSELECT @FLTOC.query('for $TocEntry in (\/\/TocEntry) \r\n\t\t\treturn &lt;a href=\"{$TocEntry\/@Link}\"&gt;{string($TocEntry\/@Title)}&lt;\/a&gt;') AS Links<\/pre>\n<\/div>\n<p>The output is:<\/p>\n<div class=\"CodeIndent\">\n<pre xml:space=\"preserve\">&lt;a href=\"\/Content\/TestTopic1.htm\"&gt;Test Topic 1&lt;\/a&gt;\r\n&lt;a href=\"\/Content\/TestTopic2.htm\"&gt;Test Topic 2&lt;\/a&gt;\r\n&lt;a href=\"\/Content\/TestTopic3.htm\"&gt;Test Topic 3&lt;\/a&gt;<\/pre>\n<\/div>\n<p>But there is a pitfall here. Not every TocEntry element has a link attribute. So be careful. If you are working with a FLTOC file in a project, there is another pitfall. Not every link is to a topic file. So be even more careful there.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>XQuery is another XML query language. XQuery uses XPath expressions, so XPath 2.0 is included with XQuery 1.0. The World Wide Web Consortium (W3C) published XQuery 1.0: An XML Query Language as recommendation in 2007 and edited to XQuery 1.0: An XML Query Language (Second Edition) in 2010. The W3C recommendation is posted at: http:\/\/www.w3.org\/TR\/xquery\/&hellip; <a class=\"more-link\" href=\"https:\/\/tregner.com\/flare-blog\/use-xquery-with-flare-files\/\">Continue reading <span class=\"screen-reader-text\">Use XQuery with Flare Files<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":[],"categories":[4],"tags":[5,12],"_links":{"self":[{"href":"https:\/\/tregner.com\/flare-blog\/wp-json\/wp\/v2\/posts\/23"}],"collection":[{"href":"https:\/\/tregner.com\/flare-blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/tregner.com\/flare-blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/tregner.com\/flare-blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/tregner.com\/flare-blog\/wp-json\/wp\/v2\/comments?post=23"}],"version-history":[{"count":9,"href":"https:\/\/tregner.com\/flare-blog\/wp-json\/wp\/v2\/posts\/23\/revisions"}],"predecessor-version":[{"id":81,"href":"https:\/\/tregner.com\/flare-blog\/wp-json\/wp\/v2\/posts\/23\/revisions\/81"}],"wp:attachment":[{"href":"https:\/\/tregner.com\/flare-blog\/wp-json\/wp\/v2\/media?parent=23"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/tregner.com\/flare-blog\/wp-json\/wp\/v2\/categories?post=23"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/tregner.com\/flare-blog\/wp-json\/wp\/v2\/tags?post=23"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}