Skip to content

Add support to the Optional attribute for the Conditional tag#31

Open
Xiphereal wants to merge 1 commit into
OpenXmlDev:vNextfrom
Xiphereal:vNext
Open

Add support to the Optional attribute for the Conditional tag#31
Xiphereal wants to merge 1 commit into
OpenXmlDev:vNextfrom
Xiphereal:vNext

Conversation

@Xiphereal

Copy link
Copy Markdown

In this PR I've added support for the Optional attribute for the Conditional tag in the DocumentAssembler.

This modification comes from the need of being able to have a Select with XPath selecting a (sometimes) missing node from the data XML.

@Xiphereal

Copy link
Copy Markdown
Author

Any updates?

@Xiphereal

Copy link
Copy Markdown
Author

Any news on the subject @EricWhiteDev ?

huan086 pushed a commit to huan086/Open-Xml-PowerTools that referenced this pull request Sep 17, 2024
Enabled system.drawing.common compatible in tests
github-actions Bot added a commit to sergey-tihon/Clippit that referenced this pull request Jul 3, 2026
…ional directive

Port of OpenXmlDev/Open-Xml-PowerTools#31.

When Optional="true" is set on a Conditional directive, a missing XPath
node is treated as an empty string for Match/NotMatch evaluation instead
of throwing an error. Without Optional, missing nodes continue to produce
a template error as before.

Changes:
- Clippit/Word/DocumentAssembler.cs: add Optional attr to Conditional XSD
  schema; read optional flag and pass to EvaluateXPathToString
- Clippit.Tests/Word/DocumentAssemblerTests.cs: 4 tests covering:
  - Optional=true + missing node + Match="" → content included
  - Optional=true + missing node + Match="x" → content excluded
  - No Optional + missing node → template error (regression guard)
  - Optional=true + present node → normal match behavior

Closes #382

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
sergey-tihon pushed a commit to sergey-tihon/Clippit that referenced this pull request Jul 3, 2026
…er Conditional directive (#395)

* fix(word): add Optional attribute support to DocumentAssembler Conditional directive

Port of OpenXmlDev/Open-Xml-PowerTools#31.

When Optional="true" is set on a Conditional directive, a missing XPath
node is treated as an empty string for Match/NotMatch evaluation instead
of throwing an error. Without Optional, missing nodes continue to produce
a template error as before.

Changes:
- Clippit/Word/DocumentAssembler.cs: add Optional attr to Conditional XSD
  schema; read optional flag and pass to EvaluateXPathToString
- Clippit.Tests/Word/DocumentAssemblerTests.cs: 4 tests covering:
  - Optional=true + missing node + Match="" → content included
  - Optional=true + missing node + Match="x" → content excluded
  - No Optional + missing node → template error (regression guard)
  - Optional=true + present node → normal match behavior

Closes #382

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>

* fix(word): guard Conditional Optional parsing and update changelog

* docs(word): mention Conditional Optional support in DocumentAssembler tutorial

---------

Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant