Log in

HCMC Journal

Converting Posts from the Old Blog

: Tracey El Hajj

Introduction

You can convert a post from the old post using the build_oldPost.xml ANT file.

To do so, open the ANT file, and press the red play button. You will be prompted to enter the URL of the post you want to convert. You can convert more than one post at a time by adding the multiple URLs separated by commas. Once done, press return or enter, and the build will proceed. If you enter one URL, the file will open in Oxygen once the build successfully completes. If you run more than one URL, only the last post built will open.

At that point, go into the converted post and make sure it is valid as per the project’s schema; validate the file, add and commit it to the repository, and lastly upload the new version of the site to the server if you have permission to do so—otherwise, your post will be pushed when an authorized user uploads a new version.

How the XSLT Works:

The old_to_new_post.xsl transformation uses two separate modes/passes to process the file and output it with a useful file name. The first pass, addNs, adds a namespace to the elements in the source file because it defaults to no (empty) namespace. The second, finalPass, is the one that cleans the file of all the unnecessary components, and makes sure that the final output aligns with the HCMC Journal standards, giving it a useful file name.

The first template that runs on addNs mode adds the namespace to elements, and applies templates to nodes and attributes, with the exception of @xmlns.

The template that runs on finalPass mode adds the necessary attributes to the root <article>, including visibility, date, author, and category(ies). It then adds the title of the article, applying templates to the rest of the components as necessary.

In this transformation, we get rid of attachments, line breaks that are not within paragraphs, and empty spans. We also replace straight apostrophes with curly ones.

The root template stores the article element with a namespace in a variable, and in another variable the file name—the title of the post, stripped of any non-alphabetical characters—to be used for naming the output/result-document. It then outputs the result document and stores it in the /posts directory, processing the sequence of the finalPass.

How the Build File Works:

First we get the old post using the URL you provide, in a target called getOldPost. Then, in tidyHtml, we clean the source HTML and prepare it for processing in the next steps. In this step, we only grab the <article> element, so we do not need to bother with the rest of the generated HTML.

The processPost target runs the clean XHMTL throught the old_to_new_post.xsl transformation as explained above, and produces a HCMC Journal updated post.

The next target, schematronValidateAll, validates the output. This target does not fail the build if the file is invalid, because we are anticipating some errors that were not automatically addressed, such as quotation marks.

The main target is buildPost, and it calls all of the other targets, then deletes the oldPostTemp directory that should not remain in the repo.

The default target is buildFiles, and it builds all the files that have been prompted (via the URL list provided).