If-exist condition for conditional text or section

WordPerfect has a very useful condition for conditional text that must be possible in Writer, but I have not figured out how to implement: How to hide a block or section of text (or frame/figure/table/etc) unless one or more instances of a class (to which that text pertains) exist. Is there a way of expressing the condition
  "If: a field {IS|IS NOT} BLANK"
that can be used in the condition to hide or expose relevant text?

I'm not sure what your use case is... (there's not much in your question
about what you are trying to do) ...so I may be in the wrong postal code
with this suggestion. I'm using mail merge, and I keep all 'conditions'
outside the document itself.

I studied the Opendocument elements and I've decided that conditional text
in LibreOffice Writer is basically a doppleganger from Opendocument 1.0
that made it into the spec, but had no functionality.

So, all text that could be "hidden" now is kept in the database that I use
for the merge (which is a registered Calc spreadsheet). And I can build my
own if statements there in new titled columns easily.

In Calc:
Column A contains book title
Column J contains number of pages in the work.
Column Z (contains paper thickness imported from a query in the calc
spreadsheet)
Column ZA contains the SpineText with the calculation: (IF(J*Z>.25,A2,"")

While the spine text here is short, I keep the entire back cover copy (up
to 5 paragraphs) in the same database, each paragraph in a separate cell
(for convenience of editing, and to make the resulting LO Writer file more
easily deal with.) I have no conditions on that back cover text but the
same method could also apply to entire paragraphs. Each point where a style
change is required, you'll need a separate cell.

This method is limited to primary text stream, and header and footer text
on each page. That is, I haven't been able to "merge" into adhoc text
boxes In LibreWriter, only into the primary stream and header footer text.
I have been able to shift the footer text outside the defined box to
anywhere on the page, but that limits to 1 (or 2) out of stream boxes per
page, and the text can't be rotated or shaped.

Greetings,
You can use a section to do that in WRITER. The easy way to start is to
highlight the text and then Insert > Section. In the section
configuration, there is a conditional "Hide" you can use. For example,
I created my wide's course material using WRITER and I use a variable
named "User"; this variable is used on the cover page to indicate
"Teacher's version" or "Student's version" (the value of User is
Teacher or Student). The document contains the homework and practice
exams the students will need to do throughout the semester. In the
"Student's version", each question is followed by a blank area or by
empty lines to allow them to write the answer to the question. In the
"Teacher's version", each question is followed by a detailed answer.
The way I did this was to create two sections after each question: the
first section is for the detailed answer, and is hidden if 'User eq
"Student"'. The second section contains the space needed for the
students to write their answer; this section is hidden if 'User neq
"Student"'. This way, I can flip between versions by changing the value
of the variable.

There is more information here:
https://help.libreoffice.org/3.3/Writer/Hiding_Text

There are multuple ways of doing what you are looking for, but I
believe sections are more flexible.

I hope this helps.
Rémy.

Hi Michael,

Sorry, I should have given an example:
Suppose there is a daily or weekly report, which includes a database query of birthday(s) for that report period. If so, the birthday-relevant text or table is included, with the specific birthdays; otherwise, no such text or table.

So the generalization is that you have a class -- say, birthdays -- and the test is whether you have any instances of that class for the period (or other domain) of interest. Writer makes it easy to conditionally hide or reveal a section of text, but not (AFAIK) to include as a condition whether a field is instantiated or empty.

The example you give is extremely interesting. I would not have thought of it, if only because it requires coordination of Calc and Writer [which I have not thought about how to do]. But the biggest essential difference is one that you identify -- keeping the 'conditions' outside the document itself -- where my initial premise was (and I think remains) to use Writer's conditional-text features within the Writer document.

Your example is a great one to study (and to think about how you coordinate Calc and Writer), but I think that Writer alone can do this job [as WordPerfect does] if there is a way to implement the condition that a field is either empty or filled/instantiated. Moreover, that approach (rather than keeping the conditional text outside the document) allows the use of Writer's rich conditional-text features. The one feature that I'm trying to reproduce is WordPerfect's ability to test whether any field of merged data is empty or instantiated, and use that test to conditionally hide or reveal a section of text.

Thanks for your reply,
John

Thanks, Remy. I'm very familiar with that use of conditional text. [My wife is also a teacher, and also depends on the LO-user in the house to help when things get moderately complex. :wink: ]

The problem comes not when I can specify a switch (like "User" == "Teacher" or "Student"), but when merging external data -- where a field may be either empty or instantiated -- to control a section of conditional text. Is there some way to do "IF-EXISTS" or "IF-BLANK" test on a field?

I appreciate your response,
John

John,

To follow up on the conditions aren't really conditional, but static
states: I got as far as page 613 of the ODF 1.2 specification. (which used
to be free from OASIS, but now costs chf198 from ISO.org.)

it says

"The text:condition attribute specifies a condition. Conditions do not have
a predefined
syntax, but the attribute value should begin with a namespace prefix,
followed by a ":" (U+003A,
COLON) separator, followed by the text of a formula. The namespace bound to
the prefix
determines the syntax and semantics of the formula."

But all my attempts to make this work within Libreoffice writer failed. LO
Writer evaluated anything I put into <text:conditional-text> as pure text,
not as a formula (as far as I could tell.)

I was approaching from a differential analysis on .fodt documents before
and after I made various changes, then studying ODF spec to determine what
that field could actually do.
There's clearly no interface to support this. It's in the spec so there
should be capability in LO Writer (or at least OpenOffice 2 & 3).. but
regardless what program I tried, I continued to get similar results...
regardless of what was in the <text:condition> attribute, i always got one
of the two results unless the evaluation was strictly either "FALSE" or
"TRUE" or some variant of capitalization of one of these. So wherever the
actual statement was it was looking for a boolean result but a string
result, which LO wasn't returning if the evaluation ever happened.

So, I switched to Calc where I know how to do boolean logic, and each cell
is visible realtime, so it doesn't take advanced forensics to see what is,
and fix.

FWIW, the 1.2 spec is still available free from
https://docs.oasis-open.org/office/v1.2/

I don't know if the words are everywhere identical with the ISO
version * but certainly the words you quote are the same.

* Does anybody know whether they are the same? The Oasis document has a
  section at the begininning prohibiting changes to the document and
  prohibiting removal of that section, so I would hope so!

The ISO version is also publically available from
https://standards.iso.org/ittf/PubliclyAvailableStandards/index.html

I suppose you must be talking about the cost of a paper copy from ISO.
I expect you're free to print a downloaded copy if you wish.

Hi Michael,

With the help of Dave Howorth's links to the OpenDocument spec, I just spent a couple hours trying to track down and understand your references, and realize that I am:
  (a) in over my head (even just to understanding the relevance of the different files organized under v.1.2), and
  (b) nowhere near a solution to how to test if a field is empty for the purpose of controlling conditional text.

[Indeed, I could not even see the connection between the schema for text:condition and my understanding of Writer's conditional text functions. It appears that working through the spec would take months -- and even then I'm not sure I would see the relationship to LO program design and functionality. (I wonder if that does not reflect your own experience, as you described it.)]

Thank you so much for the education in LO design, which I will mark to study further, but I can't afford to study it further now. I'm afraid I will have to accept that LO Writer cannot (for now) do what I thought it might do.

Kind regards,
John