title: Avoid ambiguous rule match when editing same element in XSLT?
body: <p>I want to add an attribute to a  element, if the element should not be removed from the transformation. I thought my current XSL would satisfy this, by first discarding all elements that's not in the allowedArticles variable, and then adding the attribute to the elements that are left.</p>
  
  <p>This however, does not work, and I am not sure how I would go about doing it correctly. I want to do both, discard the entire element if not in allowedArticles, and add an attribute to it if it should be in the transformation.</p>
  
  <p>Could someone point me in the right direction?</p>
  
  <p>This is my example XSL:</p>
  
  <pre><code>&lt;?xml version="1.0" encoding="UTF-8"?&gt;
  &lt;xsl:stylesheet version="2.0"
    xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
    xmlns:escenic="http://xmlns.escenic.com/2009/import"&gt;
    &lt;xsl:output omit-xml-declaration="no" indent="yes"/&gt;
    &lt;xsl:strip-space elements="*" /&gt;
  
    &lt;!-- Fetch the array from an external file: allowedArticles.xml --&gt;
    &lt;xsl:variable
      name="allowedArticles"
      select="document('allowedArticles.xml')/allowedArticles/articleId" /&gt;
  
    &lt;!-- Identity template, copies every element in source file --&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;!-- Matches content items that are NOT in the allowedArticles array,
      and discards them by doing nothing--&gt;
    &lt;xsl:template match="escenic:escenic/escenic:content[not(@exported-dbid=$allowedArticles)]" /&gt;
  
    &lt;!-- Removes section-ref elements from within content elements --&gt;
    &lt;xsl:template match="escenic:escenic/escenic:content/escenic:section-ref" /&gt;
  
    &lt;!-- Add delete-relations attribute to all content elements --&gt;
    &lt;xsl:template match="escenic:escenic/escenic:content"&gt;
      &lt;xsl:copy&gt;
        &lt;xsl:attribute name="delete-relations"&gt;
          &lt;xsl:value-of select="'true'" /&gt;
        &lt;/xsl:attribute&gt;
        &lt;xsl:apply-templates select="node() | @*" /&gt;
      &lt;/xsl:copy&gt;
    &lt;/xsl:template&gt;
  
  &lt;/xsl:stylesheet&gt;
  </code></pre>