title: Select text from linked in XML file based on the value of a specific atttribute in current node
body: <p>I have this XML data file which contains the following descriptions (<strong>XML File 1</strong>):</p>
  
  <pre><code>&lt;?xml version="1.0" encoding="UTF-8"?&gt;
  &lt;Labels Version="170902"&gt;
      &lt;AppointedAs&gt;Appointed As&lt;/AppointedAs&gt;
      &lt;Elder&gt;Elder&lt;/Elder&gt;
      &lt;MinisterialServant&gt;Ministerial servant&lt;/MinisterialServant&gt;
      &lt;NotAppointed&gt;Not appointed&lt;/NotAppointed&gt;
  &lt;/Labels&gt;
  </code></pre>
  
  <p>I also have another XML database file with details about publishers. Here is a stripped down example to show the issue in hand (<strong>XML File 2</strong>):</p>
  
  <pre><code>&lt;?xml version="1.0" encoding="utf-8"?&gt;
  &lt;PublisherDatabase xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns="http://www.publictalksoftware.co.uk/msa"&gt;
    &lt;Publishers&gt;
      &lt;Publisher Gender="Male" Appointed="MinisterialServant" Serving="Publisher"&gt;
        &lt;Name&gt;Brian Wood&lt;/Name&gt;
      &lt;/Publisher&gt;
    &lt;/Publishers&gt;
  &lt;/PublisherDatabase&gt;
  </code></pre>
  
  <p>Now, can you see the <strong>Appointed</strong> attribute in <strong>XML File 2</strong>? The <strong>values</strong> are repeated in <strong>XML File 1</strong> which in turn contain proper <strong>descriptions</strong>.</p>
  
  <p>To do what I need I am currently using this XSL script:</p>
  
  <pre><code>&lt;?xml version="1.0" encoding="UTF-8"?&gt;
  &lt;xsl:stylesheet version="1.0"
                  xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
                  xmlns:msa="http://www.publictalksoftware.co.uk/msa"&gt;
    &lt;xsl:output method="html" indent="yes" version="4.01"
      doctype-system="http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"
      doctype-public="//W3C//DTD XHTML 1.0 Transitional//EN"/&gt;
  
    &lt;xsl:variable name="PubDB" select="document('MSA_PublisherDatabase.XML')"/&gt;
    &lt;xsl:variable name="Labels" select="document('LabelsInfo.XML')"/&gt;
    &lt;xsl:template match="/"&gt;
      &lt;html&gt;
        &lt;head&gt;
          &lt;title&gt;Publishers Report&lt;/title&gt;
          &lt;link rel="stylesheet" type="text/css" href="Custom Publisher Report.css"/&gt;
        &lt;/head&gt;
        &lt;body&gt;
          &lt;table&gt;
            &lt;thead&gt;
              &lt;th class="cellVerticalHeading"&gt;
                &lt;xsl:value-of select="$Labels/Labels/AppointedAs"/&gt;
              &lt;/th&gt;
            &lt;/thead&gt;
            &lt;tbody&gt;
              &lt;xsl:apply-templates select="$PubDB/msa:PublisherDatabase/msa:Publishers/msa:Publisher[@Gender='Male']"&gt;
                &lt;xsl:sort select="msa:Name" data-type="text" order="ascending"/&gt;
              &lt;/xsl:apply-templates&gt;
            &lt;/tbody&gt;
          &lt;/table&gt;
        &lt;/body&gt;
      &lt;/html&gt;
    &lt;/xsl:template&gt;
  
    &lt;xsl:template match="msa:Publisher"&gt;
      &lt;tr&gt;
        &lt;td&gt;
          &lt;xsl:choose&gt;
            &lt;xsl:when test="@Appointed='Elder'"&gt;
              &lt;xsl:value-of select="$Labels/Labels/Elder"/&gt;
            &lt;/xsl:when&gt;
            &lt;xsl:when test="@Appointed='MinisterialServant'"&gt;
              &lt;xsl:value-of select="$Labels/Labels/MinisterialServant"/&gt;
            &lt;/xsl:when&gt;
            &lt;xsl:when test="@Appointed='NotAppointed'"&gt;
              &lt;xsl:value-of select="$Labels/Labels/NotAppointed"/&gt;
            &lt;/xsl:when&gt;
          &lt;/xsl:choose&gt;
        &lt;/td&gt;
      &lt;/tr&gt;
    &lt;/xsl:template&gt;
  
  &lt;/xsl:stylesheet&gt;
  </code></pre>
  
  <p>The above <strong>XSL</strong> is stripped down. As you can see, the value of the <strong>@Appointed</strong> attribute is <strong>MinisterialServant</strong>. It then uses this value to look up a <strong>node</strong> in the other linked in XML file to get the text to display (which is <strong>Ministerial servant</strong>).</p>
  
  <p>Can this XSL code be simplified? Can I somehow directly use the value of the <strong>@Appointed</strong> attribute in the lookup from the other linked in XML file?</p>
  
  <p>Thank you.</p>
  
  <h1>Expected Output</h1>
  
  <pre><code>   &lt;html&gt;
        &lt;head&gt;
          &lt;title&gt;Publishers Report&lt;/title&gt;
          &lt;link rel="stylesheet" type="text/css" href="Custom Publisher Report.css"/&gt;
        &lt;/head&gt;
        &lt;body&gt;
          &lt;table&gt;
            &lt;thead&gt;
              &lt;th class="cellVerticalHeading"&gt;
                Appointed As
              &lt;/th&gt;
            &lt;/thead&gt;
            &lt;tbody&gt;
                &lt;tr&gt;
                    &lt;td&gt;
                         Ministerial servant
                    &lt;/td&gt;
                &lt;/tr&gt;
            &lt;/tbody&gt;
          &lt;/table&gt;
        &lt;/body&gt;
      &lt;/html&gt;
  </code></pre>