I have an XSD where i have to use assert condition. I would want to print all columns for condition when indicator='A' and few columns another condition is indicator='D'. I have the below logic but i have around 100 columns so can anyone help me with optimizing the query?
<xs:assert test="if (indicator eq 'A')
then test1 and test2 and test3 and test4 and test5 and test6 and test7
else if (indicator eq 'B') then test1 and test3
else false()"/>
The input XML is in this format:
`<?xml version="1.0" encoding="utf-8"?>
<p:CustomerElement xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<recordCount>1234</recordCount>
<Customer>
<indicator>A</indicator>
<test1>hdjfs</test1>
<test2>idsfh</test2>
<test3>idsfh</test3>
<test4>idsfh</test4>
<test5>idsfh</test5>
<test6>idsfh</test6>
<test7>idsfh</test7>
</Customer>
<Customer>
<indicator>B</indicator>
<test1>abcd</test1>
<test2></test2>
<test3>uydshjk</test3>
<test4></test4>
<test5></test5>
<test6></test6>
<test7></test7>
</Customer>
</p:CustomerElement>
So as i mentioned when A then all columns populate and when B only 2 columns. If in case i have written the condition wrong, please help me on using which condition to use.
The values for indicator is A or B only for sure.
Thanks.
To simplify
given this statement,
allow the
else
to cover theB
case:Next, given this statement [emphasis added],
to avoid having to enumerate all of
test1
throughtest7
(especially given that you mentioned,just constrain the total count of
test1
throughtest7
in the assertion,This will be no less strict than enumerating them if you've already declared their existence explicitly in the content model of
parent
.As one last step, you might re-write
if else
to the logically equivalent,but preference for this form over its predecessor is mostly a matter of taste.