Note that there are some explanatory texts on larger screens.

plurals
  1. POHow to filter node list based on the contents of another node list
    primarykey
    data
    text
    <p>I'd like to use XSLT to filter a node list based on the contents of another node list. Specifically, I'd like to filter a node list such that elements with identical id attributes are eliminated from the resulting node list. Priority should be given to one of the two node lists. </p> <p>The way I originally imagined implementing this was to do something like this:</p> <pre><code>&lt;xsl:variable name="filteredList1" select="$list1[not($list2[@id_from_list1 = @id_from_list2])]"/&gt; </code></pre> <p>The problem is that the context node changes in the predicate for $list2, so I don't have access to attribute @id_from_list1. Due to these scoping constraints, it's not clear to me how I would be able to refer to an attribute from the outer node list using nested predicates in this fashion.</p> <p>To get around the issue of the context node, I've tried to create a solution involving a for-each loop, like the following:</p> <pre><code> &lt;xsl:variable name="filteredList1"&gt; &lt;xsl:for-each select="$list1"&gt; &lt;xsl:variable name="id_from_list1" select="@id_from_list1"/&gt; &lt;xsl:if test="not($list2[@id_from_list2 = $id_from_list1])"&gt; &lt;xsl:copy-of select="."/&gt; &lt;/xsl:if&gt; &lt;/xsl:for-each&gt; &lt;/xsl:variable&gt; </code></pre> <p>But this doesn't work correctly. It's also not clear to me how it fails... Using the above technique, filteredList1 has a length of 1, but appears to be empty. It's strange behaviour, and anyhow, I feel there must be a more elegant approach.</p> <p>I'd appreciate any guidance anyone can offer. Thanks.</p>
    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.
 

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