Search code examples
xmlxpathschematron

Schematron XPath : Can I split a string attribute acting like a list in a Schematron?


I'm trying to verify that all idRef of a list written in a single attribute are already declared ids.

Here is an example :

<Regions>
    <Region id="REGION1>
    <Region id="REGION3>
    <Region id="REGION3>
</Regions>
<Layouts>
    <Layout regions="REGION1, REGION2, REGION3" />
</Layouts>

I know how to do it if the idRef attribute define a single idRef :

<rule context="Display[@touchAspectRatio]">
    <assert test="@touchAspectRatio = //TouchAspectRatio/@id"></assert>

<TouchAspectRatio id="T1" />
<Displays>
    <Display touchAspectRatio="T1" />
    <Display touchAspectRatio="T1" />
</Displays>

but i can't find how to verify with a list defined like this in a string separated with ", ". I can't modify the structure of the XML and I know it would be much easier/feasible with a list of element but I have some constraint which stop me from changing the structure.

Do you guys have a solution?


Solution

  • Assuming you use Schematron with XSLT/XPath 2.0 you can use

    <assert test="every $id in tokenize(@regions, ',\s*') satisfies $id = //Regions/Region/@id"/>