In previous examples, we have seen the usage of a temporary variable or <let> tag to store a value which is later used in an XPath predicate (the square brackets surrounding the index of an element array). It is important to note that this is not required. A simple XPath statement can be used in the predicate for any other XPath statement. For example see the following:
<pattern id="wEmptyMetadataComment"> <title>Ensure person metadata comment is not blank.</title> <rule context="/ns:SomeDocument/nc:Person"> <assert test="string-length(/ns:SomeDocument/nc:Metadata[@s:id=current()/@s:metadata]/nc:CommentText) > 0"> Comments regarding a person should not be blank. </assert> </rule> </pattern>
In the above example, simply the attribute @s:id=/ns:SomeDocument/nc:Person/@s:metadata is used to identify which specific Metadata element should be examined. With the context defined as /ns:SomeDocument/nc:Person, the rule will loop through each nc:Person element and use the appropriate @s:metadata value in each subsequent pass.
[Updated: Corrected Syntax on 04-01-2010]
Sorry for the typo. . .updated the post to fix (post showed @s:id instead of @s:metadata).
ReplyDelete