Loading TOC...

MarkLogic 10 Product Documentation
xhtml:restructure

xhtml:restructure(
   $doc as node()?
) as node()?

Summary

Turn an XHTML with flat structure into one with div structure based on the header elements.

Parameters
doc The source XHTML.

Example

  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>
  

Stack Overflow iconStack Overflow: Get the most useful answers to questions from the MarkLogic community, or ask your own question.