Skip to content

Instantly share code, notes, and snippets.

@cmc333333
Created January 6, 2016 22:07
Show Gist options
  • Save cmc333333/d24d2f3b9b48b59de929 to your computer and use it in GitHub Desktop.
Save cmc333333/d24d2f3b9b48b59de929 to your computer and use it in GitHub Desktop.
+class AtfI50032(PreProcessorBase):
+ """478.103 contains a chunk of text which is meant to appear in a poster
+ and be easily copy-paste-able. Unfortunately, the XML post 2003 isn't
+ structured to contain all of the appropriate elements within the EXTRACT
+ associated with the poster. This PreProcessor moves these additional
+ elements back into the appropriate EXTRACT."""
+ MARKER = ("//SECTNO[contains(., '478.103')]/.." # In 478.103
+ # Look for a P with the appropriate key words
+ "/P[contains(., 'ATF I 5300.2') and contains(., 'shall state')]")
+
+ def transform(self, xml):
+ for p in xml.xpath(self.MARKER):
+ next_el = p.getnext()
+ to_move = []
+ while next_el is not None and next_el.tag != 'EXTRACT':
+ to_move.append(next_el)
+ next_el = next_el.getnext()
+ if next_el is not None:
+ extract = next_el
+ # reversed as we're inserting into the beginning
+ for xml_el in reversed(to_move):
+ extract.insert(0, xml_el)
+
+
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment