Using XPath operator “//” aka “descendant-or-self” in XSLT

In my daily work as frontend developer at I do a lot of “programming” – is one of the things you need to master most. With the focus mainly set on closing tasks I have not had the time to test a – well nice to know thing with the “” XPath . Tonight I finally found out what had been a question in my mind for at long period:

The “//” (decendant-or-self) XPath operator: Can it be used relative inside a full XPath? Will it “search” from the Document top, or start where it is placed inside the XPath selector?

An example XML:

<?xml version="1.0" encoding="utf-8"?>

  <group type="frontEnd">
    <person name="Sten" />
  <group type="backend">
    <person name="Sten" />

The two XPaths

//person[@name='Sten'] – Returns a nodeset containing 2 elements

//group[@type="frontEnd"]//person[@name='Sten'] – Returns a nodeset containing only 1 element

So as you can see the first one looked from the root (/People) and anywhere inside the document. The second one had the “//” inside a XPath, which in made the “//” operator look from the spot it was and below.


Well, I just got a litle wiser as I learned that I actually can use the “//” operator inside XPath selectors.


Leave a Reply