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 8538665
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T11:10:30+00:00 2026-06-11T11:10:30+00:00

Please consider the following XML– <div id=test> <p> Text sihdfaif</p> <p /> <p> Text

  • 0

Please consider the following XML–

<div id="test">
    <p> Text sihdfaif</p>
    <p />
    <p> Text sihdfaif</p>
    <p />
    <p> Text sihdfaif</p>
    <p> Text sihdfaif</p>
    <p> Text sihdfaif</p>
</div>

Now, I want to obtain the number of p elements that have some text within them.. in this case, that value=5 (there are 2 ‘p’ elements which are empty)

This is the XQuery that I came up with–

    let $claims_main := $doc//div[@id="test"]
        let $claims := $doc//div[@id="test"]/p
        let $n := count($claims)
        where $claims_main/p != '' 
        return $n

However the result that I get from the above is7, i.e. including the empty ‘p’ elements.

An alternative that I thought of, is using a for loop over all of the ‘p’ elements, but in that case how do I retrieve the total number of elements of the loop? If I use count in that case, then I simply get [1,1,1,1,1]- ie. count of each p element (since in the for loop the count would be for each of the ‘p’ elements, and not the div itself)…

  • 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-11T11:10:32+00:00Added an answer on June 11, 2026 at 11:10 am

    As the question asks specifically for “p elements that have some text within them”, here is how to get the number of precisely such p elements:

    count(/*/div/p[string(.)])
    

    This produces the number of all p elements with non-empty string value, that are children of a div that is a child of the top element of the XML document.

    In addition, if “non-empty” also means having non white-space-only string value:

    count(/*/div/p[normalize-space(.)])
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Please consider the following: DECLARE @xml XML SET @xml = '<Capture> <Data><DataType>Card Number</DataType><Value>1234567898765</Value></Data> <Data><DataType>Expiry
Please consider the following view: <p>Count <span data-bind=text: unreadCount()>&nbsp;</span></p> <div data-bind='template: { name: conversationTemplate,
I want to parse text from a xml file.Consider that I have a some
Please consider the following tweets table: tweet_id user_id text ---------------------------- 1 1 lorem ipsum
Please consider the following string $text = Dat foo 13.45 and $600 bar {baz:70}
I have an app that's about presenting fictional simplified cities. Please consider the following
Please consider following example: The source image consists of 6 areas that need to
Please consider following snippet: <div class=row> <div class=span12> <div class=control-group> <label class=control-label>Person Name</label> <div
Please consider the following URLs: http://www.mydomain.com/a/test.php https://www.mydomain.org/a/b/test.php http://www.mydomain.co.nr/a/b/c/test.php https://www.mydomain.com/a/b/c/d/test.php http://www.mydomain.co.uk/a/b/c/d/e/test.php https://www.mydomain.co.au.nm/a/b/c/d/e/f/test.php?var1=test1&var2=test2 Now I want
Please consider the following: <td style=width: 500px;> <div style=width: 400px;>SomeContent</div> </td> For some reason,

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.