I have list of mapping XML documents which is basically translations from one language to other. This is a sample:
<?xml version="1.0" encoding="UTF-8"?>
<root lang="en,fr">
<item name="error_1">
<en><![CDATA[User name does not exist.]]></en>
<fr><![CDATA[Nom d'utilisateur n'existe pas.]]></fr>
</item>
<item name="error_2">
<en><![CDATA[One or both path parameters have not defined.]]></en>
<fr><![CDATA[Un ou deux paramètres de trajet ne sont pas définies.]]></fr>
</item>
</root>
I need to write XSD on this type of files if it is possible.
As I see here is some type of complicity with elements because language elements is dynamic type base on attribute lang of the root element.
Language value is base on ISO 639-1 standard, separated by comma and could be one or more. In this case each item set must have the same element included. Default lang attribute has single value “en” and element item only one sub-element en. It is looks like that:
<?xml version="1.0" encoding="UTF-8"?>
<root lang="en">
<item name="error_1">
<en><![CDATA[User name does not exist.]]></en>
</item>
<item name="error_2">
<en><![CDATA[One or both path parameters have not defined.]]></en>
</item>
</root>
I need some solution, advice. Is this task achievable?
W3C schema doesn’t allow you to express those sort of conditional constraints.
Schematron is an ISO standard that was designed for this sort of validation.
As an aside, if you made the
@langNMTOKENS other systems reading the schema would know how to handle it. Comma separated values requires additional custom parsing logic to understand that there are multiple values in that attribute value.