Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>To do this, you can define a variable to hold the look-up data</p> <pre><code>&lt;xsl:variable name="lookup" select="document('Lookup.xml')/lookup"/&gt; </code></pre> <p>And then you can look-up the quantity for a particular Line-Item like so (In this case, the XSLT is currently positioned on a Quantity element within a Line-Item)</p> <pre><code>&lt;xsl:variable name="quantity" select="$lookup//Code[LookupID = current()/../ID]/LookupQuantity"/&gt; </code></pre> <p>If nothing was returned by this variable, then you know the element was not in the look-up</p> <p>Here is the full XSLT</p> <pre><code>&lt;xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"&gt; &lt;xsl:variable name="lookup" select="document('Lookup.xml')/lookup"/&gt; &lt;xsl:template match="@*|node()"&gt; &lt;xsl:copy&gt; &lt;xsl:apply-templates select="@*|node()"/&gt; &lt;/xsl:copy&gt; &lt;/xsl:template&gt; &lt;xsl:template match="Line-Item/Quantity"&gt; &lt;xsl:variable name="quantity" select="$lookup//Code[LookupID = current()/../ID]/LookupQuantity"/&gt; &lt;Quantity&gt; &lt;xsl:choose&gt; &lt;xsl:when test="number($quantity) = number($quantity)"&gt; &lt;xsl:value-of select="number(.) div number($quantity)"/&gt; &lt;/xsl:when&gt; &lt;xsl:otherwise&gt; &lt;xsl:value-of select="."/&gt; &lt;/xsl:otherwise&gt; &lt;/xsl:choose&gt; &lt;/Quantity&gt; &lt;/xsl:template&gt; &lt;/xsl:stylesheet&gt; </code></pre> <p>When applied to your sample XML, the following is output</p> <pre><code>&lt;document&gt; &lt;Line&gt; &lt;Line-Item&gt; &lt;ID&gt;5&lt;/ID&gt; &lt;Quantity&gt;4&lt;/Quantity&gt; &lt;/Line-Item&gt; &lt;/Line&gt; &lt;Line&gt; &lt;Line-Item&gt; &lt;ID&gt;6&lt;/ID&gt; &lt;Quantity&gt;3&lt;/Quantity&gt; &lt;/Line-Item&gt; &lt;/Line&gt; &lt;Line&gt; &lt;Line-Item&gt; &lt;ID&gt;60&lt;/ID&gt; &lt;Quantity&gt;3020&lt;/Quantity&gt; &lt;/Line-Item&gt; &lt;/Line&gt; &lt;/document&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