Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 5 additions & 2 deletions OpenXmlPowerTools/DocumentAssembler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -521,6 +521,7 @@ private static string ValidatePerSchema(XElement element)
<xs:attribute name='Select' type='xs:string' use='required' />
<xs:attribute name='Match' type='xs:string' use='optional' />
<xs:attribute name='NotMatch' type='xs:string' use='optional' />
<xs:attribute name='Optional' type='xs:boolean' use='optional' />
</xs:complexType>
</xs:element>
</xs:schema>",
Expand Down Expand Up @@ -750,6 +751,8 @@ static object ContentReplacementTransform(XNode node, XElement data, TemplateErr
string xPath = (string)element.Attribute(PA.Select);
var match = (string)element.Attribute(PA.Match);
var notMatch = (string)element.Attribute(PA.NotMatch);
var optionalString = (string)element.Attribute(PA.Optional);
bool optional = (optionalString != null && optionalString.ToLower() == "true");

if (match == null && notMatch == null)
return CreateContextErrorMessage(element, "Conditional: Must specify either Match or NotMatch", templateError);
Expand All @@ -760,7 +763,7 @@ static object ContentReplacementTransform(XNode node, XElement data, TemplateErr

try
{
testValue = EvaluateXPathToString(data, xPath, false);
testValue = EvaluateXPathToString(data, xPath, optional);
}
catch (XPathException e)
{
Expand Down Expand Up @@ -815,7 +818,7 @@ private static XElement CreateParaErrorMessage(string errorMessage, TemplateErro
return errorPara;
}

private static string EvaluateXPathToString(XElement element, string xPath, bool optional )
private static string EvaluateXPathToString(XElement element, string xPath, bool optional)
{
object xPathSelectResult;
try
Expand Down