The goal of this section is to offer you some illustrative examples on how to remove specific content from a template.
The options are manifold. By providing a "needle" (the text to be searched for), you may remove from a template the following blocks of content:
By also providing a match we can further filter the elements to be removed. If a match is provided the needle may be removed in certain cases.
It is also important to recall that the "removal of content" is the first set of instructions to be carried out by Docxpresso when processing the JSON data.
We strongly recommend to use Docxpresso variables as needles. This is so because Word and Libreffice may introduce XML tags that are not visible but may hinder getting the expected result in the search process. Docxpresso variables are parsed to eliminate that issue and you may later delete them or set them to an empty string.
Let us first start with an example on how to remove plain text from a template.
The following JSON will remove all appeareances of the text "Text to be removed." from the provided template:
{
"template": "insert here the given template base64 encoded",
"output": "odt",
"remove": [
{
"options": {
"needle": "Text to be removed.",
"element": "text"
}
}
]
}
You may check that the text has been removed from the template twice. In the event that you would like only the second ocurrence to be deleted you should modify the JSON as follows:
{
"template": "insert here the given template base64 encoded",
"output": "odt",
"remove": [
{
"options": {
"needle": "deleteme",
"element": "text",
"match": 2
}
}
]
}
The following JSON will remove all content bookmarked under the tag "deleteme":
{
"template": "insert here the given template base64 encoded",
"output": "odt",
"remove": [
{
"options": {
"needle": "deleteme",
"element": "bookmark"
}
}
]
}
The following JSON will remove all paragraphs (but not headings) that include the word "removed" (including the one in the table header):
{
"template": "insert here the given template base64 encoded",
"output": "odt",
"remove": [
{
"options": {
"needle": "removed",
"element": "paragraph"
}
}
]
}
As before we could have choosen a single ocurrence with the help of the match parameter. We leave that as an exercise to the reader.
The following JSON will remove the list item that includes the text "Item 1":
{
"template": "insert here the given template base64 encoded",
"output": "odt",
"remove": [
{
"options": {
"needle": "Item 1",
"element": "list-item"
}
}
]
}
If we want to remove the whole list we only need to change the option element to list:
{
"template": "insert here the given template base64 encoded",
"output": "odt",
"remove": [
{
"options": {
"needle": "Item 1",
"element": "list"
}
}
]
}
If we want to remove a particular table row including the text "First" we need to use the following JSON:
{
"template": "insert here the given template base64 encoded",
"output": "odt",
"remove": [
{
"options": {
"needle": "First",
"element": "table-row"
}
}
]
}
In case we want to remove the whole table we have just to modify the element property:
{
"template": "insert here the given template base64 encoded",
"output": "odt",
"remove": [
{
"options": {
"needle": "First",
"element": "table"
}
}
]
}
In case we want to remove an image with an alt text ({{my_image}} in this particular case):
{
"template": "insert here the given template base64 encoded",
"output": "odt",
"remove": [
{
"options": {
"needle": "my_image",
"element": "image"
}
}
]
}
We could also have chosen to remove the image because of its order of appearance to get the same result:
{
"template": "insert here the given template base64 encoded",
"output": "odt",
"remove": [
{
"options": {
"element": "image",
"match": 1
}
}
]
}
In case we want to remove a chart with an alt text ({{my_chart}} in this particular case):
{
"template": "insert here the given template base64 encoded",
"output": "odt",
"remove": [
{
"options": {
"needle": "my_chart",
"element": "chart"
}
}
]
}
We could also have chosen to remove the chart because of its order of appearance to get the same result:
{
"template": "insert here the given template base64 encoded",
"output": "odt",
"remove": [
{
"options": {
"element": "chart",
"match": 1
}
}
]
}
In case we want to remove a textbox including the text "required":
{
"template": "insert here the given template base64 encoded",
"output": "odt",
"remove": [
{
"options": {
"needle": "required",
"element": "textbox"
}
}
]
}
We will remove a heading of level 2 that contains the text "removed":
{
"template": "insert here the given template base64 encoded",
"output": "odt",
"remove": [
{
"options": {
"needle": "removed",
"element": "heading",
"heading-level": 2
}
}
]
}
We can, of course, combine any of the previous:
{
"template": "insert here the given template base64 encoded",
"output": "odt",
"remove": [
{
"options": {
"needle": "removed",
"element": "heading",
"heading-level": 2
}
},
{
"options": {
"element": "chart",
"match": 1
}
},
{
"options": {
"needle": "Item 1",
"element": "list-item"
}
}
]
}