title: Xml lookup tables
body: <p>I am attempting to use a lookup table in xml for an xsl transformation. I am familiar with xsl and not concerned with the physical loading and querying of a lookup table, rather I'm having trouble formulating an appropriate XPath with a sparsely populated lookup.</p>
  
  <p>I will be using a table that will require fallback to default values if the lookup attribute is missing. The following xml is an example of this population:</p>
  
  <pre><code>&lt;?xml version="1.0" encoding="UTF-8"?&gt;
  &lt;codes&gt;
      &lt;code id="12" country="ca" areacode="420" division="45"/&gt;
      &lt;code id="13" country="ca" areacode="519" division="45"/&gt;
      &lt;code id="14" country="ca" areacode="519" division="40"/&gt;
      &lt;code id="15" country="ca" division="46"/&gt;
      &lt;code id="16" country="ca"/&gt;
      &lt;code id="17" country="au"/&gt;
      &lt;code id="18" country="au" division="32"/&gt;
  &lt;/codes&gt;
  </code></pre>
  
  <p>When doing the lookup I will have input for country, area code and division to find the appropriate id.</p>
  
  <p>I've tried a couple of options but none of them are satisfactory. The XPath below will return two entries (I should get the id of 15):</p>
  
  <pre><code>/codes/code[@country='ca' and (@areacode='222' or empty(@areacode)) and (@division='46' or empty(@division))]/@id
  </code></pre>
  
  <p>XPath 2.0 is supported in my xsl.</p>
  
  <p>Any assistance will be greatly appreciated! </p>