I am using ISO Schematron to validate an XML document. The rule I have set works as required, but I want to report the name of the parent element from the context of where my assertion is fired. A sample document might contain the XML fragment:
<Name>Alan Smith<br/></Name>
My Schematron rule tests that the <br/>
element is only allowed to occur as a child of a <title>
element. The rule is as follows:
<rule context="br">
<assert test="parent::title"
>The "br" element is not allowed as a child of the '<iso:value-of select=".."/>' element.'</assert>
</rule>
When I run this rule against the fragment, the assertion is correctly fired, however I want the message to tell me that "The "br" element is not allowed as a child of the 'Name' element". Instead it actually shows "The "br" element is not allowed as a child of the 'Alan Smith' element". So the <iso:value-of select=".."/>
expression is actually selecting the text node and not the parent element as I expected? Can someone help explain what XPpath expression I should be using in the select statement to display the name of the parent element in my error message?. Thanks.
UPDATE: I managed to achieve the desired result by removing the select statement, and replacing it with a name element as in:
<rule context="br">
<assert test="parent::title"
>The "br" element is not allowed as a child of the '<name path=".."/>' element.'</assert>
</rule>
So my problem is solved, but if anyone can explain why my first attempt doesn't work, that would be very helpful.