
xhtml:restructure( $doc as node()? ) as node()?
Turn an XHTML with flat structure into one with div structure based on the header elements.
| Parameters | |
|---|---|
| doc | The source XHTML. |
xquery version "1.0-ml";
declare default element namespace "http://www.w3.org/1999/xhtml";
import module namespace xhtml = "http://marklogic.com/cpf/xhtml"
at "/MarkLogic/conversion/xhtml.xqy";
let $unstructured :=
<html>
<head><title>Example</title></head>
<body>
<h1>First section</h1>
<p>First paragraph.</p>
<p>Second paragraph.</p>
<h2>Subheader</h2>
<p>Sub paragraph.</p>
<h1>Second section</h1>
<p>Last paragraph.</p>
</body>
</html>
return xhtml:restructure( $unstructured )
Returns:
<html>
<head><title>Example</title></head>
<body>
<div class="mlsection1">
<h1>First section</h1>
<p>First paragraph.</p>
<p>Second paragraph.</p>
<div class="mlsection2">
<h2>Subheader</h2>
<p>Sub paragraph.</p>
</div>
</div>
<div class="mlsection1">
<h1>Second section</h1>
<p>Last paragraph.</p>
</div>
</body>
</html>