Multipart numbering

All previous examples have worked at a single level – either at the same level as the current element, or at some level higher in the document. A single list of siblings is counted, and numbered as required. However, there may be a need to present numbers that include several counters. Formal documents in particular tend to include such numbers as '1.2.7.3' or 'A–6–iv'. This effect can of course be achieved using multiple Number elements, arranged in sequence:

<xsl:template match="title">
  <P><xsl:number count="chapter" .../>.
    <xsl:number count="section" ..."/>
    <apply-templates/>
  </P>
</xsl:template>

However, this approach can be quite clumsy when dealing with several levels. As an alternative approach, the Level attribute can be used to indicate what type of numbering is required. Previous examples have illustrated the default setting for this attribute, with numbering being applied at a 'single' level (the list of siblings, at whatever level in the hierarchy). By including the attribute, and giving it the value 'multiple', the behaviour of the other attributes is changed to support multi-part numbering.

In 'multiple' level mode, the list of ancestors for the current element is searched for all occurrences of each of the elements in the pattern. Searching does not cease at the first occurrence found. For example, in a document that contains Section elements containing embedded Section elements, both levels will be applicable. For each level in the ancestor list for which a match has been made, the previous siblings of that element that match the pattern are counted. In the Count attribute, all matching elements at each level are included:

<number level="multiple" count="chapter|section" ... />

Each separate count is finally formatted into a single string (see below).

Restricting the search

The From element has a more significant role in this scenario. Unlike single-level numbering, searching up the hierarchy of elements does not stop at the first match, and so a blocking mechanism can be useful. For example:

<number count="section" from="chapter" />


   <book>
     <section> <!-- NOT INCLUDED -->
       <chapter>
         <section> <!-- INCLUDED -->

Compound number formatting

The issue that arises at this point is exactly how the compound string is to be organized. By default, the separate counts are just appended to each other, which is rarely desired. Quite apart from lack of visual appeal, a number such as '1234' could be interpreted in a number of ways, from a single value to such combinations as 'section 34 of chapter 12' or 'section 234 of chapter 1'. Typically, multipart numbers contain separating punctuation, such as a full-point as in '12.34' and '123.4'. The Format attribute is used to specify such effects. The punctuation is simply inserted between tokens that represent each level (from left to right):

<number ... format="1.a" />

1.a

1.b

1.c

...

7.m

7.n

7.o

When there are more levels in a generated number than there are tokens in the attribute, the last token (and preceding punctuation) is assumed to repeat. From the example above, values such as '3.c', '9.f.b' and '12.z.d.m' are all possible.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset