Use this pure XPath 2.0 expression:
/*/Guide
[for $gid in guideID
return ../GuideLang[guideID eq $gid and lname eq 'English']
]
/gname
This supposes that the nodes of the provided document fragment are children of the (not provided) top element of the (not provided) XML document.
This can be converted even to an XPath 1.0 expression (note that no // is used!):
/*/Guide
[guideID
=
../GuideLang[lname = 'English']/guideID
]
/gname
Update:
Just for the people that are surprized that the first expression above is pure XPath 2.0, here is a complete XSLT 2.0 - based verification:
<xsl:stylesheet version="2.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:xs="http://www.w3.org/2001/XMLSchema">
<xsl:output omit-xml-declaration="yes" indent="yes"/>
<xsl:template match="/*">
<xsl:sequence select=
"/*/Guide
[for $gid in guideID
return ../GuideLang[guideID eq $gid and lname eq 'English']
]
/gname
"/>
</xsl:template>
</xsl:stylesheet>
when this XSLT 2.0 transformation is applied on the following document (the provided fragment, wrapped into a top element):
<t>
<GuideLang>
<guideID>1</guideID>
<lname>English</lname>
</GuideLang>
<GuideLang>
<guideID>2</guideID>
<lname>German</lname>
</GuideLang>
<GuideLang>
<guideID>3</guideID>
<lname>Swedish</lname>
</GuideLang>
<Guide>
<guideID>1</guideID>
<gname>John Smith</gname>
</Guide>
<Guide>
<guideID>2</guideID>
<gname>Weber Schneider</gname>
</Guide>
</t>
the XPath 2.0 expression is evaluated and the correctly selected node is output:
<gname>John Smith</gname>