xsl:number


The <xsl:number> element performs two functions. It can be used to allocate a sequential number to the current node, and it can be used to format a number for output. These functions are often performed together, but they can also be done separately.

Note that the facilities for number formatting in the <xsl:number> element are quite separate from those offered by the format-number() function and the <xsl:decimal-format> element.

Changes in 2.0

The select attribute has been added: This allows a node other than the context node to be numbered.

XSLT 2.0 defines error conditions that must be reported when incompatible attributes are used (for example, level and value cannot appear together). In XSLT 1.0, redundant attributes were silently ignored. XSLT 2.0 also defines the result of the instruction more precisely in corner cases, for example when there is no node that matches the from pattern.

New options have been added in XSLT 2.0 for formatting numbers as words (so you can output «Chapter Three » ) and as ordinal numbers (so you can output «Fit the First » or «3rd Act » ).

Format

 <xsl:number   value? =  expression  select? =  expression  level? = "single"  "multiple"  "any"   count? =  pattern  from? =  pattern  format? = {  string  }   lang? = {  nmtoken  }   letter-value? = { "alphabetic"  "traditional" }   ordinal? = {  string  }   grouping-separator? = {  char  }   grouping-size? = { number } /> 

Position

<xsl:number> is an instruction. It is always used within a sequence constructor.

Attributes

Name

Value

Meaning

value

optional

Expression

A user -supplied number to be formatted (instead of using a node sequence number)

select

optional

Expression

Selects the node whose sequence number is to be output (by default, the instruction numbers the context node)

level

optional

«single » «multiple » «any »

Controls the way in which a sequence number is allocated based on the position of the node in the tree

count

optional

Pattern

Determines which nodes are counted to determine a sequence number

from

optional

Pattern

Determines a cut-off point, a point in the document from which sequence numbering starts afresh

format

optional

Attribute value template, returning a format string, as defined below

Determines the output format of the number

lang

optional

Attribute value template, returning a language code, as defined in XML for the xml:lang attribute

Indicates a language whose conventions for number formatting should be used

letter-value

optional

Attribute value template, returning «alphabetic » «traditional »

Distinguishes between different numbering schemes used with the same language

ordinal

optional

Attribute value template, returning a string

If the attribute is present and is not a zero-length string, it indicates that ordinal numbering is required. For English, a suitable value is «yes » ; for inflected languages, it indicates the required ending, for example, «-o » or «-a » in Italian

grouping-separator

optional

Attribute value template, returning a single character

A character to be used to separate groups of digits (for example, a comma as a thousand separator)

grouping-size

optional

Attribute value template, returning a number

The number of digits in each group , indicating where the grouping-separator should be inserted

For the syntax of a pattern, see Chapter 6.

Content

None, the element is always empty.

Effect

The <xsl:number> instruction performs four tasks :

  1. Determines a sequence number. This is actually a sequence of integers (to allow section numbers such as 1.16.2); since it is not necessarily a number in the XPath sense, the specification refers to it as the place marker.

  2. Analyzes the format string into a sequence of format tokens.

  3. Formats each part of the place marker using the appropriate format token.

  4. Writes the resulting string to the current output destination as a text node.

These steps are considered individually in the following sections.

Determining a Sequence Number

If the value attribute is specified, the place marker is obtained by evaluating the expression in the value attribute and converting it to a sequence of integers. This is done by atomizing the sequence, calling the number() function for each value, then calling the round() function, and then casting to an integer. (This rather cumbersome procedure is chosen largely for backwards compatibility reasons.)

If backwards compatibility mode is in effect (that is, if the version attribute on the <xsl:stylesheet> element or on some other enclosing element is «1.0 » ), then all items in the sequence after the first are discarded. This is to emulate the behavior of XSLT 1.0.

If the value attribute is specified, the level , count , and from attributes must not be specified.

It is an error if any value in the sequence can't be converted to an integer, or produces an integer less than 1, because <xsl:number> is designed to handle positive integers. The XSLT processor may treat this error as fatal, or it may produce a fallback representation of the number, using the same conversion rules that apply to the string() function. The <xsl:number> element is designed for handling the natural numbers that arise from counting nodes, so if you want to handle other cases, it's better to use the format-number() function described in Chapter 7, on page 558.

