This page was generated
December 08, 2009
5:50 PM
XQuery Function Reference

Module: WordProcessingML Support

The WordProcessingML function module is included in the Toolkit for Word zip package as the following file:

  • zip_dir/xquery/word-processing-ml-support.xqy

where zip_dir is the directory in which the Toolkit for Word was unzipped.

To use the word-processing-ml-support.xqy module in your own XQuery modules, copy it to your App Server root and include a line similar to the following in your XQuery prolog:

import module namespace ooxml="http://marklogic.com/openxml" 
	    at "/word-processing-ml-support.xqy";

The WordProcessingML functions are used to manipulate Microsoft Office Open XML documents.

Function Summary
ooxml:body This function creates a document body (w:body) element.
ooxml:base64-opc-format This function formats a base64 encoded string for Office 2007.
ooxml:base64-string-to-binary This function returns the binary for the provided base64 encoded string.
ooxml:binary-to-base64-string This function returns the base64 encoded string for the provided binary.
ooxml:create-paragraph This function creates a w:p element from the specified string.
ooxml:create-simple-docx This function creates a .zip file that is a .docx package containing the minimum parts required to be a valid package.
ooxml:custom-xml This function tags $content with w:customXml and sets the @element value to $tag.
ooxml:custom-xml-entity-highlight This function highlights terms in $nodes identified by cts:entity-highlight() by applying <w:customXml w:element={$cts:entity-type}> to the term.
ooxml:custom-xml-highlight This function highlights $hightlight-term in $nodes by applying <w:customXml w:element={$tag-name}> to the term.
ooxml:default-content-types This function creates a default content types element for the .docx package ([Content_Types].xml).
ooxml:directory-uris This function returns the URIs for files extracted from .docx package using Open XML Extract pipeline.
ooxml:document This function creates a document for the .docx package (word/document.xml).
ooxml:document-rels This function creates a default document relationships element for a .docx package (word/_rels/document.xml.rels).
ooxml:docx-manifest This function constructs a manifest for the given URIs in the directory.
ooxml:docx-package This function creates a .zip file that is the .docx package containing the parts passed in as parameters.
ooxml:font-table This function creates a default w:fonts element for a .docx package (word/fontTable.xml).
ooxml:get-custom-xml-ancestor This function returns the greatest ancestor of the specified node that is either an immediate parent of type w:customXml or w:sdt, a parent of that parent, and so on until the parent is not a w:customXml or w:sdt element.
ooxml:get-directory-package This function returns a document in the OPC (Open Packaging Convention) format XML.
ooxml:get-mimetype This function returns the mimetype for the given URI.
ooxml:get-paragraph-style-id This function returns the @val attribute for a w:pStyle element (child of w:pPr) from $pstyle.
ooxml:get-paragraph-styles This function returns the paragraph properties.
ooxml:get-run-style-id This function returns the values for the attribute @val for a w:rStyle element (which is a child of a w:rPr element).
ooxml:get-run-styles This function returns paragraph run styles.
ooxml:get-style-definition This function returns the style definition from styles.xml for the given style ID.
ooxml:list-paragraph-property This function returns a paragraph properties element (w:pPr) for a ListParagraph style identified by id.
ooxml:numbering This function creates a default w:numbering element for a .docx package (word/numbering.xml).
ooxml:package This function returns a document in the OPC (Open Packaging Convention) format XML.
ooxml:package-files-only This function returns only files for an extracted .docx.
ooxml:package-rels This function creates a default package relationships element for the .docx package (_rels/.rels).
ooxml:paragraph This function creates a document paragraph (w:p) element.
ooxml:remove-paragraph-styles This function removes all properties from w:p paragraphs.
ooxml:replace-custom-xml-element This function replaces any @element values for w:customXml with $newtag, where w:customXml[@w:element = $oldtag].
ooxml:replace-package-document This function replaces the document.xml in the specifed OPC document with parameter $document-xml.
ooxml:replace-paragraph-styles This function sets paragraph properties for paragraphs (w:p) within a block.
ooxml:replace-run-styles This function sets run properties for runs (w:r) within a block.
ooxml:replace-style-definition This function replaces w:style elements (style definitions) in w:styles (the styles.xml file from a .docx package).
ooxml:run This function creates a run (w:r) element.
ooxml:settings This function creates a default w:settings element for a .docx package (word/settings.xml).
ooxml:simple-content-types This function creates a content types element for a .docx package of minimal parts ([Content_Types].xml).
ooxml:styles This function creates a default w:styles element for a .docx package (word/styles.xml).
ooxml:text This function creates the text element (w:t).
ooxml:theme This function creates a default w:theme element for a .docx package (word/themes/theme1.xml).
Function Detail
ooxml:body(
$block-content as element()*
)  as  element(w:body)
Summary:

This function creates a document body element.

Parameters:
$block-content : The blockcontent to be populated within the document body.

Usage Notes:

There are two main levels of content in the document.xml; block-level and inline content. Block level describes the structure of the document, and includes paragraphs and tables. Anything that can be a child of w:body may be passed as $block-content.

Example:
xquery version "1.0-ml";
import module namespace ooxml= "http://marklogic.com/openxml" 
          at "/MarkLogic/openxml/word-processing-ml-support.xqy";

let $para := ooxml:create-paragraph("Hello there everyone.")
return ooxml:body($para)
=> 
<w:body xmlns:w="http://schemas.openxmlformats.org/wordprocessingml/2006/main">
  <w:p>
     <w:r><w:t>Hello there everyone.</w:t></w:r>
  </w:p>
</w:body>
  

ooxml:base64-opc-format(
$binstring as xs:string
)  as  xs:string
Summary:

This function formats a base64 encoded string for Office 2007.

Parameters:
$binstring : The base64 string to be formatted.

Example:
xquery version "1.0-ml";
import module namespace ooxml= "http://marklogic.com/openxml" 
          at "/MarkLogic/openxml/word-processing-ml-support.xqy";

let $img:= fn:doc("/ackbar.jpg")/node()
return ooxml:base64-opc-format(ooxml:binary-to-base64-string($img))

=> 
/9j/4AAQSkZJRgABAQAAAQABAAD/2wBDAAkGBwgHBgkIBwgKCgkLDRYPDQwMDRsUFRAWIB0iIiA
dHx8kKDQsJCYxJx8fLT0tMTU3Ojo6Iys/RD84QzQ5Ojf/2wBDAQoKCg0MDRoPDxo3JR8lNzc3Nzc
3Nzc3Nzc3Nzc3Nzc3Nzc3Nzc3Nzc3Nzc3Nzc3Nzc3Nzc3Nzc3Nzc3Nzc3Nzf ...

  
  

ooxml:base64-string-to-binary(
$binstring as xs:string
)  as  xs:binary()
Summary:

This function returns the binary for the provided base64 encoded string.

Parameters:
$binstring : The base64 string

Example:
xquery version "1.0-ml";
import module namespace ooxml= "http://marklogic.com/openxml" 
          at "/MarkLogic/openxml/word-processing-ml-support.xqy";

let $img:= fn:doc("/ackbar.jpg")/node()
let $binstring :=   ooxml:binary-to-base64-string($img)
return ooxml:base64-string-to-binary($binstring)

=>
 
  

ooxml:binary-to-base64-string(
$node as binary()
)  as  xs:string
Summary:

This function returns the base64 encoded string for the provided binary.

Parameters:
$node : The binary

Example:
xquery version "1.0-ml";
import module namespace ooxml= "http://marklogic.com/openxml" 
          at "/MarkLogic/openxml/word-processing-ml-support.xqy";

