[Schematron] Rule context expression doubt

Lars Huttar lars_huttar at sil.org
Fri Jan 2 08:51:03 EST 2009


On 1/2/2009 5:18 AM, Luis Costa wrote:
>  
> 
> I’ve a XML 1) and I need to implement for instance role described in 2)
> 
>  
> 
>  
> 
>  
> 
> XML 1)
> 
> <MediaDB>
> 
>   <DVD label="DVD">
> 
>       <Identifier>
> 
>           <key value="1"/>
> 
>       </Identifier>
> 
>       <Director value="J.S. Bach"/>
> 
>   </DVD> 
> 
>   <DVD label="DVD">
> 
>      <Identifier>
> 
>          <key value="2"/>
> 
>      </Identifier>
> 
>      <Director value="Stanley Kubrick"/>
> 
>   </DVD>
> 
> </MediaDB>
> 
>  
> 
>  
> 
>  
> 
>  
> 
> 2)
> 
> <rule context=”DVD/ Identifier/ key[@value=2]/../ Director ">           
> 
>             <assert test="@value=’Stanley Kubrick’”/>
> 
>  </assert>
> 
>  
> 
>  
> 
> For instance I need to check that:
> 
> The director of DVD/ Identifier/ key[@value=2] is “Stanley Kubrick”
> 
> I think I really have to use in context rule “/../” expression but I’m
> getting the following error:
> 
> “error in expression” when using “/../” in context expression,
> 
> Question:
> 
> Is there a valid expression similar than “/../” to use in context rule
> that allows climbing a level in XML?
> 
>  

I'm not sure I know about using ".." in a context pattern, but your
context expression could be expressed as

<rule context=”DVD[Identifier/key[@value=2]]/Director">
         <assert test="@value=’Stanley Kubrick’”/>

Does that work?


Incidentally, it seems strange that you would be establishing a whole
unique context just for a single Identifier value of a DVD... but maybe
that's just an example that doesn't actually reflect the nature of your XML.

HTH,
Lars



More information about the Schematron mailing list