If no value attribute is specified, <xsl:number> determines a place marker based on the position of a node in a source document. When the select attribute is present, the node to be numbered is determined by evaluating the expression contained in this attribute; a type error is reported if the result is anything other than a single node. If the select attribute is omitted, the instruction operates on the context node. In this case, an error is reported if the context item is not a node. Either way, we will refer to this node as the start node.

The rules for determining the place marker (always a sequence of positive integers) depend on the value of the level , count , and from attributes. If any of these attributes is omitted, the default is as follows :

Attribute

Default value

level

«single »

count

A pattern that matches nodes of the same kind as the start node, and with the same name as the start node if it has a name. As always, names with namespace prefixes are matched using the relevant namespace URI rather than the prefix

from

A pattern that matches the root node of the tree containing the selected node (that is, «/ » )

If the level attribute is «single » or «any » the place marker will normally contain a single integer; if it is «multiple » then it may contain several integers (for example «3.6.1 » ). It is also possible for the list to be empty.

The place marker is determined as follows:

level

Rules

single

This is designed for numbering peer nodes at the same level in the structure, for example the bullets in a list of bullets

First establish a target node. If the start node matches the count pattern, the target node is the start node (this is the normal case). Otherwise the target node is the innermost ancestor of the start node that matches the count pattern. If there is no such node, the place marker is an empty sequence

Now establish a boundary node. If the from pattern is defaulted, this is the root of the tree (this is by far the most common case: The from attribute is rarely used with «level=" single" ») . Otherwise, the boundary node is the start node if it matches the from pattern, else it is the innermost ancestor of the start node that matches the from pattern

If the target node is the boundary node, or is a descendant of the boundary node, the place marker is the number of preceding siblings of the target node that match the count pattern, plus one. For example, if the target node has six preceding siblings that match the count pattern then the sequence number is 7

If no target node is found, or if the target node is not a descendant-or-self of the boundary node, the place marker is an empty sequence

any

This is designed for numbering nodes that can appear at any level of the structure, for example the footnotes or equations in a chapter of a book

As a special case, if the start node is a document node, the place marker is an empty sequence

First form the set of countable nodes. This contains all nodes that can be reached from the start node using the ancestor, preceding, or self axes, provided that they match the count pattern

Now identify the boundary node. This is the last node (in document order) that can be reached from the start node using the ancestor, preceding, or self axes, and that matches the from pattern. If the from pattern was not specified, this will be the document node

Exclude from the set of countable nodes all those that are before the boundary node in document order

If there are no countable nodes, the place marker is an empty sequence; otherwise it is a single integer, equal to the number of countable nodes

multiple

This is designed to produce a composite sequence number that reflects the hierarchic position of a node, for example «2.17.1 »

First form the set of countable nodes. This contains all nodes that can be reached from the start node using the ancestor-or-self axis, and that match the count pattern

The boundary node is the same as with «level="single " »

For each countable node (taking them in document order, that is, outermost first) that has the boundary node on its ancestor-or-self axis, count how many preceding siblings it has that also match the count pattern, and add one for the node itself. The resulting sequence of integers makes up the composite place marker. It is possible for this sequence to be empty

These rules appear complex but in practice most common cases are quite straightforward, as the examples given later in this section demonstrate .

Analyzing the Format String

Once the place marker has been determined, the next stage is to format it into a string.

The place marker, as you have seen, is a list of zero or more positive integers.

The formatting is controlled primarily using the format string supplied in the format attribute. If this is omitted, the default value is «1 ».

The format string consists of a sequence of alternating formatting tokens and punctuation tokens. Any sequence of consecutive alphanumeric characters is taken as a formatting token, any other sequence is taken as a punctuation token. For example, if the format attribute is «1((a)) » , this is broken up into a formatting token «1 », a punctuation token «((» , a formatting token «a », and a punctuation token «)) » . The term alphanumeric is based on Unicode character categories, and is defined to include letters and digits from any language.

In the most common case the place marker is a single number. In this situation, the output string consists of the initial punctuation token if there is one, followed by the result of formatting the number using the first formatting token, and then the final punctuation token if there is one. So if the place marker is «42 » and the format attribute is «[ 1] » , then the final output is «[42] » .

