1. A computer program product, tangibly stored on a computer-readable storage device, comprising instructions operable to cause data processing apparatus to: display formatted content from a source document to a user; receive from the user an input selecting a portion of the displayed formatted content and identifying the selected portion as a logical record within the source document; generate from the selected portion one or more style definitions, each style definition defining a corresponding style in terms of one or more contiguous fields of the selected portion and in terms of one or more rules, each field being defined with a count of a specified number of occurrences of a respective unit of formatted content in the selected portion, each rule based on formatting values or content values or structure values that are associated with a respective unit of formatted content of at least one of the fields, each style definition matching the entire selected portion and configured to apply to multiple logical records of a target document, and wherein applying the style definition to the target document comprises (i) determining, for each field of the style definition, whether the specified number of occurrences of the field's respective content unit structure is present among the logical records of the target document and (ii) applying to the logical records of the target document formatting values or content values or structure values according to the rules of the style definition; present one or more samples that match a user-selected style definition, each sample having a boundary at a beginning and a boundary at an end of the sample; receive a user input to change a boundary of a first sample of the one or more samples presented to the user; use the changed boundary to redefine a style definition corresponding to the first sample; and use the changed boundary to generate a new style definition corresponding to the first sample.