|
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-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: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: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-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>
|
|
|