Where the place marker is a list of numbers, the rules are a little more complex but still have intuitive results, for example if the list of numbers is «3,1, 6 » and the format attribute is «1.1 (a) » then the final output is «3. 1 (f) » (because «f » is the sixth letter in the alphabet). The detailed rules are as follows:

  • The n th formatting token is used to format the nth number in the list where possible, using the rules in the following section.

  • If there are more numbers in the list than formatting tokens, then the excess numbers are formatted using the last formatting token. For example, if the list is «3, 1, 2, 5 » and the format attribute is «A. 1 » , then the output will be «C.1.2.5 ».

  • If there are no formatting tokens, then a formatting token of «1 » is used.

  • If there are more formatting tokens than numbers in the list, the excess formatting tokens are ignored.

  • Each number is preceded in the output by the punctuation token that precedes the formatting token used to format this number, if there is one. If there is no preceding punctuation token, and the number is not the first in the list, it is preceded by «. » .

  • If the formatting string ends with a punctuation token, this is added to the end of the output string.

Note that if the place marker is an empty sequence, the result will consist of the initial and final punctuation tokens. For example if the format string is «[1] » , an empty sequence will be formatted as «[] » . The most likely reason for an empty sequence is that no nodes matched the count pattern.

Formatting the Numbers

This section describes how a single number is formatted using a single formatting token to construct a string that will form part of the final output string.

The XSLT specification defines this process only partially. There are some definitive rules, some guidance for the implementor, and many other cases that are left unspecified.

The definitive cases are listed in the table below:

Formatting token

Output sequence

1

1, 2, 3, 4, ...

01

01, 02, 03,..., 10, 11, 12, ...

More generally , if the format token is «1 » preceded by n zeros, the output numbers will be in decimal notation with a minimum of n + 1 digits

other Unicode digits

The above two rules also apply to any other Unicode digits equivalent to 0 and 1, for example Thai or Tamil digits. The number is output using the same family of digits as is used in the formatting token

a

a, b, c, d, . . . , x, y, z, aa, ab, ac,...

A

A, B, C, D,..., X, Y, Z, AA, AB, AC,...

i

i, ii, iii, iv,..., x, xi, xii, xiii, xiv, . ..

I

I, II, III, IV, ..., X, XI, XII, XIII, XIV,...

w

one, two, three,... ten, eleven (in the chosen language)

W

ONE, TWO, THREE (in the chosen language)

Ww

One, Two, Three (in the chosen language)

The specification doesn't define these sequences in detail, for example it doesn't say how you represent numbers above 1,000 in roman numerals (the Romans themselves had various conventions, such as putting horizontal lines above the letters, or boxes around them-effects that would be difficult to achieve in XML output). The specification does say, however, that if the number is too large to be formatted as requested , it should be output as if the formatting token were «1 » .

The attributes grouping-separator and grouping-size can be used to control the separation of groups of digits. For example, setting «grouping-separator=" " » (a single space) and «grouping-size=" 2 " » would cause the number 12345 to be output as «1 23 45 » . The groups will always be formed by counting digits from the right-hand side. If either of these attributes is specified, the other should also be specified.

The ordinal attribute allows you to request ordinal numbers rather than cardinal numbers. For example, with a formatting token of «1 » and language set (explicitly or by default) to «en » (English), the value «ordinal="yes" » would produce «1st, 2nd, 3rd, 4th » . With the formatting token «Ww » , it would produce «First, Second, Third, Fourth » . For languages other than English, the correct form of an ordinal number often depends on the noun it is qualifying. In the case of languages where this is simply done by changing the ending, the specification says that the value of the ordinal attribute should be the required ending, for example «ordinal="-e" » or «ordinal="-er" » in German. For other languages with more complicated rules, it's left to the implementer to sort out what to do.

For formatting tokens that aren't included in the table above, the XSLT specification is not prescriptive. It indicates that any formatting token may be used to indicate a sequence starting with this token, provided the implementation supports such a sequence; if the implementation does not support such a sequence, it may format the number using the formatting token «1 » . So, for example, if an implementation supports the numbering sequence « ± , , ³ , », you can invoke this sequence with a formatting token of « ± ».

