Here is an representation of the XML file I am working with:
<root>
<header>
...
</header>
<pupils>
<pupil>
<name>Chris</name>
<assessments>
<stage>
<level>1</level>
<assessment>
<year>2012</year>
<result>55</result>
</assessment>
...
</stage>
</assessments>
</pupil>
...
</pupils>
</root>
Note: It is possible for a pupil to have ASSESSMENTs for LEVEL 1 but for a YEAR other than 2012.
I wish to select the pupils with a LEVEL 1 ASSESSMENT from YEAR 2012.
Therefore I would like to ask if the following “nested selector” method legitimate for selecting these pupils:
select="root/pupils/pupil[assessments/stage/level[../assessment/year = '2012'] = '1']"
(XsltCake does not return what I would expect)
My original attempt resulted in this:
select="root/pupils/pupil[assessments/stage/level = '1' and assessments/stage/assessment/year = '2012']"
However, because it is possible for a pupil to have an ASSESSMENT for LEVEL 1 but for a YEAR other than 2012 meanwhile having ASSESSMENTs for a different LEVEL in 2012, it would select those pupils too.
Assuming the the focus item for the XPATH expression is the document node, the the set of all pupil nodes what had a level 1 assessment in 2012 can be selected by this XPATH expression…
Caveat
This assumes that your data model is roughly as implied by your sample document. If you have some association between level and assessment, say based on adjacent nodes rather than common pupil node, then the expression would need to vary.
Also note, if you don’t want to make an assumption about what is the the current focus item, and the <root> element is the document root element, the precede the expression with a slash like so…
Example
For example, this XSLT 1.0 style-sheet…
…when applied to your sample document yields…
Principle
And yes, to answer your general question, predicates within XPATH expressions can be nested.