XQuery/Extracting data from XHTML files

From Wikibooks, open books for an open world
Jump to navigation Jump to search

Motivation[edit | edit source]

To perform an XQuery on XHTML files that use the XHTML namespace.

Method[edit | edit source]

We will start our XQuery by adding the default namespace for XHTML.

   declare default element namespace "http://www.w3.org/1999/xhtml";

Sample Source Code[edit | edit source]

Assume that you have an well-formed XHTML file in the file /db/text/index.xhtml

xquery version "1.0";
 
declare default element namespace "http://www.w3.org/1999/xhtml";
 
declare option exist:serialize "method=html media-type=text/html indent=yes";
 
let $doc := doc('/db/test/index.xhtml')
let $body := $doc/html/body/*
 
return
<html>
   <head>
      <title>Replace Head</title>
   </head>
   <body>
      {$body}
   </body>
</html>