In case the formatting token does not identify a numbering sequence unambiguously, two attributes are provided to give greater control:

  • The lang attribute is intended to indicate the target language: for example the sequence starting with a Cyrillic capital letter «A » (x0410 in Unicode) might be different for Russian («lang="ru" ») and for Bulgarian («lang="bg" ») . The language code is intended to take the same form as the xml: lang attribute defined in the XML specification.

    The most obvious case where this changes the output is for the formatting tokens such as «w » . For example, if «lang="de" » , the output for «w » would become «eins, zwei, drei » .

  • The letter-value attribute is intended for languages such as Hebrew that have several possible sequences starting with the same token. The two permitted values are «alphabetic » and «traditional » .

The detailed effect of these attributes is left entirely to the implementer, so you can't expect different products necessarily to behave in the same way. There has been a great deal of discussion on Internet mailing lists about the exact details of certain numbering sequences. With those sequences such as Roman numerals and Hebrew numbering that have a long history, practices have certainly varied at different times and places, so there is no single answer.

All the attributes controlling formatting are attribute value templates, so they can be parameterized using expressions enclosed in curly braces. This is mainly useful if you want to select the values from a localization file based on the preferred language of the current user. To achieve this, you can use the same techniques as described for localizing messages: see <xsl: message> on page 343.

Outputting the Number

The final action of <xsl: number> is to write the generated string to the current result sequence, as a text node.

The reason it is a text node rather than a string is historical: In XSLT 1.0, instructions always produced nodes. Changing it to a string in XSLT 2.0 would under some circumstances have caused it to be separated from adjacent values by a space character, giving a backwards compatibility problem. In practice, text nodes and strings are nearly always interchangeable.

If you want to do something else with the number (perhaps to write it as an attribute or to copy it to every page heading), you can save it as the value of a variable, as follows:

  <xsl:variable name="section-number" type="xs:string">   <xsl:number/>   </xsl:variable>  

Writing the value to a variable also allows you to perform further manipulation. For example, if you want to use the traditional numbering sequence for footnotes (*,   §) you cannot do this directly in <xsl: number> because these characters are punctuation symbols rather than alphanumerics. What you can do, however, is use conventional decimal numbering and then convert, for example:

  <xsl:template match="footnote">   <xsl:variable name="footnote-number">   <xsl:number level="any" from="section"/>   </xsl:variable>   <xsl:value-of select="translate($footnote-number, '12345', '*) " / >   </xsl:template>  

In practice it might be safer to use character references for these special characters to avoid them being mangled by a text editor that doesn't understand Unicode. The translate() function replaces characters in its second argument by the corresponding character in the third argument: It is described in Chapter 10 of XPath 2.0 Programmer's Reference .

I have dodged a tricky question here, which is that if you want footnote numbers to start at 1 on each page, you can't allocate them until you have paginated the document. Some kinds of numbering are really the domain of XSL Formatting rather than XSL Transformations.

Usage and Examples

Although the rules for <xsl: number> are very general and sometimes complex, most common cases are quite straightforward.

The general rules allow for numbering any kind of node, but in practice the <xsl: number> instruction is almost invariably used for numbering elements. So in this section, I'll assume that the selected node is an element.

level="single"

This option (the default) is used to number sibling elements.

The simplest way of using <xsl: number> is without any attributes:

  <xsl:number/>  

If the current element is the eighth <item> element owned by its parent element, say, this will write the text value «8 » to the current output destination. Technically, the processor is counting all the elements that match the pattern in the count attribute, and the default for the count attribute in this case is a pattern that matches <item> elements.

For this simple kind of numbering, it is often better to use the position() function, particularly if there are many nodes to be numbered. This is because with a typical implementation, each node that is numbered using <xsl: number> will result in the preceding siblings being counted, which will take an increasingly long time as the number of siblings increases . With the position() function, it is much more likely that the system already knows the position and doesn't have to do any special walking around the tree and pattern matching. Of course, this is only possible where «position() » and <xsl: number/> produce the same answer, which will happen when the sequence of nodes being processed using <xsl: apply-templates> or <xsl: for-each> consists of all the sibling elements of a particular element type.

Another option for numbering is to use the count() function, for example «count (preceding-sibling:: item) +1 » . This is often simpler if you want to use the number for further processing, rather than formatting it for output.

The count attribute of <xsl: number> can be used in two ways.

Firstly, it is useful if there are several different kinds of sibling elements that you want to count. For example, you might have an element containing a mixture of <item> and <special-item> children, as follows:

  <shopping-list>   <item>bananas</item>   <item>apples</item>   <special-item>flowers for Grandma</special-item>   <item>grapes</item>   <special-item>chocolate for Aunt Maud</special-item>   <item>cherries</item>   </shopping-list>  

