Title: Ancestor-or-self issue at top level
Tags: xpath
Question: With the following XML, the top level is returning the nodes of all levels. There are no ancestors for the top level, so why am I getting it’s children? 

```XML
<?xml version="1.0" encoding="ISO-8859-1"?&gt;
<WBSs&gt;
<WBS GUID="2"&gt;
<Name&gt;work</Name&gt;
<WBSs&gt;
<WBS GUID="1"&gt;
<Name&gt;Wall</Name&gt;
<ParentWBS&gt;2</ParentWBS&gt;
</WBS&gt;
<WBS GUID="2"&gt;
<Name&gt;South Wall</Name&gt;
<ParentWBS&gt;2</ParentWBS&gt;
</WBS&gt;
<WBS GUID="3"&gt;
<Name&gt;North Wall</Name&gt;
<ParentWBS&gt;2</ParentWBS&gt;
</WBS&gt;
</WBSs&gt;
</WBS&gt; 
</WBSs&gt;
```

XPATH
Note: Apply template is on .//WBS

```<xsl:variable name="wbsCode" select=".//ancestor-or-sel181a:6c1c:918f:f3a4:2e8c:61d6:1a08:6b16WBS/@GUID[1]"/&gt;
```

Note: I have an xslt instruction immediately following the xpath expression to strinify the nodes and include ‘.’. 



Result

(539)825-8923

2.1

2.2

2.3

Desired result

2

2.1

2.2

2.3

XSLT 

```<xsl:variable name="WBS_ELEMENT_TABLE"&gt;
   <xsl:apply-templates select=".//WBS" mode="I_WBS_ELEMENT"&gt;
     <xsl:with-param name="ProjectId" select="$ProjectId"/&gt;
   </xsl:apply-templates&gt;
</xsl:variable&gt;

<xsl:template match="WBS" mode="I_WBS_ELEMENT"&gt;
   <xsl:param name="ProjectId"/&gt;

<xsl:variable name="wbsCode" select=".//ancestor-or-sel181a:6c1c:918f:f3a4:2e8c:61d6:1a08:6b16WBS/@GUID[1]"/&gt;

<xsl:variable name="temp2" select="string-join(($wbsCode), '.')"/&gt;

<WBS_ELEMENT&gt;
    <xsl:value-of select="$temp2"/&gt; 
</WBS_ELEMENT&gt;

</xsl:template&gt;
```

Comment: Instead of writing *Apply template is on...* and *I have an XSLT instruction immediately following...*, please just create include real code in an [mcve] that illustrates your problem.  Thanks.

Comment: Here's the relevant xslt code... sorry about that.

Comment: XSLT added above... sorry about that, it started out as an XPATH problem.

Here is the accepted answer: ```//``` means ```/descendant-or-sel181a:6c1c:918f:f3a4:2e8c:61d6:1a08:6b16node()/```, so ```//ancestor181a:6c1c:918f:f3a4:2e8c:61d6:1a08:6b16*``` means ```./descendant-or-sel181a:6c1c:918f:f3a4:2e8c:61d6:1a08:6b16node()/ancestor181a:6c1c:918f:f3a4:2e8c:61d6:1a08:6b16x``` which finds all ancestors of all descendants, i.e. everything.

Get out of that habit of using ```//``` without thinking about what it means!



{'source': 'StackExchangeDataset', 'subset': 'stackoverflow.com', 'metadata': {'AnswerCount': 1, 'CommentCount': 3, 'ContentLicense': 'CC BY-SA 3.0', 'CreationDate': '2017:00:12/09/17', 'FavoriteCount': None, 'PostTypeId': 1, 'Tags': '<xpath>', 'Title': 'Ancestor-or-self issue at top level', 'ViewCount': 296, 'id': 47725092, 'user_AboutMe': None, 'user_AccountId': 12380929.0, 'user_DisplayName': 'Jkoul', 'user_Reputation': 25.0, 'user_Views': 7.0, 'user_id': 9026588.0}}