I think closest you can get the following:
//someparentpath//*[self::h3 or self::div[parent::li/parent::ul]]/somechildpath
However, as already mentioned in harpo, // does not allow them to be exactly equivalent, and I donβt think there is a way around this in one expression. Note: if you are working in XSLT, you can use several variable assignments to achieve what you are trying to do and avoid some of the redundancy:
<xsl:variable name="ppath" select="//someparentpath" /> <xsl:variable name="children" select="($ppath/h3 | $ppath/ul/div/li)/somechildpath" />
Note that the hypothetical expression you described is:
Permitted in XPath 2.0. This is simply not allowed in XPath 1.0 because 1.0 does not allow you to have expressions partially through the path.
source share