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

  • Home
  • SEARCH
  • 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 575845
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T13:59:01+00:00 2026-05-13T13:59:01+00:00

I’m trying to learn XPath, and I am having trouble with doing a nested

  • 0

I’m trying to learn XPath, and I am having trouble with doing a nested search (using contains).

Specifically, I was given the following question:

There is a list of authors, and a list of books, according to the following dtd:

<!ELEMENT db1 (book*, author*)>
<!ELEMENT book (title)>
<!ATTLIST book
    bid ID #REQUIRED
    authors IDREFS #REQUIRED
>
<!ELEMENT title (#PCDATA)>
<!ELEMENT author (#PCDATA)>
<!ATTLIST author
    aid ID #REQUIRED
>

Write an XPath expression that returns the number of authors who wrote books. It is possible to assume that there are no two author ids that contain one another.

I tried many things, but I keep getting an error of “Too many items in contains”.
I am trying to run something like this:

//author/@aid[contains(//book/@authors/string(.),  string(.))]

I am using the following xml file as an example:

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE db1 SYSTEM "C:\blabla\db1.dtd">
<db1>
<book authors="a1 a3 a4" bid="b1">
<title>Book 1</title>
</book>
<book authors="a1 a2 a3" bid="b2">
<title>Book 2</title>
</book>
<book authors="a4" bid="b3">
<title>Book 3</title>
</book>
<author aid="a1"></author>
<author aid="a91"></author>
<author aid="a2"></author>
<author aid="a88"></author>
<author aid="a3"></author>
<author aid="a4"></author>
<author aid="a5"></author>
<author aid="a6"></author>

</db1>

The expected answer should be

a1 a2 a3 a4

Any advice?

Thanks.

  • 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-05-13T13:59:01+00:00Added an answer on May 13, 2026 at 1:59 pm

    I found the answer I was looking for. It is not that difficult actually, it is just necessary to be familiar with the ‘id’ feature of XPath.

    The XPAth query for this is:
    count(id(//book/@authors))

    The list of authors could be given as id(//book/@authors). Notice that this xquery returns the full xml (and not the names only):

    <author aid="a1"/>
    <author aid="a2"/>
    <author aid="a3"/>
    <author aid="a4"/>
    

    See reference.

    The function contains is not applicable in this case, but luckily, it is also not really necessary.

    The id function selects elements by their unique ID. When the argument to id is of type node-set, then the result is the union of the result of applying id to the string-value of each of the nodes in the argument node-set. When the argument to id is of any other type, the argument is converted to a string as if by a call to the string function; the string is split into a whitespace-separated list of tokens (whitespace is any sequence of characters matching the production S); the result is a node-set containing the elements in the same document as the context node that have a unique ID equal to any of the tokens in the list.

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

Sidebar

Ask A Question

Stats

  • Questions 357k
  • Answers 357k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer The other answers are correct. Here is some code you… May 14, 2026 at 9:40 am
  • Editorial Team
    Editorial Team added an answer you ruin the noConflict concept by reassigning the jquery to… May 14, 2026 at 9:40 am
  • Editorial Team
    Editorial Team added an answer If you get that particular error, you don't actually have… May 14, 2026 at 9:40 am

Related Questions

No related questions found

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

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.