If you want to number these in a single sequence, you can write:

  <xsl:template match="item  special-item">   <xsl:number count="item  special-item"/>   <xsl:text> </xsl:text>   <xsl:value-of select="."/><br/>   </xsl:template>  

which, when you process the <shopping-list> element, will result in the output:

  1 bananas<br/>   2 apples<br/>   3 flowers for Grandma<br/>   4 grapes<br/>   5 chocolate for Aunt Maud<br/>   6 cherries<br/>  

In this case you could also use «count=" *" » to achieve this effect. If you omitted the count attribute, the output would be:

  1 bananas<br/>   2 apples<br/>   1 flowers for Grandma<br/>   3 grapes<br/>   2 chocolate for Aunt Maud<br/>   4 cherries<br/>  

because each element is numbered taking into account only other elements with the same name.

Another use of the count attribute is to specify that it is not the context node that should be counted, but an ancestor node. For example, in the template rule for a <title> element you can use <xsl: number> to determine the number of the section that the title belongs to, by writing:

  <xsl:template match="title">   <xsl:number count="section"/>   . . .   </xsl:template>  

This usage is less common, and with XSLT 2.0 the select attribute gives more flexibility, because its value is an expression rather than a pattern. The above example can be written as:

  <xsl:template match="title">   <xsl:number select="parent::section"/>   . . .   </xsl:template>  

The select attribute is particularly handy when you want to construct a cross-reference to a node other than the context node. For example, if your document contains anchors with tags such as <bookmark name="biog"/> , and references to these anchors of the form <ref name="biog"/> , then your stylesheet might expand a reference as follows:

  <xsl:key name="bm" match="bookmark" select="@name"/>   <xsl:template match="ref">   <xsl:variable name="target" select="key('bm', @name)/ancestor::div"/>   <xsl:text>(See section </xsl:text>   <a href="{generate-id($target)}">   <xsl:number select="$target"/>   </a>   <xsl:text>)</xsl:text>]   . . .   </xsl:template>  

The from attribute is rarely needed with «level=" single" » . In fact, it's difficult to construct an example that isn't completely artificial.

If you want numbering to start at a value other than 1, or perhaps to proceed in increments other than 1, you can capture the result of <xsl: number> in a variable and manipulate it using XPath expressions.

For example, the following template rule numbers the items in a list starting at an offset passed in as a parameter:

  <xsl:template match="item">   <xsl:param name="first-number" select="1"/>   <xsl:variable name="number"><xsl:number/></xsl:variable>   <xsl:value-of select="$first-number + $number - 1"/>   . . .   </xsl:template>  

level="any"

This option is useful when numbering objects within a document that have a numbering sequence of their own, independent of their position within the hierarchic structure. Examples are figures and illustrations, tables, equations, footnotes, and actions from a meeting.

The count attribute can usually be defaulted. For example, to number quotations within a document, you can write a template rule such as:

  <xsl:template match="quotation">   <table><tr>   <td width="90%" valign="top">   <i><xsl:value-of select="."/></i></td>   <td><xsl:number level="any"/></td>   </tr></table>   </xsl:template>  

Again, the count attribute is useful when several different element types are included in the same numbering sequence, for example there might be a single sequence that includes both diagrams and photographs.

Note that each evaluation of <xsl: number> is quite independent of any previous evaluations. The result depends only on the relative position of the selected element in the source document, and not on how many times the <xsl: number> element has been evaluated. So there is no guarantee that the numbers in the output document will be consecutive. In fact, if the output order is different from the input order then the numbers definitely won't be consecutive. If you want to number things based on their position in the output document, you can often achieve this by using the position() function. If this isn't adequate, the alternative is to perform a second pass, to add the sequence numbers.

You can do this by writing the result of the first pass to a temporary tree. The following example extracts all the <glossary-item> elements from a document, sorts them alphabetically , and numbers them in their output sequence. The variable glossary is used to hold the temporary tree. To achieve the same effect with an XSLT 1.0 processor, you would need to use the vendor-specific node-set() extension function.

