Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>You don't need to use an inner <strong>xsl:for-each</strong> loop here to look up the company name. You could just use an <strong>xsl:variable</strong> here with a select parameter where you can put your 'contains' expressions</p> <pre><code>&lt;xsl:for-each select="Report_Data/Report_Entry"&gt; &lt;xsl:variable name="company_name" select="/Report_Data/Company_Data/Report_Entry[contains(current()/company_id, code)]/name" /&gt; </code></pre> <p>Note the use of <strong>current()</strong> here, which is to ensure the expression uses the <strong>company_id</strong> of the current <strong>Report_Data/Report_Entry</strong> element you are on, as opposed to the <strong>Company_Data/Report_Entry</strong> you are searching in the expression. If you were to do what you were currently doing, namely <code>/Report_Data/Report_Entry/company_id</code>, then this is an 'absolute' expression which starts from the top-level document node and will always return the first <strong>company_id</strong> in the XML.</p> <p>But in anycase, you could then simply output this variable, or use an <strong>xsl:choose</strong> to output 'NA' instead should the variable be empty (i.e No company name was found).</p> <p>Were it not for the fact the ids do not match up, such looking up of values are usually better handled with a key. To look up an Report_Entry by its code you would define a key like so</p> <pre><code>&lt;xsl:key name="company" match="Company_Data/Report_Entry" use="code" /&gt; </code></pre> <p>Then to look it up you could do something like this...</p> <pre><code>&lt;xsl:for-each select="Report_Data/Report_Entry"&gt; &lt;xsl:variable name="company_name" select="key('company', company_id)" /&gt; </code></pre> <p>Of course, this would fail in your case because the ids are not exactly the same, but perhaps you can just remove leading zeroes. Try this, perhaps.</p> <pre><code>&lt;xsl:for-each select="Report_Data/Report_Entry"&gt; &lt;xsl:variable name="company_name" select="key('company', number(company_id))" /&gt; </code></pre>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload