title: How to find if element has ancestor based on a variable or parameter (XPath 2.0)
body: <p>The problem I'm trying to solve is to get all elements that contain only a unique text element but at the same time also being able to exclude node trees based on a element name passed as a parameter to the XSLT sheet.</p>
  
  <p>The part to select all the nodes containing only a unique text element that's not empty was relatively easy:</p>
  
  <pre><code>$StartNode//element()/text()[normalize-space(.)]/parent::*
  </code></pre>
  
  <p>where <code>$StartNode</code> is a Xpath Expression to a specific Element in the XML document.</p>
  
  <p>Now the part I had quite some some problems with, excluding an specific node tree from the results:</p>
  
  <p>so I was hoping for something like:</p>
  
  <pre><code>$StartNode//element()/text()[normalize-space(.)]/parent::*[not(ancestor::**$element_to_be_excluded**)]
  </code></pre>
  
  <p>where $element_to_be_excluded is the element name to exclude.</p>
  
  <p>But it's not possible to use a variable on that part of the expression...</p>
  
  <p>So I came up with this solution </p>
  
  <pre><code>&lt;xsl:variable name="ancestors_of_current_node" as="xs:string*"&gt;
     &lt;xsl:sequence select="$current_parent_node/ancestor::*/name()"/&gt;
  &lt;/xsl:variable&gt;
  &lt;xsl:variable name="is_value_in_sequence" as="xs:boolean" select="functx:is-value-in-sequence($exclude_node_local_name, $ancestors_of_current_node)"/&gt;
  &lt;xsl:if test="not($is_value_in_sequence)"&gt;
      &lt;xsl:call-template name="dataElementMap"&gt;
         &lt;xsl:with-param name="node_item" select="$current_parent_node"/&gt;
      &lt;/xsl:call-template&gt;
  &lt;/xsl:if&gt;
  </code></pre>
  
  <p>where functx:is-value-in-sequence is:</p>
  
  <pre><code>&lt;xsl:function name="functx:is-value-in-sequence" as="xs:boolean" xmlns:functx="http://www.functx.com"&gt;
    &lt;xsl:param name="value" as="xs:anyAtomicType?"/&gt;
    &lt;xsl:param name="seq" as="xs:anyAtomicType*"/&gt;
    &lt;xsl:sequence select="$value = $seq"/&gt;
  &lt;/xsl:function&gt;
  </code></pre>
  
  <p>Now the question is, it's there a more elegant way to solve this problem?</p>
  
  <p>Thanks in advance for any hint.</p>
  
  <p>Regards
  Vlax</p>