title: How to select the grandparent of a node using xslt
body: <p>I'm in a situation where I can only test for the child node, but I have to apply tags to the grandparent of this child node. </p>
  
  <p>I've tried using:</p>
  
  <pre><code>&lt;xsl:call-template name="grandparent" select="parent::parent::node()"/&gt;
  </code></pre>
  
  <p>and:</p>
  
  <pre><code>&lt;xsl:call-template name="grandparent" select="ancestor::node [@nameofgrandparentnode]"/&gt;
  </code></pre>
  
  <p>But neither works.</p>
  
  <p>The level of the grandparent node is not fixed, so I figure I can't use [@level=#] either. Any ideas on how to select it would be greatly appreciated.</p>
  
  <p><strong>EDIT: -- This part has been posted as a new question:</strong></p>
  
  <p><a href="https://stackoverflow.com/questions/3687466/xslt-select-grandparent-node-depending-on-an-attribute-value-of-its-grandchild-no">xslt select grandparent node depending on an attribute value of its grandchild node</a></p>
  
  <p>Selecting the node using the suggestions from below worked. Thanks! However I also need to test by the attribute of the grandparent or grandchild node. </p>
  
  <p>I've tried:</p>
  
  <pre><code>&lt;xsl:template name"one" match="grandparentnode"&gt;
   &lt;Tag1&gt;
    &lt;xsl:apply-templates select="parentNode" /&gt;
   &lt;/Tag1&gt;
  &lt;/xsl:template&gt;
  
  &lt;xsl:template name="two" match="grandparentnode[*/*/@grandchildattr='attrValue']"&gt;
   &lt;Tag2&gt;
       &lt;xsl:apply-templates select="parentNode" /&gt;
   &lt;/Tag2&gt;
  &lt;/xsl:template&gt;
  </code></pre>
  
  <p>However template "two" always gets called, and "" is always inserted. Even for grandchild nodes whose attribute value is not equal to 'attrValue'.</p>
  
  <p>Am I missing something here?</p>