David Carlisle wrote a very cool:
… solution that works for
any size chessboard …
Thank you David!
Here is how David models the chessboard:
<n-queens>
<queen
column="1"
row="3"/>
<queen
column="2"
row="1"/>
<queen
column="3"
row="4"/>
<queen
column="4"
row="2"/>
</n-queens>
And here is his (mind-blowing) Schematron schema:
<sch:schema
xmlns:sch="http://purl.oclc.org/dsdl/schematron"
queryBinding="xslt2">
<sch:pattern
id="n-Queens-Problem">
<sch:rule
context="n-queens">
<sch:assert
test="every
$c in 1 to count(queen) satisfies exists(queen[@column=$c])">
There cannot be two queens in the same column.
</sch:assert>
<sch:assert
test="every
$r in 1 to count(queen) satisfies exists(queen[@row=$r])">
There cannot be two queens on the same row.
</sch:assert>
<sch:assert
test="count(queen)=count(distinct-values(queen/(number(@row)
- number(@column))))">
There cannot be two queens on a (falling) diagonal.
</sch:assert>
<sch:assert
test="count(queen)=count(distinct-values(queen/(number(@row)
+ number(@column))))">
There cannot be two queens on a (rising) diagonal.
</sch:assert>
</sch:rule>
</sch:pattern>
</sch:schema>