Digital humanities


Maintained by: David J. Birnbaum (djbpitt@gmail.com) [Creative Commons BY-NC-SA 3.0 Unported License] Last modified: 2017-02-24T13:50:40+0000


Test #4: XPath

Using Bad Hamlet, provide an XPath expression that retrieves:

  1. All speeches (<sp>) by Gertrude that contain Hamlet’s name. Requires, at least in our solution, contains(). (There are fifteen such speeches.)
  2. A comma-separated list of all unique speakers (<speaker>) in Act II, without duplicates. Requires, at least in our solution, string-join() and distinct-values().
  3. The number of speeches (<sp>) in each act (//body/div). Our solution requires count(). (The number of speeches you should find are 251 for Act 1, 201 for Act 2, 249 for Act 3, 179 for Act 4, and 257 for Act 5.)
  4. The speaker elements (<speaker>) for all speeches (<sp>) that are 200 characters long. Requires, at least in our solution, string-length(). Hint: to approach this in stages: 1) find all speeches; 2) filter them to keep just the ones that are equal to 200 characters; 3) find the speakers of those speeches. (There are two such speeches, one by Hamlet and one by First Clown.)