let $img:= fn:doc("/ackbar.jpg")/node()
return ooxml:binary-to-base64-string($img)

=>
/9j/4AAQSkZJRgABAQAAAQABAAD/2wBDAAkGBwgHBgkIBwgKCgkLDRYPDQwMDRsUFRAWIB0iIiAdHx8kKDQsJCYxJx8fLT0tMTU3 ...
  

ooxml:create-paragraph(
$para as xs:string
)  as  element(w:p)
Summary:

This function creates a w:p element from the specified string.

Parameters:
$para : The text of the paragraph.

Example:
xquery version "1.0-ml";
import module namespace ooxml= "http://marklogic.com/openxml" 
          at "/MarkLogic/openxml/word-processing-ml-support.xqy";

ooxml:create-paragraph("Hello there everyone.")

=> 
<w:p xmlns:w="http://schemas.openxmlformats.org/wordprocessingml/2006/main">
   <w:r><w:t>Hello there everyone.</w:t></w:r>
</w:p>
  
  

ooxml:create-simple-docx(
$document as element(w:document)
)  as  binary()
Summary:

This function creates a .zip file that is a .docx package containing the minimum parts required to be a valid package.

Parameters:
$document : The document (w:document) for the .docx package.

Example:
xquery version "1.0-ml";
import module namespace ooxml= "http://marklogic.com/openxml" 
          at "/MarkLogic/openxml/word-processing-ml-support.xqy";

let $doc := ooxml:document(ooxml:body(ooxml:create-paragraph("Hello, World!")))
return xdmp:zip-manifest(ooxml:create-simple-docx($doc))
=> 
<parts xmlns="xdmp:zip">
  <part uncompressed-size="375" compressed-size="196" encrypted="false" last-modified="2009-11-24T14:16:14">[Content_Types].xml</part>
  <part uncompressed-size="244" compressed-size="139" encrypted="false" last-modified="2009-11-24T14:16:14">_rels/.rels</part>
  <part uncompressed-size="150" compressed-size="117" encrypted="false" last-modified="2009-11-24T14:16:14">word/document.xml</part>
</parts>
  

ooxml:custom-xml(
$content as element(),
$tag as xs:string
)  as  element(w:customXml)?
Summary:

This function tags $content with w:customXml and sets the @element value to $tag.

Parameters:
$content : The content element.
$tag : The name of the custom XML tag.

Usage Notes:

The $content parameter must either be an element of type paragraph (w:p) , run (w:r), field (w:fldSimple,w:fldChar), hyperlink (w:hyperlink), custom xml (w:customXml), structured document tag (w:sdt), table (w:tbl), cel (w:tc), or row (w:tr). If it is not one of these types, the function returns the empty sequence.

Example:
xquery version "1.0-ml";
import module namespace ooxml= "http://marklogic.com/openxml" 
		  at "MarkLogic/openxml/word-processing-ml-support.xqy";

let $para:= 
  <w:p xmlns:w="http://schemas.openxmlformats.org/wordprocessingml/2006/main">
       <w:r><w:t>This is my paragraph.</w:t></w:r>
  </w:p>
let $tag := "ABCD"
return ooxml:custom-xml($para,$tag)
=>
<w:customXml w:element="ABCD" 
  xmlns:w="http://schemas.openxmlformats.org/wordprocessingml/2006/main">
  <w:p><w:r><w:t>This is my paragraph.</w:t></w:r></w:p>
</w:customXml>

ooxml:custom-xml-entity-highlight(
$nodes as node()*,
)  as  node()*
Summary:

This function highlights terms in $nodes identified by cts:entity-highlight() by applying <w:customXml w:element={$cts:entity-type}> to the term.

Parameters:
$nodes : The paragraph(s) from which to search for the highlighted terms.

Usage Notes:

This function is a wrapper for cts:entity-highlight, and similar to ooxml:custom-xml-highlight, applies <w:customXml> to terms, adjusting runs (<w:r>) as required. The nodes passed in as a parameter to the function are intended to be paragraphs (<w:p>). You can of course, embed paragraphs within other elements.

Example:
xquery version "1.0-ml";
import module namespace ooxml= "http://marklogic.com/openxml" 
		  at "MarkLogic/openxml/word-processing-ml-support.xqy";
declare namespace w= "http://schemas.openxmlformats.org/wordprocessingml/2006/main";

let $wp := The MarkLogic government summit was in Washington DC this year.
return ooxml:custom-xml-entity-highlight($wp)
=>
<w:p>
  <w:r>
    <w:t xml:space="preserve">The MarkLogic government summit was in </w:t>
  </w:r>
  <w:customXml w:element="GPE">
    <w:r>
      <w:t>Washington DC</w:t>
    </w:r>
  </w:customXml>
  <w:r>
    <w:t xml:space="preserve"> this year.</w:t>
  </w:r>
</w:p>

ooxml:custom-xml-highlight(
$nodes as node()*,
$highlight-term as cts:query,
$tag-name as xs:string,
[$attributes as xs:string*],
[$values as xs:string*]
)  as  node()*
Summary:

This function highlights $hightlight-term in $nodes by applying <w:customXml w:element={$tag-name}> to the term. It searches for term within w:t elements within a w:r (runs), wrapping a customXml element around the element the element containing the highlighted match.

Parameters:
$nodes : The paragraph(s) from which to search for the highlighted terms.
$highlight-term : The cts:query used to find the highlight term.
$tag-name : The name used for the w:customXml w:element attribute value.
$attributes (optional): A list of attributes to be added to the w:customXml properties.
$values (optional): The values corresponding to the $attributes.

Usage Notes:

If you specify the $attributes and $values parameters, the length of the list for each parameter must be the same, otherwise an exception is thrown.

Example:
xquery version "1.0-ml";
import module namespace ooxml= "http://marklogic.com/openxml" 
		  at "MarkLogic/openxml/word-processing-ml-support.xqy";

declare namespace w=
  "http://schemas.openxmlformats.org/wordprocessingml/2006/main";

let $wp := <w:p><w:r><w:t>THIS IS A TEST!</w:t></w:r></w:p>
let $wordquery := cts:word-query("TEST")
return  ooxml:custom-xml-highlight($wp,$wordquery,"MYTAG")
=>
<w:p xmlns:w="http://schemas.openxmlformats.org/wordprocessingml/2006/main">
  <w:r>
    <w:t xml:space="preserve">THIS IS A </w:t>
  </w:r>
  <w:customXml w:element="MYTAG">
   <w:r>
     <w:t>TEST</w:t>
   </w:r>
  </w:customXml>
  <w:r>
    <w:t xml:space="preserve">!</w:t>
  </w:r>
</w:p>
  
Example:
xquery version "1.0-ml";
import module namespace ooxml= "http://marklogic.com/openxml" 
		  at "MarkLogic/openxml/word-processing-ml-support.xqy";

declare namespace w=
  "http://schemas.openxmlformats.org/wordprocessingml/2006/main";

let $wp := <w:p><w:r><w:t>THIS IS A TEST!</w:t></w:r></w:p>
let $wordquery := cts:word-query("TEST")
let $attributes := ("author","id")
let $values := ("oslo","1") 
return  ooxml:custom-xml-highlight($wp,$wordquery,"MYTAG", $attributes, $values)
=>
<w:p xmlns:w="http://schemas.openxmlformats.org/wordprocessingml/2006/main">
  <w:r>
    <w:t xml:space="preserve">THIS IS A </w:t>
  </w:r>
  <w:customXml w:element="MYTAG">
    <w:customXmlPr>
      <w:attr w:name="author" w:val="oslo"/>
      <w:attr w:name="id" w:val="1"/>
    </w:customXmlPr>
    <w:r>
      <w:t>TEST</w:t>
    </w:r>
  </w:customXml>
  <w:r>
    <w:t xml:space="preserve">!</w:t>
  </w:r>
