|Atomik Roundtrip 2.1: Tutorials||<< >>|
In this tutorial, you will learn how to create some more complex rulesets, allowing for rules to be applied only under certain conditions.
In the ruleset which you created in Tutorial 3 you applied rules globally to all elements with a particular name. However, your XML may be structured in such a way that you have identically named elements in different contexts : which you may want to present differently. For example, you may have XML that contains article elements, each of which has a ‘Title’ element and multiple book references, each of which also contains a ‘Title’ element. The difference between these elements is that one is the title of the article, the other is the title of a reference work referred to in the article. Under most circumstances, the styling of these would be very different.
You may also find that the meaning of your XML is differentiated by the contents of an attribute specified on the XML, rather than the element name. This tutorial will enable you to create rulesets which cater for both of these circumstances. It will also introduce you to Roundtrip’s Unicode and character entity support.
The objective of this tutorial is to show how Roundtrip’s rulesets can be made more flexible, allowing for a wider range of XML formats to be imported into QuarkXPress and styled appropriately.
Note: The tutorials we’ve looked at so far use XML which is fairly simple in its structure. The XML which we are going to look at in this tutorial is a bit more complex; and consequently this tutorial requires a basic understanding of XML hierarchies. If you are new to XML, you may want to take a look at ‘A brief guide to XML’ later in this manual before proceeding with this tutorial.
The XML which you shall be using in this tutorial is different, and more complex, from that used in the previous articles. This XML is for a scientific journal publication. In the magazine XML from tutorials 1 through 4, each element type was unique - a ‘GameTitle’ was always the title of a review, and would always be styled in the same way in QuarkXPress.
You can look at the XML file using any application which can read text files; such as Simple Text, BBEdit, Notepad, Microsoft Word, TextPad etc. However, you should take care not to save the XML file once you’ve taken a look at it, as some of these applications will save the file in their own format, not as a text file : and an XML file needs to be saved as a text file for Atomik Roundtrip (or indeed any other XML-aware application) to be able to read it.
<P>Umpteen XMLs lamely arose from two well-styled <Emphasis Style="Bold">Imports</Emphasis>, although multitudinous very stupendous XMLs slightly quickly bought Captain Reeder, but a very well-styled Klingon fell over two stupendous DTDS, then one hatstand mostly annoyingly bought umpteen Jabberwockies. Multitudinous hatstands towed one lampstand, even though Ermintrude slightly cleverly tickled multitudinous Imports. Umpteen Rulesets comfortably marries one XML, yet two easy-to-use Imports ran away, and umpteen structures cleverly tickled Santa Claus.</P>
The element which is particularly interesting here is the ‘Emphasis’ element. This is an element which contains an attribute ‘Style’, which has a value of ‘Bold’. If you look further through the XML, you’ll see other instances of the Emphasis element, with different values for their Style attributes (‘Italic’, for example).
<!-- XML note -->
Attributes are a special type of content within an XML file, known as ‘metadata’. Essentially this is information about the content, rather than actual content.
Attributes appear inside the tag of an element, for example:
<emph type=”bold”>This text is emboldened</emph>
It’s possible to have multiple attributes applied to the same element:
<Article section=”News” pub=”Easy_Journal” issue=”67”> ...</Article>
You can make a new rule based on an existing rule simply by selecting the existing rule, and then selecting the element to which you wish to apply the new rule in the ‘Element’ pop-up menu.
<!ELEMENT Emphasis (#PCDATA | Emphasis | Email | URL | List | FigRef | Ref)*>
<!ATTLIST Emphasis Style CDATA #IMPLIED>
The rule which we’re defining will apply to any ‘Emphasis’ elements which have an attribute of ‘Style’ with a value of ‘Bold’.
Now we’ve defined when the rule is going to be applied, we also need to add some styling information to make this rule actually do something.
Ensure that the ‘Merge’ radio button is selected. This means that this rule will add ‘Bold’ styling to the current paragraph or character style, whatever that might be.
If, for example, the current paragraph style defined the text as being underlined, having this rule defined as ‘Merge’ would mean that any Emphasis elements inserted would have both underlined (inherited from the underlying paragraph style sheet) and bold (applied by this rule) styling set.
If instead you set the radio button to ‘Set’, this will apply only bold styling, and will cancel out any existing styling which had been set by the underlying paragraph (or indeed character) style sheet.
If you take another look at the XML we’re using in this tutorial, you’ll see that there are several different elements called ‘Title’.
The first of these is the title of the article. The next instance of a ‘Title’ element is within a ‘Section’ - which is a child element of the article. In this case, the ‘Title’ element is the title of this section, and will need to be styled differently in QuarkXPress - otherwise it would look like the start of a new article, rather than a subheading of a section within the current article.
The final appearance highlighted in the palette is from the references section of the article. Here the ‘Title’ element is the title of a reference work which is referred to within the article, and again this must be styled differently to the other instances.
If you take a look at the image on the next page, this shows the same XML laid out on the QuarkXPress page, with the same elements circled - you can see here that the styling on all of these ‘Title’ elements needs to be different. This is what we’re going to do next.
18. Now try dragging the ‘Body’ element to the large 2 column text box at the bottom of the page. If you scroll down to the second page of the article, you’ll see that things are not looking so good here.
19. Now drag & drop the ‘References’ element into the blank space at the end of the article. This will look incorrect - the titles of the books referred to in the references are styled using the same style sheet which has been applied to the title of the article - certainly not how you’d want your references section to be styled.
You can see how the document should be styled by taking a look at the document ‘Easy_Journal_Finished.qxp’ inside the Tutorials folder.
You can see from looking at the ruleset palette that the ruleset is instructing Atomik Roundtrip to style all instances of the ‘Title’ element as if they were the title of an article. However as we’ve already seen that for this XML file this is not appropriate as the ‘Title’ element needs to be styled differently when it appears in different contexts within the XML hierarchy.
When a ‘Title’ appears in the ‘Head’ section of the XML, it is the title of the article, but when a ‘Title’ appears as part of a section, it is a section subheading. Similarly, when a ‘Title’ appears in the references section, it is as the title of a reference publication. These all need quite different styling in QuarkXPress.
In previous tutorials, when we’ve created different rules for styling text differently, the XML element to which we’ve applied those rules has always been different, but in this case the name of the XML element is the same. There is a special type of rule within Roundtrip rulesets to account for this eventuality - a ‘contextual’ rule.
Now, this rule will only be applied to ‘Title’ elements which are a child of the ‘Head’ element: this means that only ‘Title’ elements which are in the heading of the article will be styled up as article titles.
With only this rule defined, other ‘Title’ elements in the XML, which were not child elements of a ‘Head’ element would simply inherit styling from their parent element.
You now have two rules, one which applies to all ‘Title’ elements, and one which applies only to ‘Title’ elements which are a child of ‘Head’.
Now you have a single rule - this will style the ‘Titles’ elements which are article titles correctly, and will not style other instances of the ‘Title’ element.
25. Look at the XML tab of the Atomik Roundtrip XML palette.
Control + click or
right click inside the palette and select ‘View as Matching Rule Names’. You will see that the ‘Title’ element which appears under ‘Head’ has been renamed - ‘Title1’ and the ‘Authors’ element beneath that has been renamed ‘Authors<Head’.
When importing XML with a ruleset, Import can be set to refer to elements by the name of the rule which they match, rather than the original element name in the Atomik Roundtrip XML palette. This means that if you have XML which has element names which are not user-friendly, these elements can be given a more approachable name which you will see in the interface (although the actual name of the elements within the XML file is not changed, so the validity and integrity of the XML is not compromised).
A rule can be given any name you like, really (so long as it doesn’t contain space characters). Roundtrip will suggest that all rules are named with the name of the element or elements to which they apply, but you can override this default setting by entering a different name in the ‘Rule Name’ box within the ruleset palette.
Note that the ‘descended from’ pop-up doesn’t necessarily refer to the immediate parent of the element. To match a ‘descended from’ rule, the element simply needs to be descended from the specified element at some point in the XML hierarchy.
Roundtrip will automatically have chosen the name ‘Title’ for this rule (as the previous ‘Title’ rule has now been deleted). This default name can be changed by entering a new name (ie. Title<References) in the ‘Rule Name’ box. Click ‘Save’ to save your changes. It’s a good idea to name your rules so that it is easier to identify which rule applies to which elements when you look at the ruleset palette in the future.
The ruleset can now handle the article title and titles of references, and import them onto the QuarkXPress page with different styling. You’ve just created a context sensitive rule - a rule which styles an element depending on it’s position in the XML hierarchy.
Now two of the different types of ‘Title’ element are correctly styled. However, you’ll notice that the two ‘Section’ elements now have no particular styling to pick them out - they are styled the same way as the surrounding text. So we now need to make rules for these elements.
If you take a look at the finished text, you’ll note that the two section titles are styled differently.
If you take a look at the XML, you will see that rather than being sibling elements, the two sections are nested one inside of the other. The important thing which helps to differentiate these sections is that both the ‘Section’ elements have an attribute set, and this attribute defines the level of the section.
<Title>A paragraph marries two XMLS</Title>
The extract from the XML above shows this attribute, (“Level=’1’”).
This makes it possible to distinguish between the different section levels, and apply different styling to titles contained within them, based on the value of this level attribute.
If the attribute were specified on the ‘Title’ element, which contains the text which needs to be differently styled, then you could simply make an attribute dependant rule for the ‘Title’ element, as we did earlier for the ‘Emphasis’ element. But this is not the case - in this circumstance, it is the ‘Title’ element’s parent, ‘Section’ to which the attribute is applied. This makes a lot more sense from an XML perspective, as it’s the whole of the section to which this attribute applies, rather than to one particular element, so it is quite logical that it should be applied to the ‘Section’ element.
What we need to do, therefore is to make a rule which is applied to any ‘Title’ elements which have a parent element of ‘Section’, and that ‘Section’ element has an attribute value of ‘Level=”1”’.
36. In the Ruleset palette, select the ‘Section’ element in the ‘Element’ pop-up menu. The first thing we want to do is to turn off all the styling controls, because we’re about to make a rule which, odd as this may seem, doesn’t actually do anything! Make sure that the pop-ups for ‘Paragraph Style’ and ‘Character Style’ are both set to ‘Not Set’, ‘Use Character Attributes’ and ‘Element is an Image’ are unchecked, and that the ‘Pre’ and ‘Post’ generated text fields are empty. Also ensure that ‘Is a Paragraph’ is unchecked.
You now have two rules added to the ruleset, one which will apply to any ‘Section’ elements which have a ‘Level’ attribute defined with a value of ‘1’ - and one which will apply to any ‘Section’ elements which have a ‘Level’ attribute defined with a value of ‘2’. But neither of these rules make any changes to the styling of the text.
In doing this, we’re saying that this rule will only apply to ‘Title’ elements which are descendents of elements which match the ‘Section Level 1’ rule - which means ‘Section’ elements with an attribute of ‘Level’ that has a value of ‘1’. This means that this rule will only be applied to ‘Title’ elements which are descended from a ‘Section’ element with an attribute of ‘Level=”1” ‘, so a title in a level 1 section will have the ‘06. Section Title 1’ stylesheet applied to it.
In this tutorial you have: