Skip to content

Disallow leading space on prefix and trailing space on suffix #78

Open
fbennett opened this Issue Sep 23, 2011 · 3 comments

2 participants

@fbennett
Citation Style Language member

In the MLZ extended schema, I've introduced a constraint to disallow leading space on (most) prefixes and trailing space on (most) suffixes, as described in this post to an earlier xbiblio-devel thread and this followup.

This renders most (if not all) styles in the official repo invalid under this schema version, but it will prevent the issues flagged by Andrea in the thread from arising in the MLZ styles. Adjusting the main repo styles to satisfy this constraint would require a large (maybe prohibitively large) amount of work, but as Andrea noted, the resulting styles would be cleaner.

Anyway, here's the patch for reference:

commit bf62c155531bdad482a780f11be92abcf2948c4f
Author: Frank <biercenator@gmail.com>
Date:   Thu Sep 22 01:00:32 2011 +0000

    Treat unnecessary leading prefix and trailing suffix spaces as invalid.

diff --git a/csl.rnc b/csl.rnc
index 9020579..9514bac 100644
--- a/csl.rnc
+++ b/csl.rnc
@@ -255,6 +255,11 @@ div {

             (localized-terms? & localized-dates* & localized-options?)
         }
+
+    ## Strings for use in affixes
+    nospace-prefix = xsd:string { pattern = "([^ ].*)*" }
+    nospace-suffix = xsd:string { pattern = "(.*[^ ])*" }
+
     localized-terms = element cs:terms { (simple-term | compound-term)+ }
     term-attributes =
         (( attribute form { cs-term-forms }?,
@@ -307,7 +312,7 @@ div {
             font-formatting,
             delimiter,
             element cs:date-part {
-                affixes, text-case, font-formatting, (month | day | year)
+                date-affixes, text-case, font-formatting, (month | day | year)
             }+
         }

@@ -520,7 +525,7 @@ div {
     names =
         element cs:names {
             names-attributes,
-            ((name?, et-al?, institution?) & name-label*),
+            (name-label-before?, name?, et-al?, institution?, name-label-after?),
             substitute?
         }

@@ -554,8 +559,16 @@ div {
         }

     ## Similar to label as below, but inherits variable from <names> tag
-    name-label = element cs:label {
+    name-label-before = element cs:label {
                      attribute form { cs-term-forms }?,
+                     attribute prefix { nospace-prefix}?,
+                     attribute suffix { text }?,
+                     label-primitives
+                 }
+    name-label-after = element cs:label {
+                     attribute form { cs-term-forms }?,
+                     attribute prefix { text }?,
+                     attribute suffix { nospace-suffix }?,
                      label-primitives
                  }

@@ -636,7 +649,7 @@ div {
                 ## order, the relevant `date-part`-elements, and by applying formatting,
                 ## affixes on cs:date and cs:date-part.
                 element cs:date-part {
-                    affixes, text-case, font-formatting, (month | day | year)
+                    date-affixes, text-case, font-formatting, (month | day | year)
                 }+,
                 delimiter)),
             affixes,
@@ -740,11 +753,11 @@ div {
     label =
         element cs:label {
             label-primitives,
+            affixes,
             attribute variable { cs-numbers | "locator" | "page" },
             attribute form { "long" | "short" | "symbol" }?
         }
     label-primitives =
-        affixes,
         font-formatting,
         text-case,
         strip-periods,
@@ -1031,6 +1044,9 @@ div {
 ## Formatting attributes.
 div {
     affixes =
+        attribute prefix { nospace-prefix }?,
+        attribute suffix { nospace-suffix }?
+    date-affixes =
         attribute prefix { text }?,
         attribute suffix { text }?
     delimiter = attribute delimiter { text }?
@bdarcus
Citation Style Language member
bdarcus commented Sep 23, 2011

We first need to figure out if we want this constraint (I don't really have an opinion). I pinged Andrea to see what he thinks.

But if we do want to go here, it might be better to define named patterns of prefix-value and suffix-value (the "nospace" bit probably isn't needed). E.g. first change the schema to use the named patterns, then redefine them in your customization schema, and finally (if he adopt this) in the main csl.rnc schema.

@fbennett
Citation Style Language member

It could be cast more cleanly, for sure. I ended up using the nospace- descriptive prefix because some affixes need the current value of text (affixes on date-part, the inner suffix of a cs:names cs:label element that comes before a cs:name element, and the inner prefix of one that comes after). Casting a full set of explicitly named affixes with the four possible patterns would probably make it easier to follow.

@bdarcus
Citation Style Language member
bdarcus commented Sep 23, 2011

Casting a full set of explicitly named affixes with the four possible patterns would probably make it easier to follow.

And also makes it easier to maintain and evolve. It's common in schema design that all data-types get explicit named patterns for just this reason.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.