</w:p>
  

ooxml:default-content-types(
)  as  element(types:Types)
Summary:

This function creates a default content types element for the .docx package ([Content_Types].xml).

Parameters:

Usage Notes:

Example:
xquery version "1.0-ml";
import module namespace ooxml= "http://marklogic.com/openxml" 
          at "/MarkLogic/openxml/word-processing-ml-support.xqy";

ooxml:default-content-types()
=> 
<Types xmlns="http://schemas.openxmlformats.org/package/2006/content-types">
  <Default Extension="rels" ContentType="application/vnd.openxmlformats-package.relationships+xml"/>
  <Default Extension="xml" ContentType="application/xml"/>
  <Override PartName="/word/document.xml" ContentType="application/vnd.openxmlformats-officedocument.wordprocessingml.document.main+xml"/>
  <Override PartName="/word/numbering.xml" ContentType="application/vnd.openxmlformats-officedocument.wordprocessingml.numbering+xml"/>
  <Override PartName="/word/styles.xml" ContentType="application/vnd.openxmlformats-officedocument.wordprocessingml.styles+xml"/>
  <Override PartName="/word/settings.xml" ContentType="application/vnd.openxmlformats-officedocument.wordprocessingml.settings+xml"/>
  <Override PartName="/word/theme/theme1.xml" ContentType="application/vnd.openxmlformats-officedocument.theme+xml"/>
  <Override PartName="/word/fontTable.xml" ContentType="application/vnd.openxmlformats-officedocument.wordprocessingml.fontTable+xml"/>
</Types>
  

ooxml:directory-uris(
$directory as xs:string,
[$depth as xs:string]
)  as  xs:string()*
Summary:

This function returns the URIs for files extracted from .docx package using Open XML Extract pipeline.

Parameters:
$directory : The name of the directory containing the extracted .docx parts.
$depth (optional): "1" for immediate children, "infinity" for all. If not supplied, depth is "1".

Usage Notes:


Example:
xquery version "1.0-ml";
import module namespace ooxml= "http://marklogic.com/openxml" 
		  at "MarkLogic/openxml/word-processing-ml-support.xqy";

ooxml:directory-uris("/sampleManuscript_docx_parts/")
=>
/sampleManuscript_docx_parts/[Content_Types].xml
/sampleManuscript_docx_parts/_rels/.rels
/sampleManuscript_docx_parts/customXml/_rels/item1.xml.rels
/sampleManuscript_docx_parts/customXml/item1.xml
/sampleManuscript_docx_parts/customXml/itemProps1.xml
/sampleManuscript_docx_parts/docProps/app.xml
/sampleManuscript_docx_parts/docProps/core.xml
/sampleManuscript_docx_parts/word/_rels/document.xml.rels
/sampleManuscript_docx_parts/word/document.xml
/sampleManuscript_docx_parts/word/fontTable.xml
/sampleManuscript_docx_parts/word/numbering.xml
/sampleManuscript_docx_parts/word/settings.xml
/sampleManuscript_docx_parts/word/styles.xml
/sampleManuscript_docx_parts/word/theme/theme1.xml
/sampleManuscript_docx_parts/word/webSettings.xml

ooxml:document(
$body as element(w:body)?
)  as  element(w:document)
Summary:

This function creates a document for the .docx package (word/document.xml).

Parameters:
$body : The body content for the document.

Usage Notes:


Example:
xquery version "1.0-ml";
import module namespace ooxml= "http://marklogic.com/openxml" at
                               "/MarkLogic/openxml/word-processing-ml-support.xqy";

let $para := ooxml:create-paragraph("Hello, World!")
return ooxml:document(ooxml:body($para))
=>
<w:document xmlns:w="http://schemas.openxmlformats.org/wordprocessingml/2006/main">
  <w:body>
    <w:p>
      <w:r>
        <w:t>Hello, World!</w:t>
      </w:r>
    </w:p>
  </w:body>
</w:document>

ooxml:document-rels(
)  as  element(pr:Relationships)
Summary:

This function creates a default document relationships element for a .docx package (word/_rels/document.xml.rels).

Parameters:

Usage Notes:


Example:
xquery version "1.0-ml";
import module namespace ooxml= "http://marklogic.com/openxml" at 
                               "/MarkLogic/openxml/word-processing-ml-support.xqy";

ooxml:document-rels()
=>
<Relationships>
  <Relationship Id="rId3" Type="http://schemas.openxmlformats.org/officeDocument/2006/relationships/settings" Target="settings.xml"/>
  <Relationship Id="rId2" Type="http://schemas.openxmlformats.org/officeDocument/2006/relationships/styles" Target="styles.xml"/>
  <Relationship Id="rId1" Type="http://schemas.openxmlformats.org/officeDocument/2006/relationships/numbering" Target="numbering.xml"/>
  <Relationship Id="rId6" Type="http://schemas.openxmlformats.org/officeDocument/2006/relationships/theme" Target="theme/theme1.xml"/>
  <Relationship Id="rId5" Type="http://schemas.openxmlformats.org/officeDocument/2006/relationships/fontTable" Target="fontTable.xml"/>
</Relationships>

ooxml:docx-manifest(
$directory as xs:string,
$uris as xs:string*
)  as  element(zip:parts)
Summary:

This function constructs a manifest for the given URIs in the directory.

Parameters:
$directory : The name of the directory.
$uris: The URIs within the directory to be listed in the manifest.

Usage Notes:


Example:
xquery version "1.0-ml";
import module namespace ooxml= "http://marklogic.com/openxml" at 
                               "/MarkLogic/openxml/word-processing-ml-support.xqy";

let $uris := ("/Default_docx_parts/word/document.xml",
              "/Default_docx_parts/[Content_Types].xml",
              "/Default_docx_parts/_rels/.rels")

return ooxml:docx-manifest("/Default_docx_parts/",$uris)
=>
<parts>
  <part>word/document.xml</part>
  <part>[Content_Types].xml</part>
  <part>_rels/.rels</part>
</parts>

ooxml:docx-package(
$content-types as element(types:Types),
$rels as element(pr:Relationships),
$document as element(w:document),
[$document-rels as element(pr:Relationships)],
[$numbering as element(w:numbering)],
[$styles as element(w:styles)],
[$settings as element(w:settings)],
[$theme as element(a:theme)],
[$font-table as element(w:fonts)]
)  as  binary()
Summary:

This function creates a .zip file that is the .docx package containing the parts passed in as parameters. It
is assumed the parts are properly mapped to one another.
Just using the constructors provided its possible to generate a .docx dynamically.

Some things to remember: This function either generates:
1) a simplified .docx with just [Content_Types].xml, .rels, and document.xml. or
2) a default .docx package that consists of those 3 parts plus any provided additional optional parts.

The provided ooxml:simple-content-types() returns the [Content_Types].xml for a minimum .docx package.
ooxml:default-content-types() returns the [Content-Types].xml for a .docx package with all optional parts included.
These are intended to jumpstart your knowledge of parts required for a .docx package. Depending on your requirement, you may need
to update your [Content_Types].xml accordingly. Also, default constructors have been provided for all optional parts.

