Hi,
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.