Alexandr  Kramarev
Alexandr Kramarev

Reputation: 3

xsd:assert (complicated character verification)

Is there a way to verify that the template contains only those characters that are passed to @param ?

I considered options with xpath functions(fn:) but have not found a suitable option.

this is 2 valid xml for example:

<rule type="myRule" template="A-B-CB">
  <attribute param="B"/>
  <attribute param="A"/>
  <attribute param="C"/>
</rule> 


<rule type="myRule" template="A(C)-B">
  <attribute param="C"/>
  <attribute param="A"/>
  <attribute param="B"/>
</rule> 

and 2 not valid xml:

<rule type="myRule" template="AB-CD">
  <attribute param="A"/>
  <attribute param="B"/>
  <attribute param="C"/>
</rule> 


<rule type="myRule" template="AC">
  <attribute param="A"/>
  <attribute param="B"/>
  <attribute param="C"/>
</rule>

perhaps there are ideas how to implement it using schematrone or otherwise?

Upvotes: 0

Views: 107

Answers (1)

Michael Kay
Michael Kay

Reputation: 163322

So the set of letters in @template must be exactly the same as the set of letters in ./attribute/@param?

That is to say, distinct-values(string-to-codepoints(replace(@template, '\P{L}', ''))) must be the same set as distinct-values(attribute/@param/string-to-codepoints()).

So how do you assert that two sequences contain the same values, under permutation?

In XPath 3.1, deep-equal(sort($X), sort($Y))

In XPath 2.0, I can't think of anything better than

empty($X[not(.=$Y)]) and empty($Y[not(.=$X)])

I'll leave you to put this all together.

Upvotes: 1

Related Questions