Finally, it is possilbe for a .docx to have more/less parts depending on the information in the document. This
function is intended to help get you started with dynamic document generation for a default .docx pacakge.

Parameters:
$content-types : The [Content_Types].xml part for the .docx package.
$rels : The pacakge relationships part.
$document : The document.xml part for the .docx package.
$document-rels (optional): The document.xml relationships part.
$numbering (optional): The numbering.xml part for the .docx package. (used for numbered/bulleted lists)
$styles (optional): The styles.xml part for the .docx package.
$settings (optional): The settings.xml part for the .docx package.
$theme (optional): The theme#.xml part for the .docx package.
$font-table (optional): The fontTable.xml part for the .docx package.

Usage Notes:


Example:
xquery version "1.0-ml";
import module namespace ooxml= "http://marklogic.com/openxml" at
                               "/MarkLogic/openxml/word-processing-ml-support.xqy";

let $content-types:= ooxml:simple-content-types()
let $rels := ooxml:package-rels()
let $para := ooxml:create-paragraph("Hello, World!")
let $doc := ooxml:document(ooxml:body($para))
return xdmp:zip-manifest(ooxml:docx-package($content-types, $rels, $doc))
=>
<parts xmlns="xdmp:zip">
  <part uncompressed-size="375" compressed-size="196" encrypted="false" last-modified="2009-11-25T12:01:28">[Content_Types].xml</part>
  <part uncompressed-size="244" compressed-size="139" encrypted="false" last-modified="2009-11-25T12:01:28">_rels/.rels</part>
  <part uncompressed-size="160" compressed-size="124" encrypted="false" last-modified="2009-11-25T12:01:28">word/document.xml</part>
</parts>

ooxml:font-table(
) as element(w:fonts)
Summary:

This function creates a default w:fonts element for a .docx package (word/fontTable.xml).

Parameters:

Usage Notes:

Example:
xquery version "1.0-ml";
import module namespace ooxml= "http://marklogic.com/openxml" at 
                               "/MarkLogic/openxml/word-processing-ml-support.xqy";

ooxml:font-table()
=>
(Note:following truncated for brevity)
<w:fonts xmlns:r="http://schemas.openxmlformats.org/officeDocument/2006/relationships" xmlns:w="http://schemas.openxmlformats.org/wordprocessingml/2006/main"> <w:font w:name="Symbol"> <w:panose1 w:val="05050102010706020507"/> <w:charset w:val="02"/> <w:family w:val="roman"/> <w:pitch w:val="variable"/> <w:sig w:usb0="00000000" w:usb1="10000000" w:usb2="00000000" w:usb3="00000000" w:csb0="80000000" w:csb1="00000000"/> </w:font> <w:font w:name="Times New Roman"> ... </w:font> ... </w:fonts>

ooxml:get-custom-xml-ancestor(
$doc as element()
)  as  element()?
Summary:

This function returns the greatest ancestor of the specified node that is either an immediate parent of type w:customXml or w:sdt, a parent of that parent, and so on until the parent is not a w:customXml or w:sdt element. If no such ancestor is found, then the empty sequence is returned.

Parameters:
$doc : An element to search.

Example:
xquery version "1.0-ml";
import module namespace ooxml= "http://marklogic.com/openxml" 
		  at "MarkLogic/openxml/word-processing-ml-support.xqy";
declare namespace w=
  "http://schemas.openxmlformats.org/wordprocessingml/2006/main";

let $para:= 
 <w:p>
   <w:r><w:t>THIS IS A TEST!</w:t></w:r>
 </w:p>
let $custom := 
  <w:customXml w:element="foo">
    <w:customXml w:element="bar">{$para}</w:customXml>
  </w:customXml>
let $wp1 := $custom//w:p
return  ooxml:get-custom-xml-ancestor($wp1)
=>
<w:customXml w:element="foo" 
  xmlns:w="http://schemas.openxmlformats.org/wordprocessingml/2006/main">
 <w:customXml w:element="bar">
	<w:p><w:r><w:t>THIS IS A TEST!</w:t></w:r></w:p>
 </w:customXml>
</w:customXml>
  

ooxml:get-directory-package(
$directory as xs:string
) as element(pkg:package)
Summary:

This function returns a document in the OPC (Open Packaging Convention) format XML.

Parameters:
$directory: The directory containing the extracted parts for a .docx package

Usage Notes:


Example:
xquery version "1.0-ml";
import module namespace ooxml= "http://marklogic.com/openxml" at
                               "/MarkLogic/openxml/word-processing-ml-support.xqy";

ooxml:get-directory-package("/sampleManuscript_docx_parts/")
=>
<pkg:package xmlns:pkg="http://schemas.microsoft.com/office/2006/xmlPackage">
  <pkg:part pkg:name="/_rels/.rels" pkg:contentType="application/vnd.openxmlformats-package.relationships+xml" pkg:padding="512">
    <pkg:xmlData>
      <Relationships xmlns="http://schemas.openxmlformats.org/package/2006/relationships">
        ...
      </Relationships>
    </pkg:xmlData>
  </pkg:part>
  <pkg:part pkg:name="/word/document.xml" pkg:contentType="application/vnd.openxmlformats-officedocument.wordprocessingml.document.main+xml">
    <pkg:xmlData>
      <w:document>
        <w:body>
           <w:p> ... </w:p>
        </w:body>
      </w:document>
    </pkg:xmlData>
  </pkg:part>
    ...
<pkg:package>
Note: example above truncated for brevity. All pieces of .docx package are present and serialized
within <pkg:package>, captured as <pkg:part> elements.

Images in this format are captured as base64 encoded strings, following the Open XML format. This
file may be opened as a .XML file within Word. Saving as XML in Word will generate this format
for a .docx package as well.

ooxml:get-mimetype(
$filename as xs:string
) as xs:string?
Summary:

This function returns the mimetype for the given URI.

Parameters:
$uri : URI reference

Usage Notes:


Example:
xquery version "1.0-ml";
import module namespace ooxml= "http://marklogic.com/openxml" at
                               "/MarkLogic/openxml/word-processing-ml-support.xqy";

ooxml:get-mimetype("/sampleManuscript.docx")
=>
application/vnd.openxmlformats-officedocument.wordprocessingml.document

ooxml:get-paragraph-style-id(
$pstyle as element(w:pPr)
)  as  xs:string?
Summary:

This function returns the @val attribute for a w:pStyle element (child of w:pPr) from $pstyle. Returns the empty sequence if no IDs are found.

Parameters:
$pstyle : The w:pPr element.

Example:
xquery version "1.0-ml";
import module namespace ooxml= "http://marklogic.com/openxml" 
		  at "MarkLogic/openxml/word-processing-ml-support.xqy";

declare namespace w=
  "http://schemas.openxmlformats.org/wordprocessingml/2006/main";

let $pstyle:= 
       <w:pPr>
             <w:pStyle w:val="TestParagraphStyle" />
             <w:ind w:left="1440" />
        </w:pPr>
return ooxml:get-paragraph-style-id($pstyle)

=> TestParagraphStyle

ooxml:get-paragraph-styles(
$paragraph as element(w:p)*
)  as  element(w:pPr)*
Summary:

This function returns the paragraph properties. Returns the empty sequence if no styles are found.

Parameters:
$paragraph : The w:p element(s).

Example:
xquery version "1.0-ml";
import module namespace ooxml= "http://marklogic.com/openxml" 
		  at "MarkLogic/openxml/word-processing-ml-support.xqy";

