XSLT 2.0 and XPath 2.0 Programmer's Reference, 4th Edition (213 page)

BOOK: XSLT 2.0 and XPath 2.0 Programmer's Reference, 4th Edition
9.43Mb size Format: txt, pdf, ePub

The
count
attribute defines which ancestor elements should be included. Usually, this is expressed as a union pattern, as in the example below:


   

      format=“1.1.1. ”

      level=“multiple”

      count=“chapter | section | clause”/>

   


The effect of the rules is that a composite sequence number will be formed containing one component number for each ancestor (or the element itself) that is a

,


, or

. If the structure is regular, so that chapters, sections, and clauses are neatly nested, each clause will be output preceded by a number such as 1.13.5, where 1 is the chapter number, 13 is the number of the section within the chapter, and 5 is the number of the clause within the section.

If the structure isn't regular, for example if there are sections that don't belong to a chapter, if there are clauses that have sections as siblings at the same level, or if there are sections nested within other sections, then the effects can be surprising, but a careful reading of the rules should explain what's going on.

A problem that sometimes occurs is that the numbering is context-sensitive. For example, within Chapter 1, clauses are numbered 1.2.3, but in Appendix A, they are numbered A.2.3. It's possible to achieve this effect by exploiting the fact that the format pattern is an attribute value template; for example, you could write:


   

          select=“if (ancestor::chapter)

                  then ‘1.1.1 ’

                  else ‘A.1.1 ’”/>

   

      format=“{$format}” level=“multiple”

      count=“appendix | chapter | section | clause”/>

   


This assumes that

elements are within a wrapper such as

, while

elements are similarly wrapped by

. If this isn't the case, for example, if the first

element has four

elements as its preceding siblings, then the first appendix will be numbered E. To solve this you will need to use two different

instructions for the two cases.

See Also

count()
function in Chapter 13 on page 733

position()
function in Chapter 13 on page 854

format-number()
function, in Chapter 7 on page 788


on page 298

xsl:otherwise

The

element is used within an

instruction to indicate the action that should be taken when none of the

conditions is satisfied.

Changes in 2.0

None.

Format


  

© 100 Vampire Novels 2015 - 2024    Contact for me [email protected]