Maintained by: David J. Birnbaum (djbpitt@gmail.com)
Last modified:
2023-04-07T15:22:18+0000
Your task is to write XSLT that will generate an SVG visualization from the Federalist papers. This
XML is modified from the Federalist
papers course project from fall 2021. Before you write a single angle
bracket, take a moment to do some exploratory document analysis and get a sense of
the structure of the XML. We’ll be working across all of the papers in the document,
looking for the <federalism>
element.
Your output visualization should be a bar graph that represents the number of
instances of <federalism>
in each paper. We
more fully outline our expectations below, under the section labeled Required tasks.
You should upload both your XSLT and the SVG output, and both should observe our usual file-naming conventions.
Avoid hard-coding magic numbers when it makes sense to use variables. Use your judgment here; as a guide:
Use variables when a value is used more than once, so that if you change it you have to make the change in only one place.
Use variables where they make your code more legible. A variable name may make the meaning of your code easier to understand than if you had used a literal number.
Your code should be well organized and commented. Use comments as a way to label subsections of your stylesheet (this is sometimes called signposting) and help yourself and potential readers navigate the document. Code comments should be insightful and meaningful; imagine you are working on a course project and you need to ensure that your teammates understand you code!
There are many ways to approach this task that will result in an attractive,
well communicated visualization. Your solution doesn’t have to be the same
as ours, but it should follow good XSLT practice. Use push processing
(<xsl:apply-templates>
and
<xsl:template>
) and pull processing
(<xsl:for-each>
,
<xsl:value-of>
) appropriately. As a
general guideline, use push for elements, pull for atomic values (strings
and numbers), and whichever you find clearer for attributes.
Both your XSLT and SVG output must be valid. Run the transformation as you go, save the output, and open it in <oXygen/> to make sure it’s valid. Valid XSLT and valid SVG are baseline requirements for all XML-related development, and therefore worth a lot of points on the test.
At a minimum, your XSLT should produce SVG output with the following features:
A title that accurately describes the visualization.
X and Y axes with appropriate labels.
One bar for every paper in the document (there are 12) with uniform widths
and equal space between bars. Bar heights should accurately reflect the raw
count of the instances of
<federalism>
within that
paper.
Bars should have an appropriate label; that could be the number assigned to the paper and/or its subtitle.
There should be some means to determine how numerical values map onto bar heights. Two common methods are horizontal ruling lines and writing the value as text above each bar, as we did in SVG assignment #2. There’s nothing wrong with doing both!
The raw count of <federalism>
elements is less helpful as a measure of the federalism-related content in
the document than it would seem at first glance because some of those
elements have a lot of content and others have very little. Rather than
counting instances of the
<federalism>
element, we can find
the number of characters in those elements using
string-length()
. There will still be a
bar for each paper, but their heights will reflect the total character count
of that paper’s <federalism>
descendants.
You don’t want your character count to be thrown off by newlines and leading
space characters that were created by pretty-printing, though. You can
adjust for that by applying the
normalize-space()
function to the
<federalism>
element before
performing the character count.
By default, XSLT processes elements in document order and the
<paper>
elements in the document are
ordered according to their paper number, which is encoded in their
@no
attribute. This means that if you
don’t say otherwise, the bars will be rendered according to the paper
number. That’s a reasonable way to arrange the data, but you could instead
arrange it so that the tallest bar appears first, then the next tallest bar,
etc. You can implement that ordered by using
<xsl:sort>
.
Add some styling! Adjust the color of your elements, font sizes, stroke widths, etc. to create a more visually pleasing graphic. Style should help communicate meaning. We like to make the title the largest text in our graphics, for example, in order to communicate importance.