let $wp := 
<w:p  xmlns:w="http://schemas.openxmlformats.org/wordprocessingml/2006/main">
  <w:pPr><w:u/></w:pPr>
  <w:r><w:t>This is a test.</w:t></w:r>
</w:p>
return ooxml:get-paragraph-styles($wp)
=>
<w:pPr xmlns:w="http://schemas.openxmlformats.org/wordprocessingml/2006/main">
	<w:u/>
</w:pPr>
  

ooxml:get-run-style-id(
$rstyle as element(w:rPr)
)  as  xs:string?
Summary:

This function returns the values for the attribute @val for a w:rStyle element (which is a child of a w:rPr element). Returns the empty sequence if no IDs are found.

Parameters:
$rstyle : The w:rPr element containing the w:rStyle element.

Example:
xquery version "1.0-ml";
import module namespace ooxml= "http://marklogic.com/openxml" 
		  at "MarkLogic/openxml/word-processing-ml-support.xqy";

let $rstyle := 
<w:rPr xmlns:w="http://schemas.openxmlformats.org/wordprocessingml/2006/main">
        <w:rStyle w:val="oslo"/><w:u/>
</w:rPr>
return ooxml:get-run-style-id($rstyle)
=>
oslo

ooxml:get-run-styles(
$paragraph as element(w:p)*
)  as  element(w:rPr)*
Summary:

This function returns paragraph run styles. Returns the empty sequence if no styles are found.

Parameters:
$paragraph : The w:p element(s).

Example:
xquery version "1.0-ml";
import module namespace ooxml= "http://marklogic.com/openxml" 
		  at "MarkLogic/openxml/word-processing-ml-support.xqy";


let $wp := 
<w:p  xmlns:w="http://schemas.openxmlformats.org/wordprocessingml/2006/main">
  <w:pPr><w:u/></w:pPr>
  <w:r>
      <w:rPr><w:b/></w:rPr>
      <w:t>This is a test.</w:t>
   </w:r>
  <w:r>
      <w:rPr><w:i/></w:rPr>
      <w:t>This is another.</w:t>
   </w:r>
</w:p>
return ooxml:get-run-styles($wp)
=>
<w:rPr xmlns:w="http://schemas.openxmlformats.org/wordprocessingml/2006/main">
	<w:b/>
</w:rPr>
<w:rPr xmlns:w="http://schemas.openxmlformats.org/wordprocessingml/2006/main">
	<w:i/>
</w:rPr>


ooxml:get-style-definition(
$styleid as xs:string,
$styles as element(w:styles)
)  as  element(w:style)?
Summary:

This function returns the style definition from styles.xml for the given style ID.

Parameters:
$styleid : The style ID.
$styles : The root element from the styles.xml file in the .docx package.

Example:
xquery version "1.0-ml";
import module namespace ooxml= "http://marklogic.com/openxml" 
		  at "MarkLogic/openxml/word-processing-ml-support.xqy";
declare namespace w=
  "http://schemas.openxmlformats.org/wordprocessingml/2006/main";

let $styleids := "oslo"
let $styles := doc("/Test_docx_parts/word/styles.xml") 
return ooxml:get-style-definitions($styleids, $styles)/w:style
=>
<w:style xmlns:w="http://schemas.openxmlformats.org/wordprocessingml/2006/main"
       	w:type="character" w:customStyle="1" w:styleId="oslo">
     <w:name w:val="oslo"/><w:basedOn w:val="Emphasis"/>
     <w:uiPriority w:val="1"/><w:qFormat/><w:rsid w:val="005B2E7B"/>
       <w:rPr><w:rFonts w:ascii="Bodoni MT Black" w:hAnsi="Bodoni MT Black"/>
       <w:b/><w:sz w:val="32"/></w:rPr>
</w:style>


ooxml:list-paragraph-property(
$num-id as xs:string
) as element(w:pPr)
Summary:

This function returns a paragraph properties element (w:pPr) for a ListParagraph style identified by id.

Parameters:
$num-id : The number id for the ListParagraph style. 1 for bulleted list, 2 for numbering, etc.

Usage Notes:

Bulleted and numbered lists in a Word document, manifest themselves as a sequence of paragraphs (w:p) in the XML.
To create a numbered list of points from 1-3, you would create 3 paragraphs, and would assign each the returned value from
list-paragraph-property("2") by setting the paragraph properties accordingly.

Even thought each paragraph has a similar style and may look indistinguishable from its sibling paragraphs in the XML, the Office application
will manifest each paragraph as starting with 1. , 2. , 3. in the Word document.

Example:
xquery version "1.0-ml";
import module namespace ooxml= "http://marklogic.com/openxml" at
                               "/MarkLogic/openxml/word-processing-ml-support.xqy";

ooxml:list-paragraph-property("1")
=>
<w:pPr>
  <w:pStyle w:val="ListParagraph"/>
  <w:numPr>
    <w:ilvl w:val="0"/>
    <w:numId w:val="1"/>
  </w:numPr>
</w:pPr>

ooxml:numbering(
) as element(w:numbering)
Summary:

This function creates a default w:numbering element for a .docx package (word/numbering.xml).

Parameters:

Usage Notes:

Example:
xquery version "1.0-ml";
import module namespace ooxml= "http://marklogic.com/openxml" at 
                               "/MarkLogic/openxml/word-processing-ml-support.xqy";

ooxml:numbering()
=>
(Note:following truncated for brevity)
<w:numbering xmlns:ve="http://schemas.openxmlformats.org/markup-compatibility/2006" xmlns:o="urn:schemas-microsoft-com:office:office" xmlns:r="http://schemas.openxmlformats.org/officeDocument/2006/relationships" xmlns:m="http://schemas.openxmlformats.org/officeDocument/2006/math" xmlns:v="urn:schemas-microsoft-com:vml" xmlns:wp="http://schemas.openxmlformats.org/drawingml/2006/wordprocessingDrawing" xmlns:w10="urn:schemas-microsoft-com:office:word" xmlns:w="http://schemas.openxmlformats.org/wordprocessingml/2006/main" xmlns:wne="http://schemas.microsoft.com/office/word/2006/wordml"> <w:abstractNum w:abstractNumId="0"> ... </w:abstractNum> <w:abstractNum w:abstractNumId="1"> ... </w:abstractNum> <w:num w:numId="1"> <w:abstractNumId w:val="1"/> </w:num> <w:num w:numId="2"> <w:abstractNumId w:val="0"/> </w:num> </w:numbering>

ooxml:package(
$parts as node()*
) as element(pkg:package)
Summary:

This function returns a document in the OPC (Open Packaging Convention) format XML.

Parameters:
$parts: The xml parts that together compose a .docx package

Usage Notes:


Example:
xquery version "1.0-ml";
import module namespace ooxml= "http://marklogic.com/openxml" at
                               "/MarkLogic/openxml/word-processing-ml-support.xqy";

let $directory := "/sampleManuscript_docx_parts/"
let $uris := ooxml:directory-uris($directory)
let $validuris := ooxml:package-files-only($uris)
let $parts := fn:doc(($uris))/node()
return ooxml:package($parts)
=>
<pkg:package xmlns:pkg="http://schemas.microsoft.com/office/2006/xmlPackage">
  <pkg:part pkg:name="/_rels/.rels" pkg:contentType="application/vnd.openxmlformats-package.relationships+xml" pkg:padding="512">
    <pkg:xmlData>
      <Relationships xmlns="http://schemas.openxmlformats.org/package/2006/relationships">
        ...
      </Relationships>
    </pkg:xmlData>
  </pkg:part>
  <pkg:part pkg:name="/word/document.xml" pkg:contentType="application/vnd.openxmlformats-officedocument.wordprocessingml.document.main+xml">
    <pkg:xmlData>
      <w:document>
        <w:body>
           <w:p> ... </w:p>
        </w:body>
      </w:document>
    </pkg:xmlData>
  </pkg:part>
    ...
