You are here: Popular Formats > XML (Extensible Markup Language) Reader/Writer > xfMap > Reading the Input XML Document > Specifying Several Match Expressions for One Mapping Rule

Specifying several match expressions for one mapping rule

A mapping rule can have more than one match expression. The syntax for multiple match expressions in the <mapping> element’s match attribute is:

(ancestorElement/)*element({index})?([booleanExpr])?
[<whitespace>(ancestorElement/)*element({index})?([booleanExpr])?]*

The match expressions are evaluated in order and a mapping rule R matches an element E if any of the match expressions in the mapping rule matches element E.

For example, consider the following rule XML file:

<?xml version="1.0"?>
<c:colours xmlns:c="http://my.colours.com/colours" 
         xmlns:p="http://my.colours.com/primary"
         xmlns:o="http://my.colours.com/other">
   <p:red>255,0,0</p:red>            
   <p:green>0,255,0</p:green>
   <p:blue>0,0,255</p:blue>
   <o:orange category="oranges">255,165,0</o:orange>
   <o:DarkOrange category="oranges">255,140,0</o:DarkOrange>   
   <o:pink>255,192,203</o:pink>
   <o:brown category="browns">165,42,42</o:brown>
   <o:beige category="browns">245,245,220</o:beige>
</c:colours>

And the following mapping rule fragments:

<xfMap xmlns:c="http://my.colours.com/colours"
	xmlns:p="http://my.colours.com/primary"
	xmlns:o="http://my.colours.com/other">
<!-- Note that we bounded the ‘c’, ‘p’, and ‘o’ prefixes to their corresponding URIs in the namespace
 declarations in the xfMap root element. -->
...
<mapping match="c:colours/p:red c:colours/p:green">
<!-- Matches either the red or the green element; notice that 
	the match expressions are whitespace separated. -->
</mapping>
...
<mapping match="c:colours/o:*[@category='oranges' or @category='browns']
		 c:colours/p:*">
<!-- Matches any element that belong to the oranges or brown categories or any element that 
	belong to the primary colours namespace. i.e, the ‘orange’, ‘DarkOrange’, ‘brown’, 
	‘beige’, ‘red’, ‘green’ and ‘blue’ elements -->
</mapping>
...
<mapping match="c:colours/*[@category-]>
<!-- Matches any element having no category attribute, i.e., the ‘red’, ‘green’, ‘blue’, and 
	‘pink’ elements. -->
</mapping>
...
<mapping match="c:colours/o:*[@category-]>
<!-- Matches any element in the “http://my.colours.com/other” having no category attribute, 
	i.e., the ‘pink’ element. -->
</mapping>
...
<xfMap>