Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8399179
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T21:13:55+00:00 2026-06-09T21:13:55+00:00

Here is an representation of the XML file I am working with: <root> <header>

  • 0

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.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-09T21:13:57+00:00Added an answer on June 9, 2026 at 9:13 pm

    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…

    root/pupils/pupil[assessments/stage[level='1'][assessment/year='2012']]
    

    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…

    /root/pupils/pupil[assessments/stage[level='1'][assessment/year='2012']]
    

    Example

    For example, this XSLT 1.0 style-sheet…

    <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
    <xsl:output method="text"/>
    
    <xsl:template match="/">
    Set of all pupil nodes what had a level 1 assessment in 2012
    ------------------------------------------------------------- 
      <xsl:apply-templates select="root/pupils/pupil[assessments/stage[level='1'][assessment/year='2012']]"/>
    </xsl:template>
    
    <xsl:template match="pupil">
      <xsl:value-of select="concat(' ',name,'&#x0A;')" />
    </xsl:template>
    
    </xsl:stylesheet>
    

    …when applied to your sample document yields…

    Set of all pupil nodes what had a level 1 assessment in 2012
    ------------------------------------------------------------- 
       Chris
    

    Principle

    And yes, to answer your general question, predicates within XPATH expressions can be nested.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have XML files that are representation of a portion of HTML code. Those
Let's say we have the following XML document: <root> <options> ... </options> <children> <child
I'm trying to canonicalize the representation of some XML data by sorting each element's
I am using XSL to display an XML representation of an email message in
I've got a class that represents an XML file to be processed. I've created
I need to get the serialized XML representation of an object as a string.
I have a 2.4 MB XML file, an export from Microsoft Project (hey I'm
Here's a fictitious example of the problem I'm trying to solve. If I'm working
I have a huge xml file (1 Gig). I want to move some of
Here's a representation of my array: $arr [0] [code]='a code' [number]='a number' [1] [code]='a

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.