<pkg:package>
Note: example above truncated for brevity. All pieces of .docx package are present and serialized
within <pkg:package>, captured as <pkg:part> elements.

Images in this format are captured as base64 encoded strings, following the Open XML format. This
file may be opened as a .XML file within Word. Saving as XML in Word will generate this format
for a .docx package as well.

ooxml:package-files-only(
$uris as xs:string*
) as xs:string*
Summary:

This function returns only files for an extracted .docx.

Parameters:
$uris : The uris for an extracted .docx package.

Usage Notes:


Example:
xquery version "1.0-ml";
import module namespace ooxml= "http://marklogic.com/openxml" at 
                               "/MarkLogic/openxml/word-processing-ml-support.xqy";

let $uris := ("/Default_docx_parts/word/document.xml",
              "/Default_docx_parts/[Content_Types].xml",
              "/Default_docx_parts/_rels/.rels",
              "/Default_docx_parts/myCustomParts/")

return ooxml:package-files-only($uris)
=>
/Default_docx_parts/word/document.xml
/Default_docx_parts/[Content_Types].xml
/Default_docx_parts/_rels/.rels

ooxml:package-rels(
) as element(pr:Relationships)
Summary:

This function creates a default package relationships element for the .docx package (_rels/.rels).

Parameters:

Usage Notes:

Example:
xquery version "1.0-ml";
import module namespace ooxml= "http://marklogic.com/openxml" at
                               "/MarkLogic/openxml/word-processing-ml-support.xqy";

ooxml:package-rels()
=>
<Relationships xmlns="http://schemas.openxmlformats.org/package/2006/relationships">
  <Relationship Id="rId1" Type="http://schemas.openxmlformats.org/officeDocument/2006/relationships/officeDocument" Target="/word/document.xml"/>
</Relationships>

ooxml:paragraph(
$runs as element(w:r),
[$pProps as element(w:pPr)?]
) as element(w:p)
Summary:

This function creates a document paragraph (w:p) element.

Parameters:
$runs : The runs of text to be included in the paragraph.
$pProps (optional): The properties to be applied to the paragraph.

Usage Notes:

The styles referenced in $pProps are assumed to have their definitions defined within the .docx package.

Styles can be defined inline, as well as defined in other .docx package parts
such as styles.xml and numbering.xml.

Example:
xquery version "1.0-ml";
import module namespace ooxml= "http://marklogic.com/openxml" at
                               "/MarkLogic/openxml/word-processing-ml-support.xqy";

ooxml:paragraph(ooxml:run(ooxml:text("Hello, World!")))
=>
<w:p xmlns:w="http://schemas.openxmlformats.org/wordprocessingml/2006/main">
  <w:r>
    <w:t xml:space="preserve">Hello, World!</w:t>
  </w:r>
</w:p>
Example:
xquery version "1.0-ml";
import module namespace ooxml= "http://marklogic.com/openxml" at
			       "/MarkLogic/openxml/word-processing-ml-support.xqy";

let $styles := ooxml:list-paragraph-property("1")
return ooxml:paragraph((ooxml:run(ooxml:text("Hello, World!"))),$styles)
=>
<w:p xmlns:w="http://schemas.openxmlformats.org/wordprocessingml/2006/main">
  <w:pPr>
    <w:pStyle w:val="ListParagraph"/>
    <w:numPr>
      <w:ilvl w:val="0"/>
      <w:numId w:val="1"/>
    </w:numPr>
  </w:pPr>
  <w:r>
    <w:t xml:space="preserve">Hello, World!</w:t>
  </w:r>
</w:p>

ooxml:remove-paragraph-styles(
$paragraph as element()
)  as  element()
Summary:

This function removes all properties from w:p paragraphs. Paragraph properties are w:pPr elements and run properties are w:rPr elements.

Parameters:
$paragraph : Any block-level element.

Usage Notes:

This function is useful when you want to insert a paragraph with the Office defaults, or when you want to switch the existing properties for a paragraph.

Example:
xquery version "1.0-ml";
import module namespace ooxml= "http://marklogic.com/openxml" 
		  at "MarkLogic/openxml/word-processing-ml-support.xqy";

let $paragraph:=
<w:p xmlns:w="http://schemas.openxmlformats.org/wordprocessingml/2006/main">
  <w:pPr><w:b/></w:pPr>
     <w:r><w:rPr><w:u/></w:rPr>
             <w:t>This is a test.</w:t>
      </w:r></w:p>
return ooxml:remove-paragraph-styles($paragraph)
=>
<w:p xmlns:w="http://schemas.openxmlformats.org/wordprocessingml/2006/main">
	<w:r><w:t>This is a test.</w:t></w:r>
</w:p>


ooxml:replace-custom-xml-element(
$content as element(),
$oldtag as xs:string,
$newtag as xs:string
)  as  element()
Summary:

This function replaces any @element values for w:customXml with $newtag, where w:customXml[@w:element = $oldtag].

Parameters:
$content : The OOXML content.
$oldtag : The old tag for the element name.
$newtag : The new tag for the element name.

Example:
xquery version "1.0-ml";
import module namespace ooxml= "http://marklogic.com/openxml" 
		  at "MarkLogic/openxml/word-processing-ml-support.xqy";

declare namespace w=
  "http://schemas.openxmlformats.org/wordprocessingml/2006/main";

let $block:=
<w:customXml w:element="ABCD">
    <w:p>
<w:r><w:t>This is my paragraph.</w:t></w:r>
         </w:p>
</w:customXml>
let $origtag := "ABCD"
let $newtag := "EFGH"
return ooxml:replace-custom-xml-element($block,$origtag,$newtag)
=>
<w:customXml w:element="EFGH" 
  xmlns:w="http://schemas.openxmlformats.org/wordprocessingml/2006/main">
  <w:p><w:r><w:t>This is my paragraph.</w:t></w:r></w:p>
</w:customXml>

ooxml:replace-package-document(
$pkg-xml as element(pkg:package),
$document-xml as element(w:document)
)  as  element(pkg:package)
Summary:

This function replaces the document.xml in the specifed OPC document with parameter $document-xml.

Parameters:
$pkg-xml: The .docx package in Flat OPC format. It is the .docx serialized as a single &tl;pkg:package>.
$document-xml: The document.xml (<w:document>) for a .docx package.

Usage Notes:

This function is intended to help facilitate managment of .docx documents and subdocuments in the Open XML Flat OPC format.

Think of the OPC format as a container. It contains all the parts for a valid .docx package.
You can open a file serialized in the OPC format as a Word document within Word. Also, if you
were to save a Word document as .xml instead of .docx you can see it is serialized in the OPC format.

While you can open and save a document in OPC format as a complete document, you can also insert this XML into
an active Word document using the Toolkit javascript API (MLA.insertXML()). When you use this function, the entire
document inserts at the current cursor location, but the document body children elements insert and become additional
paragraphs, tables, bulleted lists, etc. within the document being authored. The document inserted does NOT replace
the document being authored. Used in this way, the OPC format provides a container for managing the document parts
you'd like to insert into an active Word document.

Because the OPC document contains the styles and associated parts required by the document.xml, when inserted into another
document, required styles and references are appended to the appropriate XML parts in the .docx being authored.

