title: XSLT 2.0 separating two recursive outputs
body: <p>XSLT fiddle here: <a href="https://xsltfiddle.liberty-development.net/bdxtqU/5" rel="nofollow noreferrer">https://xsltfiddle.liberty-development.net/bdxtqU/5</a></p>
  
  <p>This question follows on from the implications of <a href="https://stackoverflow.com/questions/52834795/xsl-2-0-generating-distinct-urls-from-nested-elements">this answer</a> where I wanted to output, using XSLT 2.0, <code>&lt;persName&gt;</code> into an HTML URL, where <code>&lt;persName&gt;</code> can be found inside another <code>&lt;persName&gt;</code>, so all are turned into URLs.</p>
  
  <pre><code>&lt;persName nymRef="#Raimunda_Faure"&gt;Raimunda uxor 
     &lt;persName nymRef="#Bernard_Faure_Senior"&gt;Bernardi Fabri 
                     senior&lt;/persName&gt;&lt;/persName&gt;
  </code></pre>
  
  <p>Outputs to:</p>
  
  <pre><code> &lt;a href="www.foo.com/person/Raimunda_Faure"&gt;Raimunda 
      uxor&lt;/a&gt;&lt;a href="www.foo.com/person/Bernard_Faure_Senior"&gt;Bernardi 
        Fabri&lt;a&gt;
  </code></pre>
  
  <p>Using the code found below. And I also use it for another 'named entity' that gets output to a URL, <code>&lt;placeName&gt;</code>.</p>
  
  <p>The problem is that <code>&lt;persName&gt;</code> can appear inside <code>&lt;placeName&gt;</code> like so (and vice versa):</p>
  
  <pre><code>&lt;placeName type="event_loc" nymRef="#home_of_Guilhem_Vidal"&gt;in domo 
      &lt;persName nymRef="#Guilhem_Vidal_MSP-AU" role="own"&gt;Willelmi Vitalis&lt;/persName&gt;&lt;/placeName&gt;
  </code></pre>
  
  <p>What I'd like is a separation of <code>&lt;placeName&gt;</code> and <code>&lt;persName&gt;</code>, such that they only create nested URLs where the same named entity type is nested inside a named entity. </p>
  
  <p>Schematically, these would recursively output all <code>&lt;placeName&gt;</code> and <code>&lt;persName&gt;</code>:</p>
  
  <pre><code> &lt;persName&gt;text
     &lt;persName&gt;text&lt;/persname&gt;
     &lt;persName&gt;text&lt;/persname&gt;
   &lt;/persName&gt;
  
   &lt;placeName&gt;text
     &lt;placeName&gt;text&lt;/placename&gt;
     &lt;placeName&gt;text&lt;/placename&gt;
   &lt;/placeName&gt;
  </code></pre>
  
  <p>But these would only output the parent entity as URL, whether <code>&lt;placeName&gt;</code> or <code>&lt;persName&gt;</code>, and bypass the named entities contained within them:</p>
  
  <pre><code> &lt;persName nymRef="#Raimunda_Faure"&gt;Raimunda
     &lt;placeName nymRef="#Toulouse"&gt;Toulouse&lt;/placename&gt;
     &lt;placeName nymRef="Paris"&gt;Paris&lt;/placename&gt;
   &lt;/persName&gt;
  </code></pre>
  
  <p>Output to <code>&lt;a href="www.foo.com/person/Raimunda_Faure"&gt;Raimunda Toulouse Paris&lt;/a&gt;</code></p>
  
  <pre><code> &lt;placeName nymRef="#Toulouse"&gt;Toulouse
     &lt;persName nymRef="#Raimunda_Faure"&gt;Raimunda&lt;/persname&gt;
     &lt;persName nymRef="#Bernard_Faure"&gt;Bernard&lt;/persname&gt;
   &lt;/placeName&gt;
  </code></pre>
  
  <p>Output to <code>&lt;a href="www.foo.com/place/Toulosue"&gt;Toulouse Raimunda Bernard&lt;/a&gt;</code></p>
  
  <p>Here are the two existing templates:</p>
  
  <pre><code>&lt;xsl:template match="tei:text//tei:persName"&gt;
      &lt;xsl:variable name="nested" select="tei:persName[1]|
                       tei:persName[1]/following-sibling::node()" /&gt;
      &lt;xsl:element name="a"&gt; 
          &lt;xsl:attribute name="href"&gt;&lt;xsl:value-of select="concat($paramPersonurl,substring-after(@nymRef,'#'))"/&gt;&lt;/xsl:attribute&gt;
          &lt;xsl:apply-templates select="node() except $nested" /&gt;
      &lt;/xsl:element&gt;
      &lt;xsl:apply-templates select="$nested" /&gt;
  &lt;/xsl:template&gt;
  
  &lt;xsl:template match="tei:text//tei:placeName"&gt;
      &lt;xsl:variable name="nested" select="tei:placeName[1]|
                      tei:placeName[1]/following-sibling::node()" /&gt;
      &lt;xsl:element name="a"&gt; 
          &lt;xsl:attribute name="href"&gt;&lt;xsl:value-of select="concat($paramPersonurl,substring-after(@nymRef,'#'))"/&gt;&lt;/xsl:attribute&gt;
          &lt;xsl:apply-templates select="node() except $nested" /&gt;
      &lt;/xsl:element&gt;
      &lt;xsl:apply-templates select="$nested" /&gt;
  &lt;/xsl:template&gt;
  </code></pre>
  
  <p>It seems I should add an exclusion of the other named entity to either <code>&lt;xsl:apply-templates select="node() except $nested" /&gt;</code> or <code>&lt;xsl:apply-templates select="$nested" /&gt;</code> using something like <code>[node()[name() != 'persName']]</code>but I've not had success.</p>
  
  <p>Thanks in advance.</p>