obdurodon / dh_course

Digital Humanities course site
GNU General Public License v3.0
20 stars 6 forks source link

Adding Values Between Functions #458

Closed Rober-Igtm closed 3 years ago

Rober-Igtm commented 4 years ago

I had some trouble with the second part of the Schematron test, in which we had to form a rule that stipulated each of the sonnet numbers be in consecutive order; in both the table of contents and body. As the test proscribed, I wanted the rule to take each sonnet number and have it be equal to its preceding sonnet number plus one. Here's what I wrote for this rule:

Sonnets in the table of contents must be in consecutive order! (I apologize for the poor formatting.) When put into XPath, the first function will find the number value of each sonnet in the table of contents, and the second function does the same, but with the preceding sonnet's number values plus one. They work out individually, and the rule is accepted by Schematron. However, when I purposefully break the rule in the document, and re-verify, nothing is reported. What exactly is going wrong here? Thank you!
djbpitt commented 4 years ago

@Rober-Igtm Concerning the formatting, look up how to format a code block, that is, a few consecutive lines of code. See https://help.github.com/en/github/writing-on-github/creating-and-highlighting-code-blocks.

Your Schematron rule is close. Here are some detials:

  1. You want to compare the current sonnet number not to any preceding sibling, but only to the immediately preceding sibling. preceding-sibling::sonnet is any preceding sibling <sonnet> (starting from the current context), but preceding-sibling::sonnet[1] is the first (closest) preceding <sonnet>.
  2. You want to find the first preceding sonnet starting from the current context. When you start your XPath expression with a double slash, you start from the document node, so you are asking for all preceding sibling <sonnet> elements of all sonnets in the document. That isn’t what you want; from each sonnet, you want only its preceding siblings. The default context is the particular <sonnet> you’ve just matched (assuming you’re matching <sonnet> elements), so you want a relative path from there, instead of an absolute path from the document node.
  3. You can get the number of the first preceding sonnet with (abbreviated path; you’ll need the full one) preceding-sibling::sonnet[1]/@n, so that value plus 1 is preceding-sibling::sonnet[1]/@n + 1.

Does this help?

Rober-Igtm commented 4 years ago

Ok, I understand the issue with the immediate preceding siblings now. Thank you!