To investigate more, the javascript Toolkit API also provides functions for extracting the WordOpenXML property (MLA.getContentControlWordOpenXML())
for Content Controls. The XML returned by this function returns the contents of the Control as if it were the only
content in its own .docx package.


Example:
xquery version "1.0-ml";
import module namespace ooxml= "http://marklogic.com/openxml" at
                               "/MarkLogic/openxml/word-processing-ml-support.xqy";

let $directory:="/sampleManuscript_docx_parts/" 
let $uris := ooxml:directory-uris($directory)
let $pkg := ooxml:package($directory, $uris)

let $text := ooxml:text("Hello, ")
let $text2 := ooxml:text("World!")
let $run := ooxml:run(($text,$text2))
let $para := ooxml:paragraph($run)
let $body := ooxml:body($para)
let $document := ooxml:document($body)

return ooxml:replace-package-document($pkg, $document)
=>
<pkg:package xmlns:pkg="http://schemas.microsoft.com/office/2006/xmlPackage">
    ...
  <pkg:part pkg:name="/word/document.xml" pkg:contentType="application/vnd.openxmlformats-officedocument.wordprocessingml.document.main+xml">
    <pkg:xmlData>
      <w:document>
        <w:body>
          <w:p>
            <w:r>
              <w:t xml:space="preserve">Hello, </w:t>
              <w:t xml:space="preserve">World!</w:t>
            </w:r>
          </w:p>
        </w:body>
      </w:document>
    </pkg:xmlData>
  </pkg:part>
    ...
</pkg:package>
Note: example above truncated for brevity. All pieces of .docx package are present and serialized
within <pkg:package>, captured as <pkg:part> elements.

Images in this format are captured as base64 encoded strings, following the Open XML format. This
file may be opened as a .XML file within Word. Saving as XML in Word will generate this format
for a .docx package as well.

ooxml:replace-paragraph-styles(
$block as element(),
$wpProps as element(w:pPr)?
)  as  element()
Summary:

This function sets paragraph properties for paragraphs (w:p) within a block. If the empty sequence is passed for $wpProps, then the paragraph properties for the $block are removed.

Parameters:
$block : The block containing the paragraph to be updated.
$wpProps : The paragraph properties, as a w:pPr element, to be applied within the paragraph block.

Usage Notes:

If $block already has styles applied, these styles are replaced by the new style parameters. If the empty sequence is passed for $wpProps, the paragraph properties for the $block are removed. If there are no properties currently defined for the paragraph, the $wpProps are applied.

Note that this function does not validate that the w:pPr element passed in is valid, so make sure the element you pass in is valid WordProcessingML markup. If you pass in an invalid element, it could result in a document that cannot be opened in Microsoft Word.


Example:
xquery version "1.0-ml";
import module namespace ooxml= "http://marklogic.com/openxml" 
		  at "MarkLogic/openxml/word-processing-ml-support.xqy";
declare namespace w=
  "http://schemas.openxmlformats.org/wordprocessingml/2006/main";

let $wp1 := 
<w:p>
     <w:r><w:t>THIS IS A TEST!</w:t></w:r>
</w:p>
let $pPr := <w:pPr><w:b/></w:pPr>
return  ooxml:replace-paragraph-styles($wp1,$pPr)
=>
<w:p xmlns:w="http://schemas.openxmlformats.org/wordprocessingml/2006/main">
	<w:pPr>
		<w:b/>
        </w:pPr>
	<w:t>THIS IS A TEST!</w:t>
</w:p>


ooxml:replace-run-styles(
$block as element(),
$wrProps as element(w:rPr)?
)  as  element()
Summary:

This function sets run properties for runs (w:r) within a block. If the empty sequence is passed for $wrProps, then the paragraph properties for the $block are removed.

Parameters:
$block : The block containing the run to be updated.
$wrProps : The run properties, as a w:rPr element, to be applied within the run block.

Usage Notes:

Note that this function does not validate that the w:rPr element passed in is valid, so make sure the element you pass in is valid WordProcessingML markup. If you pass in an invalid element, it could result in a document that cannot be opened in Microsoft Word.

Example:
xquery version "1.0-ml";
import module namespace ooxml= "http://marklogic.com/openxml" 
		  at "MarkLogic/openxml/word-processing-ml-support.xqy";
declare namespace w=
  "http://schemas.openxmlformats.org/wordprocessingml/2006/main";

let $wp1 := 
<w:p>
     <w:r><w:t>THIS IS A TEST!</w:t></w:r>
</w:p>
let $rPr := <w:rPr><w:b/></w:rPr>
return  ooxml:replace-run-styles($wp1,$rPr)
=>
<w:p xmlns:w="http://schemas.openxmlformats.org/wordprocessingml/2006/main">
  <w:r>
    <w:rPr>
      <w:b/>
    </w:rPr>
    <w:t>THIS IS A TEST!</w:t>
  </w:r>
</w:p>	


ooxml:replace-style-definition(
$newstyle as element(w:style),
$styles as element(w:styles)
)  as  element(w:styles)
Summary:

This function replaces w:style elements (style definitions) in w:styles (the styles.xml file from a .docx package).

Parameters:
$newstyle : The new style element.
$styles : The old styles element (from styles.xml).

Usage Notes:

If the id for the style $newstyle matches a style definition already present in $styles, the $newstyle will replace the existing style.

If the id for the style $newstyle does not exist in $styles, the $newstyle definition will be appended to the other definitions in $styles.

Note that it is possible within Microsoft Word to create styles with names that differ only in their case that have different style attributes. For example, you can create two styles: "mystyle" and "MYSTYLE", which have completely different style definitions.


Example:
xquery version "1.0-ml";
import module namespace ooxml= "http://marklogic.com/openxml" 
		  at "MarkLogic/openxml/word-processing-ml-support.xqy";

let $oldstyle := 
 <w:styles 
  xmlns:w="http://schemas.openxmlformats.org/wordprocessingml/2006/main">
  <w:style w:type="character" w:customStyle="1" w:styleId="oslo">
     <w:name w:val="oslo"/><w:basedOn w:val="Emphasis"/>
     <w:uiPriority w:val="1"/><w:qFormat/><w:rsid w:val="005B2E7B"/>
       <w:rPr><w:rFonts w:ascii="Bodoni MT Black" w:hAnsi="Bodoni MT Black"/>
       <w:b/><w:sz w:val="32"/></w:rPr>
   </w:style>
 </w:styles>
let $newstyle :=
  <w:style 
   xmlns:w="http://schemas.openxmlformats.org/wordprocessingml/2006/main"
   w:type="character" w:customStyle="1" w:styleId="oslo">
     <w:name w:val="oslo"/><w:basedOn w:val="Emphasis"/>
     <w:uiPriority w:val="1"/><w:qFormat/><w:rsid w:val="005B2E7B"/>
       <w:rPr><w:rFonts w:ascii="Courier New" w:hAnsi="Courier New"/>
       <w:b/><w:sz w:val="32"/></w:rPr>
   </w:style>
return
ooxml:replace-style-definition($newstyle, $oldstyle)
=>
<w:styles 
  xmlns:w="http://schemas.openxmlformats.org/wordprocessingml/2006/main">
  <w:style w:type="character" w:customStyle="1" w:styleId="oslo">
    <w:name w:val="oslo"/><w:basedOn w:val="Emphasis"/>
    <w:uiPriority w:val="1"/><w:qFormat/><w:rsid w:val="005B2E7B"/>
    <w:rPr><w:rFonts w:ascii="Courier New" w:hAnsi="Courier New"/>
      <w:b/>
      <w:sz w:val="32"/>
    </w:rPr>
  </w:style>