Imagine a source document that contains glossary definitions scattered throughout the document, in the form:

  <glossary-item>   <term>XML</term>   <definition>Extensible Markup Language</definition>   </glossary-item>  

The relevant template looks like this:

  <xsl:template name="make-glossary">   <xsl:variable name="glossary">   <xsl:for-each select="//glossary-item">   <xsl:sort select="term"/>   <xsl:copy-of select="."/>   </xsl:for-each>   </xsl:variable>   <table>   <xsl:for-each select="$glossary/glossary-item">   <tr>   <td><xsl:number format="[1]"/></td>   <td><xsl:value-of select="term"/></td>   <td><xsl:value-of select="definition"/></td>   </tr>   </xsl:for-each>   </table>   </xsl:template>  

In this example, however, the numbers could have been generated equally well on the first pass using the position() function.

The from attribute is useful for indicating where numbering should restart:

  <xsl:template match="footnote">   <xsl:number level="any" from="chapter"/>   <xsl:text> </xsl:text>   <xsl:value-of select="."/>   </xsl:template>  

The above code would number footnotes consecutively within a chapter, starting again at 1 for each chapter.

Numbering the Lines of a Poem
start example

The following example numbers the lines of a poem, showing the number to the right of every third line. Assume the input structure contains a <poem> element, a <stanza> element and a <line> element: The lines are to be numbered within the poem as a whole, not within each stanza.

Source

This stylesheet can be used with the source file poem. xml used in Chapter 1.

Stylesheet

This stylesheet is poem.xsl . It uses <xsl: number> to get the number of every line, but displays it only every third line, using the «mod » operator to get the remainder when the line number is divided by 3.

  <xsl:stylesheet version="1.0"   xmlns:xsl="http://www.w3.org/1999/XSL/Transform">   <xsl:template match="/">   <html><body>   <p><xsl:apply-templates select="/poem/stanza"/></p>   </body></html>   </xsl:template>   <xsl:template match="stanza">   <p><table><xsl:apply-templates/></table></p>   </xsl:template>   <xsl:template match="line''>   <tr>   <td width="350"><xsl:value-of select="."/></td>   <td width="50">   <xsl:variable name="line-nr">   <xsl:number level="any" from="poem"/>   </xsl:variable>   <xsl:if test="$line-nr mod 3 = 0">   <xsl:value-of select="$line-nr"/>   </xsl:if>   </td>   </tr>   </xsl:template>   </xsl:stylesheet>  

Output

See Figure 5-8

click to expand
Figure 5-8
end example
 

level="multiple"

This option is typically used to produce the hierarchic sequence numbers often found in technical or legal documents, for example 1.12.3, or A2(iii).

Note that an alternative way to produce such numbers is to use several calls on <xsl: number> with «level="single" » and different count attributes, for example:

  <xsl:number count="chapter"/>.<xsl:number count="section"/>   (<xsl:number count="clause"/>)  

Another technique, which might be marginally faster, is to evaluate the chapter number once and pass it as a parameter to the template handling the section, and then pass both the chapter number and section number (or their concatenation) as parameters to the template handling each clause.

However, using «level="multiple" » is convenient , and in some cases (particularly with recursive structures, where <section> elements are contained within <section> elements) may be the only way of achieving the required effect.

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

  <xsl:template match="clause">   <xsl:number   format="1.1.1. "   level="multiple"   count="chapter  section  clause"/>   <xsl:apply-templates/>   </xsl:template>  

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 <chapter> , <section> , or <clause> . 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 a regular chapter, clauses are numbered 1.2.3, but in an appendix, 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:

  <xsl:template match="clause">   <xsl:variable name="format"   select="if (ancestor::chapter)   then '1.1.1.'   else 'A.1.1 '"/>   <xsl:number   format="{$format}"   level="multiple"   count="appendix  chapter  section  clause"/>   <xsl:apply-templates/>   </xsl:template>  

See Also

  • count() function in XPath 2.0 Programmer's Reference, Chapter 10.

  • position() function in XPath 2.0 Programmer's Reference, Chapter 10.

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

  • <xsl:decimal-format> on page 251




XSLT 2.0 Programmer's Reference
NetBeansв„ў IDE Field Guide: Developing Desktop, Web, Enterprise, and Mobile Applications (2nd Edition)
ISBN: 764569090
EAN: 2147483647
Year: 2003
Pages: 324

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net