</w:styles>

ooxml:run(
$text as element(w:t)*,
[$rProps as element(w:rPr)?]
) as element(w:r)
Summary:

This function creates a run (w:r) element.

Parameters:
$text : The text elements to be included in the run.
$rProps (optional): The properties to be applied to the run.

Usage Notes:

The styles referenced in $rProps are assumed to have their definitions defined within the .docx package.

Styles can be defined inline, as well as defined in other .docx package parts
such as styles.xml and numbering.xml.

Example:
xquery version "1.0-ml";
import module namespace ooxml= "http://marklogic.com/openxml" at 
                               "/MarkLogic/openxml/word-processing-ml-support.xqy";

ooxml:run(ooxml:text("Hello, World!"))
=>
<w:r xmlns:w="http://schemas.openxmlformats.org/wordprocessingml/2006/main">
  <w:t xml:space="preserve">Hello, World!</w:t>
</w:r>
Example:
xquery version "1.0-ml";
import module namespace ooxml= "http://marklogic.com/openxml" at
                               "/MarkLogic/openxml/word-processing-ml-support.xqy";

declare namespace w= "http://schemas.openxmlformats.org/wordprocessingml/2006/main";

let $bold := <w:rPr><w:b/></w:rPr>
return ooxml:run((ooxml:text("Hello, World!")),$bold)
=>
<w:r xmlns:w="http://schemas.openxmlformats.org/wordprocessingml/2006/main">
  <w:rPr>
    <w:b/>
  </w:rPr>
  <w:t xml:space="preserve">Hello, World!</w:t>
</w:r>

ooxml:settings(
) as element(w:settings)
Summary:

This function creates a default w:settings element for a .docx package (word/settings.xml).

Parameters:

Usage Notes:

Example:
xquery version "1.0-ml";
import module namespace ooxml= "http://marklogic.com/openxml" at 
                               "/MarkLogic/openxml/word-processing-ml-support.xqy";

ooxml:settings()
=>
<w:settings xmlns:o="urn:schemas-microsoft-com:office:office"
	    xmlns:r="http://schemas.openxmlformats.org/officeDocument/2006/relationships" 
            xmlns:m="http://schemas.openxmlformats.org/officeDocument/2006/math" 
            xmlns:v="urn:schemas-microsoft-com:vml" 
            xmlns:w10="urn:schemas-microsoft-com:office:word" 
            xmlns:w="http://schemas.openxmlformats.org/wordprocessingml/2006/main" 
            xmlns:sl="http://schemas.openxmlformats.org/schemaLibrary/2006/main"/>
<w:zoom w:percent="100"/>
<w:proofState w:spelling="clean" w:grammar="clean"/>
<w:defaultTabStop w:val="720"/>
<w:characterSpacingControl w:val="doNotCompress"/>
  <w:compat>
    <w:useFELayout/>
  </w:compat>
  <w:rsids>
    <w:rsidRoot w:val="003D2A77"/>
    <w:rsid w:val="002A2DDE"/>
    <w:rsid w:val="00397362"/>
    <w:rsid w:val="003D2A77"/>
  </w:rsids>
  <m:mathPr>
    <m:mathFont m:val="Cambria Math"/>
    <m:brkBin m:val="before"/>
    <m:brkBinSub m:val="--"/>
    <m:smallFrac m:val="off"/>
    <m:dispDef/>
    <m:lMargin m:val="0"/>
    <m:rMargin m:val="0"/>
    <m:defJc m:val="centerGroup"/>
    <m:wrapIndent m:val="1440"/>
    <m:intLim m:val="subSup"/>
    <m:naryLim m:val="undOvr"/>
  </m:mathPr>
  <w:themeFontLang w:val="en-US"/>
  <w:clrSchemeMapping w:bg1="light1" w:t1="dark1" w:bg2="light2" w:t2="dark2" w:accent1="accent1" w:accent2="accent2" w:accent3="accent3" w:accent4="accent4" w:accent5="accent5" w:accent6="accent6" w:hyperlink="hyperlink" w:followedHyperlink="followedHyperlink"/>
  <w:shapeDefaults>
  <o:shapedefaults v:ext="edit" spidmax="3074"/>
    <o:shapelayout v:ext="edit">
      <o:idmap v:ext="edit" data="1"/>
    </o:shapelayout>
  </w:shapeDefaults>
  <w:decimalSymbol w:val="."/>
  <w:listSeparator w:val=","/>
</w:settings>

ooxml:simple-content-types(
)  as  element(types:Types)
Summary:

This function creates a content types element for a .docx package of minimal parts ([Content_Types].xml).

Parameters:

Usage Notes:

The minimum .docx package includes: [Content_Types].xml, _rels/.rels, word/document.xml

Example:
xquery version "1.0-ml";
import module namespace ooxml= "http://marklogic.com/openxml" 
          at "/MarkLogic/openxml/word-processing-ml-support.xqy";

ooxml:simple-content-types()
=> 
<Types xmlns="http://schemas.openxmlformats.org/package/2006/content-types">
  <Default Extension="rels" ContentType="application/vnd.openxmlformats-package.relationships+xml"/>
  <Default Extension="xml" ContentType="application/xml"/>
  <Override PartName="/word/document.xml" ContentType="application/vnd.openxmlformats-officedocument.wordprocessingml.document.main+xml"/>
</Types>
  

ooxml:styles(
) as element(w:styles)
Summary:

This function creates a default w:styles element for a .docx package (word/styles.xml).

Parameters:

Usage Notes:

Example:
xquery version "1.0-ml";
import module namespace ooxml= "http://marklogic.com/openxml" at 
                               "/MarkLogic/openxml/word-processing-ml-support.xqy";

ooxml:styles()
=>
(Note:following truncated for brevity)
<w:styles> <w:docDefaults> ... </w:docDefaults> <w:latentStyles w:defLockedState="0" w:defUIPriority="99" w:defSemiHidden="1" w:defUnhideWhenUsed="1" w:defQFormat="0" w:count="267"> ... </w:latentStyles> <w:style w:type="paragraph" w:default="1" w:styleId="Normal"> ... </w:style> <w:style w:type="character" w:default="1" w:styleId="DefaultParagraphFont"> ... </w:style> ... </w:styles>

ooxml:text(
$text as xs:string?
) as element(w:t)
Summary:

This function creates a run (w:r) element.

Parameters:
$text: The string to be included in the text (w:t) element.

Usage Notes:


Example:
xquery version "1.0-ml";
import module namespace ooxml= "http://marklogic.com/openxml" at 
                               "/MarkLogic/openxml/word-processing-ml-support.xqy";

ooxml:text("Hello, World!")
=>
  <w:t xmlns:w="http://schemas.openxmlformats.org/wordprocessingml/2006/main" xml:space="preserve">Hello, World!</w:t>

ooxml:theme(
) as element(a:theme)
Summary:

This function creates a default w:theme element for a .docx package (word/themes/theme1.xml).

Parameters:

Usage Notes:

Example:
xquery version "1.0-ml";
import module namespace ooxml= "http://marklogic.com/openxml" at 
                               "/MarkLogic/openxml/word-processing-ml-support.xqy";

ooxml:theme()
=>
(Note:following truncated for brevity)
<a:theme name="Office Theme" xmlns:a="http://schemas.openxmlformats.org/drawingml/2006/main"> <a:themeElements> ... </a:themeElements> <a:objectDefaults/> <a:extraClrSchemeLst/> </a:theme>