<?xml version="1.0" encoding="utf-8"?>
<?xml:stylesheet href="stylesheet/xml.dsl" type="text/dsssl"?>
<!-- $Id: WD-xsl-19980818.xml,v 1.1 1998/08/18 12:39:35 clilley Exp $ -->
<!DOCTYPE spec SYSTEM "xslspec.dtd" [
<!ENTITY XMLRec "http://www.w3.org/TR/REC-xml">
<!ENTITY XMLNames "http://www.w3.org/TR/WD-xml-names">
<!ENTITY year "1998">
<!ENTITY month "August">
<!ENTITY day "18">
<!ENTITY MMDD "0818">
<!ENTITY fo SYSTEM "fo.xml">
<!ENTITY D "DSSSL:">
<!ENTITY C "CSS:">
]>
<spec>
<header>
<title>Extensible Stylesheet Language (XSL)</title>
<version>Version 1.0</version>
<w3c-designation>WD-xsl-&year;&MMDD;</w3c-designation>
<w3c-doctype>World Wide Web Consortium Working Draft</w3c-doctype>
<pubdate><day>&day;</day><month>&month;</month><year>&year;</year></pubdate>
<publoc>
<loc href="http://www.w3.org/TR/&year;/WD-xsl-&year;&MMDD;"
          >http://www.w3.org/TR/&year;/WD-xsl-&year;&MMDD;</loc>
<loc href="http://www.w3.org/TR/&year;/WD-xsl-&year;&MMDD;.xml"
          >http://www.w3.org/TR/&year;/WD-xsl-&year;&MMDD;.xml</loc>
<loc href="http://www.w3.org/TR/&year;/WD-xsl-&year;&MMDD;.html"
          >http://www.w3.org/TR/&year;/WD-xsl-&year;&MMDD;.html</loc>
<loc href="http://www.w3.org/TR/&year;/WD-xsl-&year;&MMDD;.pdf"
          >http://www.w3.org/TR/&year;/WD-xsl-&year;&MMDD;.pdf</loc>
</publoc>
<latestloc>
<loc href="http://www.w3.org/TR/WD-xsl"
          >http://www.w3.org/TR/WD-xsl</loc>
</latestloc>
<authlist>
<author part="Tree Construction">
<name>James Clark</name>
<email href="mailto:jjc@jclark.com">jjc@jclark.com</email>
</author>
<author part="Formatting Objects">
<name>Stephen Deach</name>
<affiliation>Adobe</affiliation>
<email href="mailto:sdeach@adobe.com">sdeach@adobe.com</email>
</author>
</authlist>

<status>

<p>This is a W3C Working Draft for review by W3C members and other
interested parties. It is the first working draft of XSL.  It is based
on the <loc href="http://www.w3.org/TR/NOTE-xsl">XSL Submission</loc>,
but differs substantially in many important respects.  It is a draft
document and may be updated, replaced, or obsoleted by other documents
at any time.  The XSL Working Group will not allow early
implementation to constrain its ability to make changes to this
specification prior to final release.  It is inappropriate to use W3C
Working Drafts as reference material or to cite them as other than
<quote>work in progress</quote>. A list of current W3C working drafts
can be found at <loc
href="http://www.w3.org/TR">http://www.w3.org/TR</loc>.</p>

<p>Comments may be sent to <loc
href="mailto:xsl-editors@w3.org">xsl-editors@w3.org</loc>.  Public
discussion of XSL takes place on the <loc
href="http://www.mulberrytech.com/xsl/xsl-list/index.html">XSL-List</loc>
mailing list.</p>

</status>

<abstract>

<p>XSL is a language for expressing stylesheets.  It consists of two
parts:</p>

<olist>

<item><p>a language for transforming XML documents, and</p></item>

<item><p>an XML vocabulary for specifying formatting
semantics.</p></item>

</olist>

<p>An XSL stylesheet specifies the presentation of a class of XML
documents by describing how an instance of the class is transformed
into an XML document that uses the formatting vocabulary.</p>

</abstract>

<langusage>
<language id="EN">English</language>
<language id="ebnf">EBNF</language>
</langusage>
<revisiondesc>
<slist>
<sitem>See RCS log for revision history.</sitem>
</slist>
</revisiondesc>
</header>
<body>
<div1>
<head>Overview</head>

<p>XSL is a language for expressing stylesheets. Each stylesheet
describes rules for presenting a class of XML source documents. There
are two parts to the presentation process. First, the result tree is
constructed from the source tree. Second, the result tree is
interpreted to produce formatted output on a display, on paper, in
speech or onto other media.</p>

<p>The first part, constructing the result tree, is achieved by
associating patterns with templates.  A pattern is matched against
elements in the source tree.  A template is instantiated to create
part of the result tree.  The result tree is separate from the source
tree.  The structure of the result tree can be completely different
from the structure of the source tree. In constructing the result
tree, the source tree can be filtered and reordered, and arbitrary
structure can be added.</p>

<p>The second part, formatting, is achieved by using the formatting
vocabulary specified in this document to construct the result tree.
Formally, this vocabulary is an XML namespace.  Each element type in the
vocabulary corresponds to a formatting object class. A formatting
object class represents a particular kind of formatting behavior. For
example, the block formatting object class represents the breaking of
the content of a paragraph into lines.  Each attribute in the
vocabulary corresponds to a formatting property.  A formatting object
class has a specific set of formatting properties which provide finer
control over the behavior of the formatting object class; for example,
controlling indenting of lines, spacing between lines, and spacing
before and after the collection of lines.  A formatting object can
have content, and its formatting behavior is applied to its
content.</p>

<p>XSL does not require result trees to use the formatting vocabulary
and thus can be used for general XML transformations.  For example,
XSL can be used to transform XML to <quote>well-formed</quote> HTML,
that is, XML that uses the element types and attributes defined by
HTML.</p>

<p>When the result tree uses the formatting vocabulary, a conforming
XSL implementation must be able to interpret the result tree according
to the semantics of the formatting vocabulary as defined in this
document; it may also be able to externalize the result tree as XML,
but it is not required to be able to do so.</p>

</div1>

<div1>
<head>Tree Construction</head>

<div2>
<head>Overview</head>

<p>A stylesheet contains a set of template rules.  A 
template rule has two parts: a pattern which is matched against nodes
in the source tree and a template which can be instantiated
to form part of the result tree.  This allows a stylesheet to be applicable to
a wide class of documents that have similar source tree
structures.</p>

<p>A template is instantiated for a particular source element
to create part of the result tree. A template can contain elements
that specify literal result element structure.  A template can also
contain elements that are instructions for creating result tree
fragments.  When a template is instantiated, each instruction is
executed and replaced by the result tree fragment that it creates.
Instructions can select and process descendant elements.  Processing a
descendant element creates a result tree fragment by finding the
applicable template rule and instantiating its template. Note
that elements are only processed when they have been selected by the
execution of an instruction.  The result tree is constructed by
finding the template rule for the root node and instantiating
its template.</p>

<p>In the process of finding the applicable template rule, more
than one template rule may have a pattern that matches a given
element. However, only one template rule will be applied. The
method for deciding which template rule to apply is described
in <specref ref="conflict"/>.</p>

<p>XSL uses XML namespaces <bibref ref="XMLNAMES"/> to distinguish
elements that are instructions to the XSL processor from elements that
specify literal result tree structure.  Instruction elements all
belong to the XSL namespace.  The examples in this document use a
prefix of <code>xsl:</code> for elements in the XSL namespace.</p>

<p>An XSL stylesheet contains an <code>xsl:stylesheet</code> document
element.  This element may contain <code>xsl:template</code> elements
specifying template rules, which will be described later in
this document.</p>

<p>The following is an example of a simple XSL stylesheet that
constructs a result tree for a sequence of <code>para</code> elements
containing <code>emphasis</code> elements.  The
<code>result-ns="fo"</code> attribute indicates that a tree using the
formatting object vocabulary is being constructed. The rule for the
root node specifies the use of a page sequence formatted with any font
with serifs. The <code>para</code> elements become <code>block</code>
formatting objects which are set in 10 point type with a 12 point
space before each block.</p>

<eg><![CDATA[<xsl:stylesheet
  xmlns:xsl="http://www.w3.org/TR/WD-xsl"
  xmlns:fo="http://www.w3.org/TR/WD-xsl/FO"
  result-ns="fo">
  <xsl:template match="/">
    <fo:page-sequence font-family="serif">
       <xsl:process-children/>
    </fo:page-sequence>
  </xsl:template>
  
  <xsl:template match="para">
    <fo:block font-size="10pt" space-before="12pt">
      <xsl:process-children/>
    </fo:block>
  </xsl:template>
</xsl:stylesheet>]]></eg>

<p>The <code>xsl:stylesheet</code> element can also contain elements
importing other XSL stylesheets, elements defining macros, elements
defining global constants, and elements identifying source attributes
as individual element identifiers.</p>

</div2>

<div2>
<head>Stylesheet Structure</head>

<p>A stylesheet is represented by an <code>xsl:stylesheet</code>
element in an XML document.</p>

<p>XSL processors must use the XML namespaces mechanism <bibref
ref="XMLNAMES"/> for both source documents and stylesheets.  All XSL
defined elements, that is those specified in this document with a
prefix of <code>xsl:</code>, will only be recognized by the XSL
processor if they belong to a namespace with the URI
<code>http://www.w3.org/TR/WD-xsl</code>; XSL defined elements are
recognized only in the stylesheet not in the source document.</p>

<issue id="issue-versioning"><p>Should there be some way for a
stylesheet to indicate which version of XSL it conforms to?  Can this
be done through the URI of the XSL namespace?</p></issue>

<p>The <code>xsl:stylesheet</code> element has an optional
<code>result-ns</code> attribute; the value must be a namespace
prefix.  If this attribute is specified, all result elements must
belong to the namespace identified by this prefix.  If there is a
namespace declared as the default namespace, then an empty string may
be used as the value to specify that all result elements belong to
that namespace. If the <code>result-ns</code> attribute specifies the
XSL Formatting Objects namespace, then in addition to constructing the
result XML tree, the XSL processor must interpret it according to the
semantics defined in this document.  The XSL Formatting Objects
namespace has the URI <code>http://www.w3.org/TR/WD-xsl/FO</code>.
The examples in this document use the <code>fo:</code> prefix for this
namespace.</p>

<p>The <code>xsl:stylesheet</code> element may contain the following types
of elements:</p>
<olist>
<item><p><code>xsl:import</code></p></item>
<item><p><code>xsl:include</code></p></item>
<item><p><code>xsl:id</code></p></item>
<item><p><code>xsl:strip-space</code></p></item>
<item><p><code>xsl:preserve-space</code></p></item>
<item><p><code>xsl:define-macro</code></p></item>
<item><p><code>xsl:define-attribute-set</code></p></item>
<item><p><code>xsl:define-constant</code></p></item>
<item><p><code>xsl:template</code></p></item>
</olist>

<p>This example shows the structure of a stylesheet.  Ellipses
(<code>...</code>) indicate where attribute values or content have
been omitted.
Although this example shows one of each type of allowed element,
stylesheets may contain zero or more of each of these elements.</p>

<eg><![CDATA[<?xml version="1.0"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/TR/WD-xsl">
  <xsl:import href="..."/>

  <xsl:include href="..."/>

  <xsl:id attribute="..."/>

  <xsl:strip-space element="..."/>
  
  <xsl:preserve-space element="..."/>

  <xsl:define-macro name="...">
   ...
  </xsl:define-macro>

  <xsl:define-attribute-set name="...">
  ...
  </xsl:define-attribute-set>

  <xsl:define-constant name="..." value="..."/>

  <xsl:template match="...">
    ...
  </xsl:template>
</xsl:stylesheet>]]></eg>

<p>The order in which the children of the <code>xsl:stylesheet</code>
element occur is not significant except for <code>xsl:import</code>
elements and for error recovery.  Users are free to order the elements
as they prefer, and stylesheet creation tools need not provide control
over the order in which the elements occur.</p>

<issue id="issue-media-rule"><p>Should we provide the functionality
of CSS's <code>@media</code> rule and if so how?</p></issue>

</div2>

<div2>
<head>Processing Model</head>

<ednote><edtext>This needs expanding and polishing.</edtext></ednote>

<p>A node is processed to create a result tree fragment.  The
result tree is constructed by processing the root node.  A node is
processed by finding all the template rules with patterns that
match the node, and choosing the best amongst them.  The chosen rule's
template is then instantiated for the node.  <termdef
id="dt-current-node" term="Current Node">During the instantiation of
a template, the node for which the template is being
instantiated is called the current node.</termdef> A template
typically contains instructions that select an additional sequence of
source nodes for processing.  A sequence of source nodes is processed
by appending the result tree structure created by processing each of
the members of the sequence in order.  The process of matching,
instantiation and selection is continued recursively until no new
source nodes are selected for processing.</p>

<p>Implementations are free to process the source document in any way
that produces the same result as if it were processed using this
processing model.</p>

</div2>

<div2>
<head>Data Model</head>

<p>XSL operates on an XML document, whether a stylesheet or a source
document, as a tree.  Any two stylesheets or source documents that
have the same tree will be processed the same by XSL.  This section
describes how XSL models an XML document as a tree.  This model is
conceptual only and does not mandate any particular
implementation.</p>

<p>XML documents operated on by XSL must conform to the XML namespaces
specification <bibref ref="XMLNAMES"/>.</p>

<p>The tree contains nodes and character data.  There are three kinds
of node:</p>

<ulist>

<item><p>root nodes</p></item>

<item><p>element nodes</p></item>

<item><p>attribute nodes</p></item>

</ulist>

<issue id="issue-node-types"><p>We need to support at least processing
instructions and comments, possibly other node types as well.  Support
requires having patterns that match/select them, being able to get at
their contents, and being able to create them.  How should this
work?</p></issue>

<div3 id="root-node">
<head>Root Node</head>

<p>The root node is the root of the tree.  It does not occur anywhere
else in the tree.  It has a single child which is the element node for
the document element of the document.</p>

</div3>

<div3 id="element-nodes">
<head>Element Nodes</head>

<p>There is an element node for every element in the document.  An
element has an expanded name consisting of a local name and a possibly
null URI (see <bibref ref="XMLNAMES"/>); the URI will be null if the
element type name has no prefix and there is no default namespace in
scope.</p>

<p><termdef id="dt-namespace-prefix-map" term="Namespace Prefix
Map">An element node also has a <term>namespace prefix map</term> that
specifies the namespace URI for each namespace prefix that is in scope
for the element.</termdef> The semantics of a document type may treat
parts of attribute values or data content as namespace prefixes.  The
namespace prefix map ensures that the semantics can be preserved when
the tree is written out as XML.  When writing an element node out as
XML, an XSL processor must add sufficient namespace-declaring
attributes to the start-tag to ensure that all prefixes in the element
node's namespace prefix map are correctly declared.</p>

<p>The children of an element node are the element nodes and
characters for its content.  Entity references to both internal and
external entities are expanded.  Character references are
resolved.</p>

<p><termdef id="dt-descendants" term="Descendants">The
<term>descendants</term> of an element node are the character
children, the element node children, and the descendants of the
element node children.</termdef></p>

<p><termdef id="dt-document-order" term="Document Order">The set of
all element nodes in a document can be ordered according to the order
of the start-tags of the elements in the document; this is known as
<term>document order</term>.</termdef></p>

<div4 id="unique-id">
<head>Unique IDs</head>

<p>An element object may have a unique identifier (ID).  This is the
value of the attribute which is declared in the DTD as type
<code>ID</code>.  Since XSL must also work with XML documents that do
not have a DTD, stylesheets may specify which attributes in the source
document should be treated as IDs.  The <code>xsl:id</code> element
has a required <code>attribute</code> attribute, which gives the name
of an attribute in the source document that should be treated as
specifying the element's ID. A stylesheet may contain more than one
<code>xsl:id</code> element, for cases where the source document uses
several attributes as IDs.  An <code>xsl:id</code> element also has an
optional <code>element</code> attribute which specifies the name of an
element type; when the <code>element</code> attribute is specified,
then the <code>xsl:id</code> element specifies that the
<code>attribute</code> attribute of <code>element</code> elements are
treated as IDs.  <code>xsl:id</code> elements may only occur in the
stylesheet body (not within a rule).  The following causes XSL to
treat all <code>name</code> attributes in the source document as
IDs.</p>

<eg><![CDATA[<xsl:id attribute="name"/>]]></eg>

<p>It is an error if, as a consequence of the use of
<code>xsl:id</code>, there is more than one element with the same ID
in the source tree. An XSL processor may signal the error; if it does
not signal the error, it must recover by treating only the first (in
<termref def="dt-document-order">document order</termref>) of the
elements as having that ID.</p>

</div4>

<div4 id="base-uri">

<head>Base URI</head>

<p>An element node also has an associated URI called its base URI
which is used for resolving attribute values that represent relative
URIs into absolute URIs.  If an element occurs in an external entity,
the base URI of that element is the URI of the external entity.
Otherwise the base URI is the base URI of the document.</p>

</div4>

</div3>

<div3 id="attribute-nodes">
<head>Attribute Nodes</head>

<p>Each element node has an associated set of attribute nodes.  A
defaulted attribute is treated the same as a specified attribute.  If
an attribute was declared for the element type, but the default was
declared as <code>#IMPLIED</code>, and the attribute was not specified
on the element, then the element's attribute set does not contain a
node for the attribute.</p>

<p>An attribute node has an expanded name and has a string value.  The
expanded name consists of a local name and a possibly null URI (see
<bibref ref="XMLNAMES"/>); the URI will be null if the specified
attribute name did not have a prefix.  The value is the normalized
value as specified by the XML Recommendation <bibref ref="XML"/>.  An
attribute value whose value is of zero length is not treated
specially.</p>

<p>There are no attribute nodes for attributes that declare namespaces
(see <bibref ref="XMLNAMES"/>).</p>

<issue id="issue-external-dtd"><p>Should we specify something about
how we expect XSL processors to process external DTDs and parameter
entities?  For example, what happens if an attribute default is
declared in an external DTD?</p></issue>

</div3>

<div3>
<head>Character Data</head>

<p>Each character within a CDATA section is treated as character data.
Thus <code>&lt;![CDATA[&lt;]]&gt;</code> in the source document will
treated the same as <code>&amp;lt;</code>.  Characters inside comments
or processing instructions are not character data. Line-endings in
external entities are normalized to #xA as specified in the XML
Recommendation <bibref ref="XML"/>.</p>

</div3>

<div3 id="strip">
<head>Whitespace Stripping</head>

<p>After the tree has been constructed, but before it is otherwise
processed by XSL, some whitespace characters may be stripped.  The
stripping process takes as input a set of element types for which
whitespace must be preserved.  The stripping process is applied to
both stylesheets and source documents, but the set of
whitespace-preserving element types is determined differently for
stylesheets and for source documents.</p>

<p>A character object is preserved if any of the following apply:</p>

<ulist>

<item><p>The element type of the parent of the character is in the set
of whitespace-preserving element types.</p></item>

<item><p>It is part of a chunk that contains at least one
non-whitespace character.  As in XML, a whitespace character is #x20,
#x9, #xD or #xA.  A chunk of characters is a maximal sequence of
sibling characters without any intervening elements.</p></item>

<item><p>An ancestor element of the character has an
<code>xml:space</code> attribute with a value of
<code>preserve</code>, and no closer ancestor element has
<code>xml:space</code> with a value of
<code>default</code>.</p></item>

</ulist>

<p>Otherwise the character object is stripped.</p>

<p>The <code>xml:space</code> attributes are not stripped from the
tree.</p>

<note><p>This implies that if an <code>xml:space</code> attribute is
specified on a literal result element, it will be included in the
result.</p></note>

<p>For stylesheets, the set of whitespace-preserving element types
consists of just <code>xsl:text</code><!-- and <code>fo:text</code>-->.</p>

<!--<note><p><code>fo:text</code> is a formatting object that can contain
only characters.  Whereas characters outside <code>fo:text</code> are
subject to the XSL-defined whitespace-related formatting properties
(such as collapsing adjacent whitespace characters) in the same way as
characters in the source document, whitespace characters occurring in
<code>fo:text</code> will not be collapsed or stripped by the
formatter.</p></note>-->

<p>For source documents, the set of whitespace-preserving element
types is determined using the stylesheet as follows:</p>

<ulist>

<item><p>If the <code>xsl:stylesheet</code> element specifies a
<code>default-space</code> attribute with a value of
<code>strip</code>, then the set is initially empty.  Otherwise the
set initially contains all element types that occur in the
document.</p></item>

<item><p>The <code>xsl:strip-space</code> element causes an element
type to be removed from the set of whitespace-preserving element types.
The <code>element</code> attribute gives the name of the element
type.</p></item>

<item><p>The <code>xsl:preserve-space</code> element causes an element
type to be added to the set whitespace-preserving element types. The
<code>element</code> attribute gives the name of the element
type.</p></item>

</ulist>

<issue id="issue-declare-multiple-elements"><p>Should the value of the
<code>element</code> attribute of <code>xsl:strip-space</code>,
<code>xsl:preserve-space</code> and <code>xsl:id</code> be a list of
element type names (and thus be renamed to <code>elements</code>)?  If
so, should the <code>attribute</code> attribute of <code>xsl:id</code>
also be a list of attribute names?</p></issue>

<ednote><edtext>Clarify how these declarations interact with each
other and with xsl:import.</edtext></ednote>

<p>The <code>xsl:stylesheet</code> element can include an
<code>indent-result</code> attribute with values <code>yes</code> or
<code>no</code>.  If the stylesheet specifies
<code>indent-result="yes"</code>, then the XSL processor may add
whitespace to the result tree (possibly based on whitespace stripped
from either the source document or the stylesheet) in order to indent
the result nicely; if <code>indent-result="no"</code>, it must not add
any whitespace to the result.  When adding whitespace with
<code>indent-result="yes"</code>, the XSL processor can use any
algorithm provided that the result is the same as the result with
<code>indent-result="no"</code> after whitespace is stripped from both
using the process described with the set of whitespace-preserving
element types consisting of just <code>xsl:text</code><!-- and
<code>fo:text</code>-->.</p>

</div3>

</div2>

<div2>
<head>Template Rules</head>

<p>A template rule is specified with the <code>xsl:template</code>
element. The <code>match</code> attribute identifies the source node
or nodes to which the rule applies. The content of the
<code>xsl:template</code> element is the template.</p>

<p>For example, an XML document might contain:</p>

<eg><![CDATA[This is an <emph>important</emph> point.]]></eg>

<p>The following template rule matches elements of type
<code>emph</code> and has a template which produces a
<code>fo:sequence</code> formatting object with a
<code>font-weight</code> property of <code>bold</code>.</p>

<eg><![CDATA[<xsl:template match="emph">
  <fo:sequence font-weight="bold">
    <xsl:process-children/>
  </fo:sequence>
</xsl:template>
]]></eg>

<p>As described later, the <code>xsl:process-children</code> element
recursively processes the children of the source element.</p>

<div3 id="conflict">
<head>Conflict Resolution for Template Rules</head>

<p>It is possible for a source node to match more than one 
template rule. The template rule to be used is determined as
follows:</p>

<olist>

<item><p>First, all matching template rules that are less
<termref def="dt-important">important</termref> than the most
important matching template rule or rules are eliminated from
consideration.</p></item>

<item><p>Next, all matching template rules that are less
specific (as defined in <specref ref="specificity"/>) than the most
specific matching template rule or rules are eliminated from
consideration.</p></item>

<item><p>Next, all matching template rules that have a lower
priority than the matching template rule or rules with the
highest priority are eliminated from consideration.  The priority of a
rule is specified by the <code>priority</code> attribute on the rule.
The value of this must be an integer (positive or negative).  The
default priority is 0.  The integer must not be greater than
2147483647 nor less than -2147483648.</p></item>

</olist>

<p>It is an error if this leaves more than one matching template
rule.  An XSL processor may signal the error; if it does not signal
the error, it must recover by choosing from amongst the matching
template rules that are left the one that occurs last in the
stylesheet.</p>

</div3>

<div3>
<head>Built-in Template Rule</head>

<p>There is a built-in template rule to allow recursive
processing to continue in the absence of a successful pattern match by
an explicit rule in the stylesheet.  This rule applies to both element
nodes and the root node.  The following shows the equivalent of the
built-in template rule:</p>

<eg><![CDATA[<xsl:template match="*|/">
  <xsl:process-children/>
</xsl:template>]]></eg>

<p>The built-in template rule is treated as if it were imported
implicitly before the stylesheet and so is considered less <termref
def="dt-important">important</termref> than all other template
rules.  Thus the author can override the built-in rule by including an
explicit rule with <code>match="*|/"</code>.</p>

</div3>
</div2>

<div2>
<head>Patterns</head>

<p>A pattern is a string which is matched against an element in the
source document.  The most common pattern specifies the element type
name of a matching element. For example, the pattern <code>emph</code>
matches an element whose type is <code>emph</code>.  More complex
patterns specify the element types of ancestors of a matching element.
For example, the pattern <code>olist/item</code> matches an element
whose type is <code>item</code> with a parent element of type
<code>olist</code>.  Each element type in the list of ancestors may be
followed by a list of <quote>qualifiers</quote> separated by commas.
For example,</p>

<eg><![CDATA[list[attribute(ordered)="yes")]/item[first-of-type()]]]></eg>

<p>matches an element whose type is <code>item</code>, which is the
first amongst its siblings of this type, and which has a parent of
type <code>list</code> with an <code>ordered</code> attribute equal to
<code>yes</code>.  This section describes the syntax and semantics of
patterns in detail.</p>

<p><termdef id="dt-match-pattern" term="Match Pattern">A pattern that
is matched against an element is known as a <term>match
pattern</term>.</termdef> Patterns in <code>xsl:template</code> are match
patterns.</p>

<p><termdef id="dt-select-pattern" term="Select Pattern">A pattern can
also be used to select a list of nodes; a pattern that is used for
this is known as a <term>select pattern</term>.</termdef> In a select
pattern, there is a current node which provides a context for the
selection.  The pattern selects the list of the source nodes that
match the pattern.  Nodes in the selected list are in <termref
def="dt-document-order">document order</termref>.  Patterns in
<code>xsl:process</code>, <code>xsl:for-each</code> and
<code>xsl:value-of</code> are select patterns.</p>

<p>In the following grammar, the nonterminals <xnt
href="&XMLNames;#NT-NCName">NCName</xnt> and <xnt
href="&XMLNames;#NT-QName">QName</xnt> are defined in <bibref
ref="XMLNAMES"/>, and <xnt href="&XMLRec;#NT-S">S</xnt> is defined in
<bibref ref="XML"/>.</p>

<issue id="issue-pattern-text-content"><p>Should patterns be able to
match elements based on their textual content?  If XSL is not to
discriminate between DTDs that use attributes and those that use
elements, then it needs at least a qualifier that matches an element
whose pcdata content is exactly some specified string.</p></issue>

<issue id="issue-pattern-text-target"><p>At the moment, the only kind
of node that can match a pattern is an element.  Should it be possible
to have a pattern that matches text?  What would this mean for the
processing model?</p></issue>

<issue id="issue-pattern-pi-target"><p>Should it be possible to have
a pattern that matches a processing instruction?</p></issue>

<issue id="issue-regex"><p>Should XSL support regular
expressions for matching against any or all of pcdata content,
attribute values, attribute names, element type names?</p></issue>

<div3>
<head>Alternative Patterns</head>

<p>A pattern may consist of a set of patterns representing ancestry
separated by the <code>|</code> character.  This indicates that an
element matching any one of the ancestry patterns matches the entire
pattern.  Each ancestry pattern may itself have the capability of a
full pattern except for the <code>|</code> operator.</p>

<scrap>
<head>Alternation</head>
<prod id="NT-Pattern">
<lhs>Pattern</lhs>
<rhs><nt def="NT-OrPattern">OrPattern</nt></rhs>
</prod>
<prod id="NT-OrPattern">
<lhs>OrPattern</lhs>
<rhs><nt def="NT-AncestryPattern">AncestryPattern</nt> ('|' <nt
def="NT-AncestryPattern">AncestryPattern</nt>)*</rhs>
</prod>
</scrap>

<p>This example creates an <code>fo:sequence</code> for either
<code>emph</code> or <code>strong</code> elements:</p>

<eg><![CDATA[<xsl:template match="emph | strong">
  <fo:sequence font-weight="bold">
    <xsl:process-children/>
  </fo:sequence>
</xsl:template>]]></eg>
</div3>

<div3>
<head>Matching on Element Ancestry</head>

<p>Element ancestry can be represented within the pattern by using the
parent operator (<code>/</code>). This operator is based on the
familiar directory navigation metaphor.  Two patterns separated by the
parent operator match an element if the right-hand side matches the
element and the left-hand side matches the parent of the element.</p>

<scrap>
<head>Ancestry</head>
<prod id="NT-AncestryPattern">
<lhs>AncestryPattern</lhs>
<rhs><nt def="NT-NodePatterns">NodePatterns</nt></rhs>
<rhs>| (<nt def="NT-Anchor">Anchor</nt> (<nt def="NT-AncestryOp">AncestryOp</nt> <nt def="NT-NodePatterns">NodePatterns</nt>)?)</rhs>
<rhs>| (<nt def="NT-RootPattern">RootPattern</nt> <nt def="NT-NodePatterns">NodePatterns</nt>?)</rhs>
</prod>
<prod id="NT-NodePatterns">
<lhs>NodePatterns</lhs>
<rhs>(<nt def="NT-ElementPatterns">ElementPatterns</nt>
(<nt def="NT-AncestryOp">AncestryOp</nt>
 <nt def="NT-AttributePattern">AttributePattern</nt>)?)</rhs>
<rhs>| <nt def="NT-AttributePattern">AttributePattern</nt></rhs>
</prod>
<prod id="NT-ElementPatterns">
<lhs>ElementPatterns</lhs>
<rhs><nt def="NT-ElementPattern">ElementPattern</nt> (<nt def="NT-AncestryOp">AncestryOp</nt> <nt def="NT-ElementPattern">ElementPattern</nt>)*</rhs>
</prod>
<prod id="NT-AncestryOp">
<lhs>AncestryOp</lhs><rhs>'/' | '//'</rhs>
</prod>
<prod id="NT-ElementPattern">
<lhs>ElementPattern</lhs>
<rhs><nt def="NT-ElementTypePattern">ElementTypePattern</nt>
<nt def="NT-ElementQualification">ElementQualification</nt>?</rhs>
</prod>
</scrap>

<p>For example, the following pattern matches <code>title</code>
source elements that have a <code>section</code> element as a parent
and a <code>chapter</code> element as a grandparent:</p>

<eg><![CDATA[<xsl:template match="chapter/section/title">
  ...
</xsl:template>]]></eg>

<p>While the parent operator specifies a parent-child relationship, the
ancestor operator (<code>//</code>) specifies an ancestor-descendant
relationship.  Two patterns separated by the ancestor operator match
an element if the right-hand side matches the element and the element
has at least one ancestor that the left-hand side matches.  Thus zero
or more levels of hierarchy may intervene between the element matching
the pattern specified on the left-hand side of the ancestor operator
and the element matching the pattern specified on the right-hand
side.</p>

<p>This example applies to <code>changed</code> elements which have
a <code>para</code> element as an ancestor.</p>

<eg><![CDATA[<xsl:template match="para//changed">
  ...
</xsl:template>]]></eg>

</div3>

<div3>
<head>Anchors</head>

<p>The first component of an <nt
def="NT-AncestryPattern">AncestryPattern</nt> can be an <nt
def="NT-Anchor">Anchor</nt>.  An <nt def="NT-Anchor">Anchor</nt> is a
pattern that only a specific element in the source tree matches (if
any elements at all match).  <termdef id="dt-address" term="Address">The
<nt def="NT-Anchor">Anchor</nt> is said to <term>address</term> the
specific element that matches it.</termdef></p>

<p>There are two kinds of anchor, relative and absolute.  A relative
anchor addresses an element relative to the current node.  An absolute
anchor addresses an element independently of any current node.  A
<termref def="dt-match-pattern">match pattern</termref> must not
contain a <nt def="NT-RelativeAnchor">RelativeAnchor</nt>; all anchors
in a match pattern must be absolute.  A <termref
def="dt-select-pattern">select pattern</termref> may contain both
kinds of anchor.</p>

<scrap>
<head>Anchors</head>
<prod id="NT-Anchor">
<lhs>Anchor</lhs>
<rhs><nt def="NT-AbsoluteAnchor">AbsoluteAnchor</nt></rhs>
<rhs>| <nt def="NT-RelativeAnchor">RelativeAnchor</nt></rhs>
</prod>
<prod id="NT-AbsoluteAnchor">
<lhs>AbsoluteAnchor</lhs>
<rhs><nt def="NT-IdAnchor">IdAnchor</nt></rhs>
</prod>
<prod id="NT-RelativeAnchor">
<lhs>RelativeAnchor</lhs>
<rhs><nt def="NT-CurrentNodeAnchor">CurrentNodeAnchor</nt></rhs>
<rhs>| (<nt def="NT-ParentAnchor">ParentAnchor</nt>
('/' <nt def="NT-ParentAnchor">ParentAnchor</nt>)*)</rhs>
<rhs>| <nt def="NT-AncestorAnchor">AncestorAnchor</nt></rhs>
</prod>
<prod id="NT-CurrentNodeAnchor">
<lhs>CurrentNodeAnchor</lhs>
<rhs>'.'</rhs>
</prod>
<prod id="NT-ParentAnchor">
<lhs>ParentAnchor</lhs>
<rhs>'..'</rhs>
</prod>
</scrap>

<p>A <nt def="NT-CurrentNodeAnchor">CurrentNodeAnchor</nt> <termref
def="dt-address">addresses</termref> the current node.</p>

<p>A <termref def="dt-select-pattern">select pattern</termref> is
implicitly anchored to the current node: if an <nt
def="NT-AncestryPattern">AncestryPattern</nt> in the <nt
def="NT-Pattern">Pattern</nt> does not start with an <nt
def="NT-Anchor">Anchor</nt> or a <nt
def="NT-RootPattern">RootPattern</nt>, it is treated as if it were
<code>./</code><nt def="NT-AncestryPattern">AncestryPattern</nt>.  For
example, a select pattern of <code>foo</code> will be treated as
<code>./foo</code> and will thus select the <code>foo</code> children
of the current node.</p>

<p>A <nt def="NT-ParentAnchor">ParentAnchor</nt> <termref
def="dt-address">addresses</termref> the parent of the current
node.</p>

<div4>
<head>Ancestor Anchors</head>

<scrap>
<head>Ancestor Anchors</head>
<prod id="NT-AncestorAnchor">
<lhs>AncestorAnchor</lhs>
<rhs>'ancestor' '(' <nt def="NT-Pattern">Pattern</nt> ')'</rhs>
</prod>
</scrap>

<p>An <nt def="NT-AncestorAnchor">AncestorAnchor</nt> <termref
def="dt-address">addresses</termref> the nearest ancestor of the
current node that matches the specified pattern.  The pattern in a <nt
def="NT-AncestorAnchor">AncestorAnchor</nt> is a <termref
def="dt-match-pattern">match pattern</termref>.</p>

</div4>

<div4>
<head>Id Anchors</head>

<p>An <nt def="NT-IdAnchor">IdAnchor</nt> <termref
def="dt-address">addresses</termref> the element whose ID (see
<specref ref="unique-id"/>) is the specified <xnt
href="&XMLNames;#NT-NCName">NCName</xnt>.</p>

<scrap>
<head>Id Anchors</head>
<prod id="NT-IdAnchor">
<lhs>IdAnchor</lhs>
<rhs>'id' '(' <xnt href="&XMLNames;#NT-NCName">NCName</xnt> ')'</rhs>
</prod>
</scrap>

</div4>

</div3>

<div3>
<head>Matching the Root Node</head>

<p>A <nt def="NT-RootPattern">RootPattern</nt> matches the root
node (see <specref ref="root-node"/>).</p>

<scrap>
<head>Root Patterns</head>
<prod id="NT-RootPattern">
<lhs>RootPattern</lhs>
<rhs>'/'</rhs>
</prod>
</scrap>

</div3>

<div3>
<head>Matching on Element Types</head>

<p>The simplest pattern consists of just an element type name.  This
matches any element of that type.</p>

<eg><![CDATA[<xsl:template match="first-name">
  ...
</xsl:template>]]></eg>

<p>The <code>*</code> pattern is a wildcard that matches a single
element of any type.  When used within an ancestry chain, the wildcard
matches exactly one level of hierarchy.</p>

<scrap>
<head>Element Type Pattern</head>
<prodgroup pcw2="10">
<prod id="NT-ElementTypePattern">
<lhs>ElementTypePattern</lhs>
<rhs><nt def="NT-OneElementTypePattern">OneElementTypePattern</nt></rhs>
<rhs>| <nt def="NT-AnyElementTypePattern">AnyElementTypePattern</nt></rhs>
</prod>
<prod id="NT-OneElementTypePattern">
<lhs>OneElementTypePattern</lhs>
<rhs><nt def="NT-ElementTypeName">ElementTypeName</nt></rhs>
</prod>
<prod id="NT-ElementTypeName">
<lhs>ElementTypeName</lhs>
<rhs><xnt href="&XMLNames;#NT-QName">QName</xnt></rhs>
</prod>
<prod id="NT-AnyElementTypePattern">
<lhs>AnyElementTypePattern</lhs>
<rhs>'*'</rhs>
</prod>
</prodgroup>
</scrap>

<p>The following pattern matches any element that is an immediate
child of a <code>data-samples</code> element.</p>

<eg><![CDATA[<xsl:template match="data-samples/*">
  ...
</xsl:template>]]></eg>

<p>When determining whether a source element matches an <nt
def="NT-ElementTypeName">ElementTypeName</nt>, the expanded element
type names are compared (see <specref ref="element-nodes"/>).</p>

<issue id="issue-pattern-namespace-wildcards"><p>Should patterns of
the form <code>foo:*</code> or <code>*:foo</code> be allowed?  If so,
should <code>*</code> match any element or any element without a
namespace URI?</p></issue>

</div3>

<div3>
<head>Qualifiers</head>

<p>An element within the pattern hierarchy may have qualifiers applied
to it, which further constrain which elements match the term.  These
qualifiers may constrain the element to have certain attributes or
sub-elements or may constrain its position with respect to its
siblings.  The qualifiers are specified in square brackets
(<code>[]</code>) following the element type name or wildcard
symbol. A pattern matches only if all of the qualifiers are
satisfied.</p>

<scrap>
<head>Qualifiers</head>
<prod id="NT-ElementQualification">
<lhs>ElementQualification</lhs>
<rhs>'[' <nt def="NT-Qualifiers">Qualifiers</nt>? ']'</rhs>
</prod>
<prod id="NT-Qualifiers">
<lhs>Qualifiers</lhs>
<rhs>
<nt def="NT-Qualifier">Qualifier</nt>
(',' <nt def="NT-Qualifier">Qualifier</nt>)*
</rhs>
</prod>
<prod id="NT-Qualifier">
<lhs>Qualifier</lhs>
<rhs><nt def="NT-ChildQualifier">ChildQualifier</nt></rhs>
<rhs>| <nt def="NT-AttributeQualifier">AttributeQualifier</nt></rhs>
<rhs>| <nt def="NT-PositionalQualifier">PositionalQualifier</nt></rhs>
</prod>
</scrap>

<p>This example matches <code>author</code> elements within
<code>book</code> elements where the book contains at least one
<code>excerpt</code> sub-element and the author has a
<code>degree</code> attribute:</p>

<eg><![CDATA[<xsl:template match="book[excerpt]/author[attribute(degree)]">
  ...
</xsl:template>]]></eg>

<issue id="issue-sibling-qual"><p>Should there be qualifiers that
constrain an element to have an immediately preceding or following
sibling of a particular type?</p></issue>

</div3>
<div3>
<head>Matching on Children</head>

<p>An element can be constrained to have a child element of a
particular type by specifying the name of that type as a
qualifier.</p>

<scrap>
<head>Child Qualifier</head>
<prod id="NT-ChildQualifier">
<lhs>ChildQualifier</lhs>
<rhs><nt def="NT-ElementTypeName">ElementTypeName</nt></rhs>
</prod>
</scrap>

<p>This example has a pattern that matches <code>author</code>
elements within <code>book</code> elements which also have
<code>excerpt</code> children (the <code>author</code> and
<code>excerpt</code> elements are siblings).</p>

<eg><![CDATA[<xsl:template match="book[excerpt]/author">
  ...
</xsl:template>]]></eg>

<note><p>There is no requirement that each child qualifier is matched
by a distinct element.  Thus
<code><![CDATA[foo[bar,bar]]]></code> is matched by
<code><![CDATA[<foo><bar/></foo>]]></code>.</p></note>

</div3>
<div3>
<head>Matching on Attributes</head>

<p>Attributes on the source element or any of its ancestor elements
can also be used to determine whether a particular rule applies to an
element. An attribute qualifier constrains an element either to have a
specific attribute with a specific value, or to have a specific
attribute with any value.</p>

<scrap>
<head>Attribute Qualifier</head>
<prodgroup pcw2="9">
<prod id="NT-AttributeQualifier">
<lhs>AttributeQualifier</lhs>
<rhs><nt def="NT-AttributePattern">AttributePattern</nt>
('=' <nt def="NT-AttributeValue">AttributeValue</nt>)?</rhs>
</prod>
<prod id="NT-AttributePattern">
<lhs>AttributePattern</lhs>
<rhs>'attribute' '(' <xnt href="&XMLNames;#NT-QName">QName</xnt> ')'</rhs>
</prod>
<prod id="NT-AttributeValue">
<lhs>AttributeValue</lhs>
<rhs>'"' [^"]* '"'</rhs>
<rhs>| "'" [^']* "'"</rhs>
</prod>
</prodgroup>
</scrap>

<p>When matching attribute names, the expanded names are compared (see
<specref ref="attribute-nodes"/>).</p>

<issue id="issue-attribute-qual-case"><p>Do we need to be able
to match attributes in a case insensitive way?</p></issue>

<p>The following example matches an <code>item</code> element that has
for its parent a <code>list</code> element which has a
<code>compact</code> attribute:</p>

<eg><![CDATA[<xsl:template match="list[attribute(compact)]/item">
  ...
</xsl:template>]]></eg>

<p>The following example matches an <code>item</code> element that has for
its parent a <code>list</code> element whose <code>liststyle</code> attribute
has the value <code>enum</code>:</p>

<eg><![CDATA[<xsl:template match="list[attribute(liststyle)='enum']/item">
  ...
</xsl:template>]]></eg>

<p>It is also possible to select attribute nodes.  Within a <termref
def="dt-select-pattern">select pattern</termref>, an <nt
def="NT-AncestryPattern">AncestryPattern</nt> can end with an <nt
def="NT-AttributePattern">AttributePattern</nt>.  This will select the
attribute node with the specified name for each element in the node
list selected by the pattern preceding <nt
def="NT-AttributePattern">AttributePattern</nt>.  Within a <termref
def="dt-match-pattern">match pattern</termref>, an <nt
def="NT-AncestryPattern">AncestryPattern</nt> must not end with an <nt
def="NT-AttributePattern">AttributePattern</nt>.</p>

<issue id="issue-class-attribute"><p>Should there be a way of
specifying that an attribute serves as a class attribute and then
pattern syntax that treats class attributes specially?</p></issue>

</div3>

<div3>
<head>Matching on Position</head>

<p>Positional qualifiers may be used to further constrain the pattern
to match on the element's position or uniqueness among its
siblings.</p>

<p>XSL defines the following positional qualifiers:</p>
<ulist>

<item><p><code>first-of-type()</code>. The element must be the first
sibling of its type.</p></item>

<item><p><code>not-first-of-type()</code>. The element must not be the
first sibling of its type.</p></item>

<item><p><code>last-of-type()</code>. The element must be the last
sibling of its type.</p></item>

<item><p><code>not-last-of-type()</code>. The element must not be the
last sibling of its type.</p></item>

<item><p><code>first-of-any()</code>. The element must be the first
sibling element of any type.</p></item>

<item><p><code>not-first-of-any()</code>. The element must not be the
first sibling element of any type.</p></item>

<item><p><code>last-of-any()</code>. The element must be the last
sibling element of any type.</p></item>

<item><p><code>not-last-of-any()</code>. The element must not be the
last sibling element of any type.</p></item>

<item><p><code>only-of-type()</code>. The element must have no element
siblings of the same type.</p></item>

<item><p><code>not-only-of-type()</code>. The element must have one or
more element siblings of the same type.</p></item>

<item><p><code>only-of-any()</code>. The element must have no element
siblings at all.</p></item>

<item><p><code>not-only-of-any()</code>. The element must have one or
more element siblings.</p></item>

</ulist>

<scrap>
<head>Positional Qualifier</head>
<prodgroup pcw2="9">
<prod id="NT-PositionalQualifier">
<lhs>PositionalQualifier</lhs>
<rhs><nt def ="NT-Position">Position</nt> '(' ')'</rhs>
</prod>
<prod id="NT-Position">
<lhs>Position</lhs>
<rhs>'first-of-type' | 'not-first-of-type'</rhs>
<rhs>| 'first-of-any' | 'not-first-of-any'</rhs>
<rhs>| 'last-of-type' | 'not-last-of-type'</rhs>
<rhs>| 'last-of-any' | 'not-last-of-any'</rhs>
<rhs>| 'only-of-type' | 'not-only-of-type'</rhs>
<rhs>| 'only-of-any' | 'not-only-of-any'</rhs>
</prod>
</prodgroup>
</scrap>

<p>The following pattern matches the first <code>item</code> in a
<code>list</code>:</p>

<eg><![CDATA[<xsl:template match="list/item[first-of-type()]">
  ...
</xsl:template>]]></eg>

<p>The following rule is used for <code>appendix</code> elements when
there is only one appendix:</p>

<eg><![CDATA[<xsl:template match="backmatter/appendix[only-of-type()]">
  ...
</xsl:template>]]></eg>

</div3>

<div3>
<head>Whitespace in Patterns</head>

<p>For readability, whitespace may be used in patterns even though not
explicitly allowed by the grammar: <nt
def="NT-PatternWhitespace">PatternWhitespace</nt> may be freely added
within patterns before or after any <nt
def="NT-PatternToken">PatternToken</nt>.</p>

<scrap>
<head>Pattern Lexical Structure</head>
<prod id="NT-PatternToken">
<lhs>PatternToken</lhs>
<rhs>'/' | '//' | '(' | ')' | '|' | '[' | ']' | ',' | '=' | '.' | '..' | '*'</rhs>
<rhs>| 'attribute' | 'id' | 'ancestor'</rhs>
<rhs>| <xnt href="&XMLNames;#NT-NCName">NCName</xnt></rhs>
<rhs>| <xnt href="&XMLNames;#NT-QName">QName</xnt></rhs>
<rhs>| <nt def="NT-AttributeValue">AttributeValue</nt></rhs>
<rhs>| <nt def="NT-Position">Position</nt></rhs>
</prod>
<prod id="NT-PatternWhitespace">
<lhs>PatternWhitespace</lhs>
<rhs><xnt href="&XMLRec;#NT-S">S</xnt></rhs>
</prod>
</scrap>

</div3>

<div3 id="specificity">
<head>Specificity</head>

<p>When a source element is matched against multiple patterns, it is
possible for it to match more than one distinct pattern.  In this
situation, XSL defines which pattern or patterns are the most
specific.</p>

<p>A pattern that starts with an <nt def="NT-IdAnchor">IdAnchor</nt>
is more specific than a pattern that does not.  If two patterns both
start with an <nt def="NT-IdAnchor">IdAnchor</nt> or both do not start
with an <nt def="NT-IdAnchor">IdAnchor</nt>, then the one with the
more components is the more specific, where a component is either a
<nt def="NT-Qualifier">Qualifier</nt> or a <nt
def="NT-OneElementTypePattern">OneElementTypePattern</nt>.</p>

<p>For example, the following patterns are in decreasing order of
specificity:</p>

<olist>
<item><p><code>id(employee-of-the-month)</code></p></item>
<item><p><code>employee[attribute(type)='contract',attribute(country)='USA']</code></p></item>
<item><p><code>employee[attribute(type)='contract']</code></p></item>
<item><p><code>employee</code></p></item>
<item><p><code>*</code></p></item>
</olist>

<p>When a pattern contains alternatives separated by <code>|</code>,
each alternative is treated separately for specificity purposes.  A
rule that contains a pattern with two alternatives is equivalent to
two rules with the same content each specifying one of the
alternatives as its patterns. For example</p>

<eg><![CDATA[<xsl:template match="EMPH|B" priority="1">
  <fo:sequence font-weight="bold"><xsl:process-children/></fo:sequence>
</xsl:template>
]]></eg>

<p>is equivalent to</p>

<eg><![CDATA[<xsl:template match="EMPH" priority="1">
  <fo:sequence font-weight="bold"><xsl:process-children/></fo:sequence>
</xsl:template>
<xsl:template match="B" priority="1">
  <fo:sequence font-weight="bold"><xsl:process-children/></fo:sequence>
</xsl:template>
]]></eg>

</div3>
</div2>

<div2>
<head>Templates</head>

<div3>
<head>Overview</head>

<p>When the rule that is to be applied to the source element has been
identified, the rule's template is instantiated. A 
template can contain literal result elements, character data and
instructions for creating fragments of the result tree.  Instructions
are represented by elements in the XSL namespace.</p>

<p>Instructions can select descendant elements for processing.  There
are two such instructions, the <code>xsl:process-children</code> instruction
and the <code>xsl:process</code> instruction; the
<code>xsl:process-children</code> instruction processes the immediate children
of the source element, while the <code>xsl:process</code> instruction
processes elements selected by a specified pattern.</p>

<eg><![CDATA[<xsl:template match="chapter/title">
  <fo:rule-graphic/>
  <fo:block space-before="2pt">
    <xsl:text>Chapter </xsl:text>
    <xsl:number/>
    <xsl:text>: </xsl:text>
    <xsl:process-children/>
  </fo:block>
  <fo:rule-graphic/>
</xsl:template>]]></eg>

<p>Note that <code>xsl:process-children</code> selects any character children
of the source element as well as the element children.  The result in
this case is the sequence of results of processing the individual
character children and element children in sequence.</p>

<issue id="issue-instruction-next-match"><p>Should we add an
instruction with the functionality of <code>next-match</code> in
DSSSL?</p></issue>

<issue id="issue-instruction-error"><p>Should there be an instruction
that generates an error, like the <code>error</code> procedure in
DSSSL?</p></issue>

<issue id="issue-instruction-sort"><p>There needs to be an instruction
that can do sorting.  How should this work?</p></issue>

<issue id="issue-instruction-result-number"><p>There needs to be
instruction that allows result elements to be numbered.  How should
this work?</p></issue>

<issue id="issue-modes"><p>How should the functionality of DSSSL modes
be provided?  Should nested template rules be used for this? Is
there a way of getting source elements to appear in multiple places in
the output that can be implemented in a single pass?</p></issue>

<issue id="issue-identity-transform"><p>There needs to be a way to do
the identity transformation (creating a result tree identical to the
source tree).  How should this be done?</p></issue>

</div3>

<div3>
<head>Literal Result Elements</head>

<p>In a template an element in the stylesheet that does not
belong to the XSL namespace is instantiated to create an element node
of the same type; the created element node will have the attributes
that were specified on the element in the template tree.</p>

<p>The value of an attribute of a literal result element is
interpreted as an <termref def="dt-attribute-value-template">attribute
value template</termref>: it can contain string expressions
contained in curly braces (<code>{}</code>).</p>

<p>The <termref def="dt-namespace-prefix-map">namespace prefix
map</termref> of the result element node is the namespace prefix map
of the element node in the stylesheet after the removal of any prefixes
that map to the XSL namespace URI.</p>

<p>Since an XSL processor acts on elements belonging to the XSL
namespace, the problem arises of how to create elements belonging to
the XSL namespace.  A namespace whose URI is
<code>http://www.w3.org/TR/WD-xsl</code> followed by one or more
occurrences of <code>/quote</code> is called a quoted namespace.
Quoted namespaces are treated specially: before a result tree is
written out as XML all quoted namespace URIs in expanded names and in
namespace prefix maps are unquoted by removing the final
<code>/quote</code>.</p>

</div3>

<div3>
<head>Named Attribute Sets</head>

<p>The <code>xsl:define-attribute-set</code> element defines a named
set of attributes.  The <code>name</code> attribute specifies the name
of the attribute set.  The content of the
<code>xsl:define-attribute-set</code> element is an
<code>xsl:attribute-set</code> element that specifies the
attributes. A literal result element or an
<code>xsl:attribute-set</code> element can specify an attribute set
name as the value of the <code>xsl:use</code> attribute.</p>

<p>The following example creates a named attribute set
<code>title-style</code> and uses it in a template rule.</p>

<eg><![CDATA[<xsl:define-attribute-set name="title-style">
  <xsl:attribute-set font-size="12pt"
                     font-weight="bold"/>
</xsl:define-attribute-set>

<xsl:template match="chapter/heading">
  <fo:block xsl:use="title-style" quadding="start">
    <xsl:process-children/>
  </fo:block>
</xsl:template>]]></eg>

<p>If the <code>xsl:use</code> attribute is specified on an element
that also specifies a value for an attribute that is also part of the
attribute set named by <code>xsl:use</code>, the attribute in the
named attribute set is not used.</p>

<p>Multiple definitions of an attribute set with the same name are
merged.  An attribute from a definition that is more <termref
def="dt-important">important</termref> takes precedence over an
attribute from a definition that is less <termref
def="dt-important">important</termref>.  It is an error if there are
two attribute sets with the same name that are equally important and
that both contain the same attribute unless there is a more <termref
def="dt-important">important</termref> definition of the attribute set
that also contains the attribute.  An XSL processor may signal the
error; if it does not signal the error, it must recover by choosing
from amongst the most important definitions that specify the attribute
the one that was specified last in the stylesheet.</p>

<p>An <code>xsl:use</code> attribute may specify a list of attribute
set names separated by whitespace.  These attribute sets will be
merged treating the list as being in order of increasing
importance.</p>

</div3>

<div3>

<head>Literal Text in Templates</head>

<p>A template can also contain PCDATA.  Each data character in a
template remaining after whitespace has been stripped as
specified in <specref ref="strip"/> will create a data character in
the result tree.</p>

<p>Literal data characters may also be wrapped in an
<code>xsl:text</code> element.  This wrapping may change what
whitespace characters are stripped (see <specref ref="strip"/>) but
does not affect how the characters are handled by the XSL processor
thereafter.</p>

</div3>

<div3>
<head id="children">Processing with <code>xsl:process-children</code></head>

<ednote><edtext>There is no WG consensus on the name
xsl:process-children.</edtext></ednote>

<ednote><edtext>When we add to select patterns the ability to select
characters as well as elements, the functionality of
xsl:process-children will be available from
xsl:process.</edtext></ednote>

<p>This example creates a block for a <code>chapter</code>
element and then processes its immediate children.</p>

<eg><![CDATA[<xsl:template match="chapter">
  <fo:block>
    <xsl:process-children/>
  </fo:block>
</xsl:template>]]></eg>

<p>The <code>xsl:process-children</code> instruction processes all of the
children of the current node, including characters.  However,
characters that have been stripped as specified in <specref
ref="strip"/> will not be processed.</p>

<p>Processing a character in the source tree adds the character to the
result tree.  Note that this works at the tree level.  Thus, markup of
<code>&amp;lt;</code> in content will be represented by a character
<code>&lt;</code> in the source tree which will, with the built-in
template rules, turn into a <code>&lt;</code> character in the
result tree, which would be represented by the markup
<code>&amp;lt;</code> (or an equivalent character reference) when the
result tree is externalized as an XML document.</p>

</div3>

<div3>
<head>Processing with <code>xsl:process</code></head>

<ednote><edtext>There is no WG consensus on the name
xsl:process.</edtext></ednote>

<issue id="issue-process-name"><p>What should <code>xsl:process</code>
be called?</p></issue>

<p>The <code>xsl:process</code> element processes elements selected by
a pattern.  The pattern of an <code>xsl:process</code> element is a
<termref def="dt-select-pattern">select pattern</termref> and so is
implicitly anchored to the current node.  The following example
processes all of the <code>author</code> children of the
<code>author-group</code>:</p>

<eg><![CDATA[<xsl:template match="author-group">
  <fo:sequence>
    <xsl:process select="author"/>
  </fo:sequence>
</xsl:template>]]></eg>

<p>The <code>xsl:process</code> element processes all
<emph>elements</emph> which match the specified pattern. Character
data content is not matched by an <code>xsl:process</code> element.
The pattern must not contain an <nt
def="NT-AttributePattern">AttributePattern</nt> except as part of an
<nt def="NT-AttributeQualifier">AttributeQualifier</nt></p>

<p>The pattern controls the depth at which matches occur. The
following example processes all of the <code>first-name</code>s of the
<code>author</code>s that are direct children of
<code>author-group</code>:</p>

<eg><![CDATA[<xsl:template match="author-group">
  <fo:sequence>
    <xsl:process select="author/first-name"/>
  </fo:sequence>
</xsl:template>]]></eg>

<p>The <code>//</code> operator can be used in the pattern to allow
the matches to occur at arbitrary depths.</p>

<p>This example processes all of the <code>heading</code> elements
contained in the <code>book</code> element.</p>

<eg><![CDATA[<xsl:template match="book">
  <fo:block>
    <xsl:process select=".//heading"/>
  </fo:block>
</xsl:template>]]></eg>

<p>An <nt def="NT-AncestorAnchor">AncestorAnchor</nt> in the pattern
allows the processing of elements that are not descendants of the
current node.  This example finds an employee's department and then
processes the <code>group</code> children of the
<code>department</code>.</p>

<eg><![CDATA[<xsl:template match="employee">
  <fo:block>
    Employee <xsl:process select="name"/> belongs to group
    <xsl:process select="ancestor(department)/group"/>
  </fo:block>
</xsl:template>]]></eg>

<p>This example assumes that a <code>department</code> element
contains <code>group</code> and <code>employee</code> elements (at
some level). When processing the <code>employee</code> elements, the
<nt def="NT-AncestorAnchor">AncestorAnchor</nt> in the pattern allows
navigation upward to the <code>department</code> element in order to
extract the information about the group to which the employee
belongs.</p>

<p>An <nt def="NT-IdAnchor">IdAnchor</nt> allows processing of
elements with a specific ID.  For example, this template rule applies
to elements with the ID <code>cfo</code>; the second
<code>xsl:process</code> element processes the <code>name</code> child of
the element with ID <code>ceo</code>:</p>

<eg><![CDATA[<xsl:template match="id(cfo)">
  <xsl:process select="name"/> reports to <xsl:process select="id(ceo)/name"/>
</xsl:template>]]></eg>

<p>Multiple <code>xsl:process</code> elements can be used within a
single template to do simple reordering.  The following example
creates two HTML tables. The first table is filled with domestic sales
while the second table is filled with foreign sales.</p>

<eg><![CDATA[<xsl:template match="product">
  <TABLE>
    <xsl:process select="sales/domestic"/>
  </TABLE>
  <TABLE>
    <xsl:process select="sales/foreign"/>
  </TABLE>
</xsl:template>]]></eg>

<note>

<p>It is possible for there to be two matching descendants where one
is a descendant of the other.  This case is not treated specially:
both descendants will be processed as usual. For example, given a
source document</p>

<eg><![CDATA[<doc><div><div></div></div></doc>]]></eg>

<p>the rule</p>

<eg><![CDATA[<xsl:template match="doc">
  <xsl:process select=".//div"/>
</xsl:template>]]></eg>

<p>will process both the outer <code>div</code> and inner <code>div</code>
elements.</p>

</note>

<p>Use of <nt def="NT-Anchor">Anchor</nt>s in patterns in
<code>xsl:process</code> can lead to infinite loops.  It is an error
if, during the invocation of a rule for an element, that same rule is
invoked again for that element.  An XSL processor may signal the
error; if it does not signal the error, it must recover by creating an
empty result tree structure for the nested invocation.</p>

<issue id="issue-select-function"><p>What mechanisms should be
provided for selecting elements for processing?  For example, how can
elements specified indirectly be handled?  Suppose there's an
<code>xref</code> element with a <code>ref</code> attribute that
specifies the ID of a <code>div</code> element.  The template
for <code>xref</code> needs to select <code>title</code> child of the
<code>div</code> element referenced by the <code>ref</code> attribute.
Should it be possible to select elements in other XML
documents?</p></issue>

</div3>

<div3>

<head>Direct Processing</head>

<p>When the result has a known regular structure, it is useful to be
able to specify directly the template for selected elements.
The <code>xsl:for-each</code> element contains a template which
is instantiated for each element selected by the pattern specified by
the <code>select</code> attribute.</p>

<p>For example, given an XML document with this structure</p>

<eg><![CDATA[<customers>
  <customer>
    <name>...</name>
    <order>...</order>
    <order>...</order>
  </customer>
  <customer>
    <name>...</name>
    <order>...</order>
    <order>...</order>
  </customer>
</customers>]]></eg>

<p>the following would create an HTML document containing a table with
a row for each <code>customer</code> element</p>

<eg><![CDATA[<xsl:template match="/">
  <HTML>
    <HEAD>
      <TITLE>Customers</TITLE>
    </HEAD>
    <BODY>
      <TABLE>
	<TBODY>
	  <xsl:for-each select="customers/customer">
	    <TR>
	      <TH>
		<xsl:process select="name"/>
	      </TH>
	      <xsl:for-each select="order">
		<TD>
		  <xsl:process-children/>
		</TD>
	      </xsl:for-each>
	    </TR>
	  </xsl:for-each>
	</TBODY>
      </TABLE>
    </BODY>
  </HTML>
</xsl:template>]]></eg>

<p>As with <code>xsl:process</code> the pattern is a <termref
def="dt-select-pattern">select pattern</termref> and so is implicitly
anchored to the current node.  The <code>select</code> attribute is
required. The pattern must not contain an <nt
def="NT-AttributePattern">AttributePattern</nt> except as part of an
<nt def="NT-AttributeQualifier">AttributeQualifier</nt>.</p>

</div3>


<div3>
<head>Numbering in the Source Tree</head>

<p>The <code>xsl:number</code> element does numbering based on the
position of the current node in the source tree.</p>

<p>The <code>xsl:number</code> element can have the following
attributes:</p>

<ulist>

<item><p>The <code>level</code> attribute specifies what levels of the
source tree should be considered; it has the values
<code>single</code>, <code>multi</code> or <code>any</code>. The
default is <code>single</code>.</p></item>

<item><p>The <code>count</code> attribute is a <termref
def="dt-match-pattern">match pattern</termref> that specifies what
elements should be counted at those levels.  The <code>count</code>
attribute defaults to the element type name of the current
node.</p></item>

<item><p>The <code>from</code> attribute is a <termref
def="dt-match-pattern">match pattern</termref> that specifies where
counting starts from.</p></item>

</ulist>

<p>In addition the <code>xsl:number</code> element has the attributes
specified in <specref ref="convert"/> for number to string
conversion.</p>

<p>The <code>xsl:number</code> element first constructs a list of
positive integers using the <code>level</code>, <code>count</code> and
<code>from</code> attributes:</p>

<ulist>

<item><p>When <code>level="single"</code>, it goes up to the nearest
ancestor (including the current node as its own ancestor) that
matches the <code>count</code> pattern, and constructs a list of length one
containing one plus the number of preceding siblings of that ancestor
that match the <code>count</code> pattern.  If there is no such
ancestor, it constructs an empty list.  If the <code>from</code>
attribute is specified, then the only ancestors that are searched are
those that are descendants of the nearest ancestor that matches the
<code>from</code> pattern.</p></item>

<item><p>When <code>level="multi"</code>, it constructs a list of all
ancestors of the current node in document order followed by the
element itself; it then selects from the list those elements that
match the <code>count</code> pattern; it then maps each element of the
list to one plus the number of preceding siblings of that element that
match the <code>count</code> pattern.  If the <code>from</code>
attribute is specified, then the only ancestors that are searched are
those that are descendants of the nearest ancestor that matches the
<code>from</code> pattern.</p></item>

<item><p>When <code>level="any"</code>, it constructs a list of length
one containing one plus number of elements at any level of the
document that start before this node and that match the
<code>count</code> pattern.  If the <code>from</code> attribute is
specified, then only elements after the first element before this
element that match the <code>from</code> pattern are
considered.</p></item>

</ulist>

<p>The list of numbers is then converted into a string using the
attributes specified in <specref ref="convert"/>; when used with
<code>xsl:number</code> the value of each of these attributes is
interpreted as an <termref def="dt-attribute-value-template">attribute
value template</termref>.  After conversion, the resulting string is
inserted in the result tree.</p>

<p>The following would number the items in an ordered list:</p>

<eg><![CDATA[<xsl:template match="ol/item">
  <fo:block>
    <xsl:number/><xsl:text>. </xsl:text><xsl:process-children/>
  </fo:block>
<xsl:template>]]></eg>

<p>The following two rules would number <code>title</code> elements.
This is intended for a document that contains a sequence of chapters
followed by a sequence of appendices, where both chapters and
appendices contain sections which in turn contain subsections.
Chapters are numbered 1, 2, 3; appendices are numbered A, B, C;
sections in chapters are numbered 1.1, 1.2, 1.3; sections in
appendices are numbered A.1, A.2, A.3.</p>

<eg><![CDATA[<xsl:template match="title">
  <fo:block>
     <xsl:number level="multi"
                 count="chapter|section|subsection"
                 format="1.1. "/>
     <xsl:process-children/>
  </fo:block>
</xsl:template>

<xsl:template match="appendix//title">
  <fo:block>
     <xsl:number level="multi"
                 count="appendix|section|subsection"
                 format="A.1. "/>
     <xsl:process-children/>
  </fo:block>
</xsl:template>]]></eg>

<p>The following example numbers notes sequentially within a
chapter:</p>

<eg><![CDATA[<xsl:template match="note">
  <fo:block>
     <xsl:number level="any" from="chapter" format="(1) "/>
     <xsl:process-children/>
  </fo:block>
</xsl:template>]]></eg>

<p>The following example would number <code>H4</code> elements in HTML
with a three-part label:</p>

<eg><![CDATA[<xsl:template match="H4">
 <fo:block>
   <xsl:number level="any" from="H1" count="H2"/>
   <xsl:text>.</xsl:text>
   <xsl:number level="any" from="H2" count="H3"/>
   <xsl:text>.</xsl:text>
   <xsl:number level="any" from="H3" count="H4"/>
   <xsl:text> </xsl:text>
   <xsl:process-children/>
 </fo:block>
</xsl:template>]]></eg>

</div3>

<div3 id="convert">
<head>Number to String Conversion Attributes</head>

<p>The following attributes are used to control conversion of a list
of numbers into a string. The numbers are integers greater than
0. The attributes are all optional.</p>

<p>The main attribute is <code>format</code>.  The default value for
the <code>format</code> attribute is <code>1</code>.  The
<code>format</code> attribute is split into a sequence of tokens where
each token is a maximal sequence of alphanumeric characters or a
maximal sequence of non-alphanumeric characters.  The alphanumeric
tokens (format tokens) specify the format to be used for each number
in the list; the non-alphanumeric tokens (separator tokens) specify
the separators used to join numbers in the list.  Alphanumeric means
any character that has a Unicode category of Nd, Nl, No, Lu, Ll, Lt,
Lm or Lo. If the first token is a separator token, then the
constructed string will start with that token; if the last token is a
separator token, then the constructed string will end with that token.
The n-th format token will be used to format the n-th number in the
list.  If there are more numbers than format tokens, then the last
format token will be used to format remaining numbers. The format
token specifies the string to be used to represent the number 1.  If
there are more than n numbers, then the n-th number will be separated
from the following number by the separator token following the n-th
format token; if there is no such separator token, then the last
separator token will be used; if there are no separator tokens, then
<code>.</code> will be used.</p>

<p>Format tokens are a superset of the allowed values for the
<code>type</code> attribute for the <code>OL</code> element in HTML
4.0 and are interpreted as follows:</p>

<ulist>

<item><p>Any token where the last character has a decimal digit value
of 1 (as specified in the Unicode 2.0 character property database),
and the Unicode value of preceding characters is one less than the
Unicode value of the last character.  This generates a decimal
representation of the number where each number is at least as long as
the format token.  Thus a format token <code>1</code> generates the
sequence <code>1 2 ... 10 11 12 ...</code>, and a format token
<code>01</code> generates the sequence <code>01 02 ... 09 10 11 12
... 99 100 101</code>.</p></item>

<item><p>A format token <code>A</code> generates the sequence <code>A
B C ... Z AA AB AC...</code>.</p></item>

<item><p>A format token <code>a</code> generates the sequence <code>a
b c ... z aa ab ac...</code>.</p></item>

<item><p>A format token <code>i</code> generates the sequence <code>i
ii iii iv v vi vii vii ix x ...</code>.</p></item>

<item><p>A format token <code>I</code> generates the sequence <code>I
II III IV V VI VII VII IX X ...</code>.</p></item>

<item><p>Any other format token indicates a numbering sequence that
starts with that token.  If an implementation does not support a
numbering system that starts with that token, it must use a format
token of <code>1</code>.</p></item>

</ulist>

<p>When numbering with an alphabetic sequence, the
<code>xml:lang</code> attribute specifies which language's alphabet is
to be used.</p>

<note><p>This can be considered as specifying the language of the
value of the <code>format</code> attribute and hence is consistent
with the semantics of <code>xml:lang</code>.</p></note>

<p>The <code>letter-value</code> attribute disambiguates between
numbering schemes that use letters.  In many languages there are two
commonly used numbering schemes that use letters.  One numbering
scheme assigns numeric values to letters in alphabetic sequence, and
the other assigns numeric values to each letter in some other manner.
In English, these would correspond to the numbering sequences
specified by the format tokens <code>a</code> and <code>i</code>.  In
some languages the first member of each sequence is the same, and so
the format token alone would be ambiguous.  A value of
<code>alphabetic</code> specifies the alphabetic sequence; a value of
<code>other</code> specifies the other sequence.</p>

<p>The <code>digit-group-sep</code> attribute gives the separator
between groups of digits, and the optional
<code>n-digits-per-group</code> specifies the number of digits per
group.  For example, <code>digit-group-sep=","</code> and
<code>n-digits-per-group="3"</code> would produce numbers of the form
<code>1,000,000</code>.</p>

<p>The <code>sequence-src</code> attribute gives the URI of a text
resource that contains a whitespace separated list of the members of
the numbering sequence.</p>

<ednote><edtext>Specify what should happen when the sequence runs
out.</edtext></ednote>

<p>Here are some examples of conversion specifications:</p>

<ulist>

<item><p><code>format="&amp;#x30A2;"</code> specifies Katakana
numbering</p></item>

<item><p><code>format="&amp;#x30A4;"</code> specifies Katakana
numbering in the <quote>iroha</quote> order</p></item>

<item><p><code>format="&amp;#x0E51;"</code> specifies numbering with
Thai digits</p></item>

<item><p><code>format="&amp;#x05D0;" letter-value="other"</code>
specifies <quote>traditional</quote> Hebrew numbering</p></item>

<item><p><code>format="&amp;#x10D0;" letter-value="other"</code>
specifies Georgian numbering</p></item>

<item><p><code>format="&amp;#x03B1;" letter-value="other"</code>
specifies <quote>classical</quote> Greek numbering</p></item>

<item><p><code>format="&amp;#x0430;" letter-value="other"</code>
specifies Old Slavic numbering</p></item>

</ulist>

</div3>

<div3>
<head>Conditionals within a Template</head>

<p>There are two instructions in XSL which support conditional
processing in a template: <code>xsl:if</code> and
<code>xsl:choose</code>. The <code>xsl:if</code> instruction provides
simple if-then conditionality; the <code>xsl:choose</code> instruction
supports selection of one choice when there are several
possibilities.</p>

<div4>
<head>Conditional Processing with <code>xsl:if</code></head>

<p>The <code>xsl:if</code> element has a single attribute,
<code>test</code> which specifies a <termref
def="dt-select-pattern">select pattern</termref>.  The content is a
template.  If the pattern selects a non-empty list of elements,
then the content is instantiated; otherwise nothing is created.  In
the following example, the names in a group of names are formatted as
a comma separated list:</p>

<eg><![CDATA[<xsl:template match="namelist/name">
  <xsl:process-children/>
  <xsl:if test=".[not-last-of-type()]">, </xsl:if>
</xsl:template>]]></eg>

</div4>

<div4>
<head>Conditional Processing with <code>xsl:choose</code></head>

<p>The <code>xsl:choose</code> element selects one among a number of
possible alternatives. It consists of a series of
<code>xsl:when</code> elements followed by an optional
<code>xsl:otherwise</code> element.  Each <code>xsl:when</code>
element has a single attribute, <code>test</code>, which specifies a
<termref def="dt-select-pattern">select pattern</termref>; the test is
treated as true if the pattern selects a non-empty list of elements.
The content of the <code>xsl:when</code> and
<code>xsl:otherwise</code> elements is a template.  When an
<code>xsl:choose</code> element is processed, each of the
<code>xsl:when</code> elements is tested in turn.  The content of the
first, and only the first, <code>xsl:when</code> element whose test is
true is instantiated.  If no <code>xsl:when</code> is true, the
content of the <code>xsl:otherwise</code> element is instantiated. If
no <code>xsl:when</code> element is true, and no
<code>xsl:otherwise</code> element is present, nothing is created.</p>

<p>The following example enumerates items in an ordered list using
arabic numerals, letters, or roman numerals depending on the depth to
which the ordered lists are nested.</p>

<eg><![CDATA[<xsl:template match="orderedlist/listitem">
  <fo:list-item indent-start='2pi'>
    <fo:list-item-label>
      <xsl:choose>
        <xsl:when test='ancestor(orderedlist/orderedlist)'>
          <xsl:number format="i"/>
        </xsl:when>
        <xsl:when test='ancestor(orderedlist)'>
          <xsl:number format="a"/>
        </xsl:when>
        <xsl:otherwise>
          <xsl:number format="1"/>
        </xsl:otherwise>
      </xsl:choose>
      <xsl:text>. </xsl:text>
    </fo:list-item-label>
    <fo:list-item-body>
      <xsl:process-children/>
    </fo:list-item-body>
  </fo:list-item>
</xsl:template>]]></eg>
</div4>
</div3>

<div3 id="stringexpr">
<head>Computing Generated Text</head>

<p>Within a template, the <code>xsl:value-of</code> element can
be used to compute generated text, for example by extracting text from
the source tree or by inserting the value of a string constant.  The
<code>xsl:value-of</code> element does this with a string expression
that is specified as the value of the <code>expr</code> attribute.
String expressions can also be used inside attribute values of literal
result elements by enclosing the string expression in curly brace
(<code>{}</code>).</p>

<div4>
<head>String Expressions</head>

<scrap>
<head>String Expressions</head>
<prod id="NT-StringExpr">
<lhs>StringExpr</lhs>
<rhs><nt def="NT-Pattern">Pattern</nt></rhs>
<rhs>| <nt def="NT-ConstantRef">ConstantRef</nt></rhs>
<rhs>| <nt def="NT-MacroArgRef">MacroArgRef</nt></rhs>
</prod>
</scrap>

<p>The value of a string expression that is a pattern is the character
content of the first node selected by the pattern.  If the first node
is an attribute node, the value is the attribute value.  If the first
node is an element node, the value is computed by concatenating all
characters that are <termref
def="dt-descendants">descendants</termref> of the element node in the
order in which they occur in the document.  The pattern is a <termref
def="dt-select-pattern">select pattern</termref> and so is implicitly
anchored to the current node.</p>

<issue id="issue-resolve-expr"><p>Do we need a
<code>resolve(pattern)</code> string expression that treats the
characters as a relative URI and turns it into an absolute URI using
the base URI of the addressed node?</p></issue>

</div4>

<div4>
<head>Using String Expressions with <code>xsl:value-of</code></head>

<p>The <code>xsl:value-of</code> element is replaced by the value of
the string expression specified by the <code>expr</code> attribute.
The <code>expr</code> attribute is required.</p>

<p>For example, the following creates an HTML paragraph from a
<code>person</code> element with <code>first-name</code> and
<code>surname</code> attributes.</p>

<eg><![CDATA[<xsl:template match="person">
  <P>
   <xsl:value-of expr="attribute(first-name)"/>
   <xsl:text> </xsl:text>
   <xsl:value-of expr="attribute(surname)"/>
  </P>
</xsl:template>]]></eg>

<p>For example, the following creates an HTML paragraph from a
<code>person</code> element with <code>first-name</code> and
<code>surname</code> children elements.</p>

<eg><![CDATA[<xsl:template match="person">
  <P>
   <xsl:value-of expr="first-name"/>
   <xsl:text> </xsl:text>
   <xsl:value-of expr="surname"/>
  </P>
</xsl:template>]]></eg>

<p>The following precedes each <code>procedure</code> element with a
paragraph containing the security level of the procedure.  It assumes
that the security level that applies to a procedure is determined by a
<code>security</code> attribute on an ancestor element of the
procedure. It also assumes that if more than one ancestor has a
<code>security</code> attribute then the security level is determined
by the closest such ancestor of the procedure.</p>

<eg><![CDATA[<xsl:template match="procedure">
  <fo:block>
    <xsl:value-of expr="ancestor(*[attribute(security)])/attribute(security)"/>
  </fo:block>
  <xsl:process-children/>
</xsl:template>]]></eg>

<issue id="issue-inherited-attribute"><p>Unless an element counts as
one of its own ancestors, using
<code>ancestor(*[attribute(security)])/attribute(security)</code>
won't work to get the inherited value of an attribute.  We could
either say <code>ancestor</code> always includes the current node;
alternatively we could provide a variant of <code>ancestor</code> that
does include the current node; alternatively we could provide a select
pattern of the form
<code>inherited-attribute(security)</code>.</p></issue>

</div4>

<div4 id="attribute-value-templates">
<head>Attribute Value Templates</head>

<p><termdef id="dt-attribute-value-template" term="Attribute Value
Template">In an attribute value that is interpreted as an
<term>attribute value template</term>, such as an attribute of a
literal result element, string expressions can be used by surrounding
the string expression with curly braces (<code>{}</code>)</termdef>.
The attribute value template is instantiated by replacing the string
expression together with surrounding curly braces by the value of the
string expression.</p>

<p>The following example creates an <code>IMG</code> result element
from a <code>photograph</code> element in the source; the value of the
<code>SRC</code> attribute of the <code>IMG</code> element is computed
from the value of the <code>image-dir</code> constant and the content
of the <code>href</code> child of the <code>photograph</code> element;
the value of the <code>WIDTH</code> attribute of the <code>IMG</code>
element is computed from the value of the the <code>width</code>
attribute of the <code>size</code> child of the
<code>photograph</code> element:</p>

<eg><![CDATA[<xsl:define-constant name="image-dir" value="/images"/>

<xsl:template match="photograph">
<IMG SRC="{constant(image-dir)}/{href}" WIDTH="{size/attribute(width)}"/>
</xsl:template>]]></eg>

<p>With this source</p>

<eg><![CDATA[<photograph>
  <href>headquarters.jpg</href>
  <size width="300"/>
</photograph>]]></eg>

<p>the result would be</p>

<eg><![CDATA[<IMG SRC="/images/headquarters.jpg" WIDTH="300"/>]]></eg>

<p>When an attribute value template is instantiated, a double left or
right curly brace outside a string expression will be replaced by a
single curly brace.  It is an error if a right curly brace occurs in
an attribute value template outside a string expression without being
followed by a second right curly brace; an XSL processor may signal
the error or recover by treating the right curly brace as if it had
been doubled.  A right curly brace inside an <nt
def="NT-AttributeValue">AttributeValue</nt> in a string expression is
not recognized as terminating the string expression.</p>

<p>Curly braces are <emph>not</emph> recognized recursively inside
string expressions.  For example:</p>

<eg role="error"><![CDATA[<a href="#{id({attribute(ref)})/title}">]]></eg>

<p>is <emph>not</emph> allowed.</p>

</div4>

</div3>

<div3>
<head>String Constants</head>

<p>Global string constants may be defined using a
<code>define-constant</code> element.  The name attribute specifies
the name of the constant, and the <code>value</code> attribute
specified the value.</p>

<p>A stylesheet must not contain more than one definition of a
constant with the same name and same <termref
def="dt-important">importance</termref>.  A definition of a
constant will not be used if there is another definition of a constant
with the same name and higher <termref
def="dt-important">importance</termref>.</p>

<p>String constants are referenced using a <nt
def="NT-ConstantRef">ConstantRef</nt> string expression.</p>

<scrap>
<head>String Constant References</head>
<prod id="NT-ConstantRef">
<lhs>ConstantRef</lhs>
<rhs>'constant' '(' <xnt href="&XMLNames;#NT-NCName">NCName</xnt> ')'</rhs>
</prod>
</scrap>

<eg><![CDATA[<xsl:define-constant name="para-font-size" value="12pt"/>

<xsl:template match="para">
 <fo:block font-size="{constant(para-font-size)}">
   <xsl:process-children/>
 </fo:block>
</xsl:template>
]]></eg>

<issue id="issue-local-constants"><p>Should there be a way to define
local constants?</p></issue>

<p>The <code>value</code> attribute is interpreted as an <termref
def="dt-attribute-value-template">attribute value template</termref>.
If the value of a constant definition <code>x</code> references a
constant <code>y</code>, then the value for <code>y</code> must be
computed before the value of <code>x</code>.  It is an error if it is
impossible to do this for all constant definitions because of
dependency cycles.</p>

</div3>

<div3> <head>Macros</head>

<issue id="issue-macro-name"><p>Should macros be called something
else?</p></issue>

<p>Parts of templates can also be factored out of similar rules
into macros for reuse.  Macros allow authors to create aggregate
result fragments and refer to the composite as if it were a single
object.  In this example, a macro is defined for a boxed paragraph
with the word <quote>Warning!</quote> preceding the contents.  The
macro is referenced from a rule for <code>warning</code> elements.</p>

<eg><![CDATA[<xsl:define-macro name="warning-para">
  <fo:box>
    <fo:block>
      <xsl:text>Warning! </xsl:text>
      <xsl:contents/>
    </fo:block>
  </fo:box>
</xsl:define-macro>

<xsl:template match="warning">
  <xsl:invoke macro="warning-para">
    <xsl:process-children/>
  </xsl-invoke>
</xsl:template>]]></eg>

<p>Macros are defined using the <code>define-macro</code> element. The
<code>name</code> attribute specifies the name of the macro being
defined.  The content of the <code>define-macro</code> element is a
template, called the body of the macro.  A macro is invoked
using the <code>xsl:invoke</code> element; the content of
<code>xsl:invoke</code> is a template.  The name of the macro
to be invoked is given by the <code>macro</code> attribute.  Invoking a
macro first instantiates the content of <code>xsl:invoke</code>. It
then instantiates the body of the invoked macro passing it the result tree
fragment created by the instantiation of the content of
<code>xsl:invoke</code>; this fragment can be inserted in the body of
the macro using the <code>xsl:contents</code> element.</p>

<p>Macros allow named arguments to be declared with the
<code>xsl:macro-arg</code> element; the <code>name</code> attribute
specifies the argument name, and the optional <code>default</code>
attribute specifies the default value for the argument.  Within the
body of a macro, macro arguments are referenced using a <nt
def="NT-MacroArgRef">MacroArgRef</nt> string expression.  It is an
error to refer to a macro argument that has not been declared.  An XSL
processor may signal the error; if it does not signal the error, it
must recover by using an empty string.  Arguments are supplied to a
macro invocation using the code <code>xsl:arg</code> element; the
<code>name</code> attribute specifies the argument name, and the
<code>value</code> attribute specifies the argument value.  It is an
error to supply an argument to a macro invocation if the macro did not
declare an argument of that name.  An XSL processor may signal the
error; if it does not signal the error, it must recover by ignoring
the argument.  The <code>value</code> attribute of
<code>xsl:arg</code> and the <code>default</code> attribute of
<code>xsl:macro-arg</code> are interpreted as <termref
def="dt-attribute-value-template">attribute value templates</termref>;
they can contain string expressions in curly braces as with literal
result elements.</p>

<scrap>
<head>Macro Argument References</head>
<prod id="NT-MacroArgRef">
<lhs>MacroArgRef</lhs>
<rhs>'arg' '(' <xnt href="&XMLNames;#NT-NCName">NCName</xnt> ')'</rhs>
</prod>
</scrap>

<p>This example defines a macro for a <code>numbered-block</code> with
an argument to control the format of the number.</p>

<eg><![CDATA[<xsl:define-macro name="numbered-block">
  <xsl:macro-arg name="format" default="1. "/>
  <xsl:number format="{arg(format)}"/>
  <fo:block/>
    <xsl:contents/>
  </fo:block>
</xsl:define-macro>

<xsl:template match="appendix/title">
  <xsl:invoke name="numbered-block">
    <xsl:arg name="format" value="A. "/>
    <xsl:process-children/>
  </xsl:invoke>
</xsl:template>]]></eg>

<p>It is an error if a stylesheet contains more than one definition of
a macro with the same name and same <termref
def="dt-important">importance</termref>.  An XSL processor may signal
the error; if it does not signal the error, if must recover by
choosing from amongst the definitions with highest importance the one
that occurs last in the stylesheet.</p>

<issue id="issue-macro-arg-syntax"><p>The proposal used the same
element for declaring macro arguments and for invoking them.  Should
these be separate elements and if so what should they be
called?</p></issue>

</div3>
</div2>

<div2>
<head>Style Rules</head>

<p>This section will describe a facility similar to style rules in the
XSL submisson.</p>

<issue id="issue-style-rules"><p>How should style rules
work?</p></issue>

</div2>

<div2>
<head>Combining Stylesheets</head>

<p>XSL provides two mechanisms to combine stylesheets:</p>

<slist>

<sitem>an import mechanism that allows stylesheets to override each
other, and</sitem>

<sitem>an inclusion mechanism that allows stylesheets to be textually
combined.</sitem>

</slist>

<div3 id="import">
<head>Stylesheet Import</head>

<p>An XSL stylesheet may contain <code>xsl:import</code> elements. All
the <code>xsl:import</code> elements must occur at the beginning of
the stylesheet.  The <code>xsl:import</code> element has an
<code>href</code> attribute whose value is the URI of a stylesheet to
be imported.  A relative URI is resolved relative to the base URI of
the <code>xsl:import</code> element (see <specref
ref="base-uri"/>).</p>

<eg><![CDATA[<xsl:stylesheet xmlns:xsl="http://www.w3.org/TR/WD-xsl">
  <xsl:import href="article.xsl"/>
  <xsl:import href="bigfont.xsl"/>
  <xsl:define-attribute-set name="note-style">
    <xsl:attribute-set font-posture="italic"/>
  </xsl:define-attribute-set>
</xsl:stylesheet>]]></eg>

<p><termdef id="dt-important" term="Important">Rules and definitions in
the importing stylesheet are defined to be more <term>important</term>
than rules and definitions in any imported stylesheets.  Also rules
and definitions in one imported stylesheet are defined to be more
<term>important</term> than rules and definitions in previous imported
stylesheets.</termdef></p>

<p>In general a more important rule or definition takes precedence
over a less important rule or definition.  This is defined in detail
for each kind of rule and definition.</p>

<issue id="issue-stylesheet-partition"><p>Should there be an XSL
defined element that can be used to divide a stylesheet into parts,
each of which is treated as if it were separately imported for
precedence purposes?</p></issue>

<issue id="issue-import-source"><p>Provide a way for a stylesheet
to import a stylesheet that is embedded in the document.</p></issue>

<issue id="issue-import-media"><p>Should we provide media-dependent
imports as in CSS?</p></issue>

<ednote><edtext>Say something about the case where the same stylesheet
gets imported twice. This should be treated the same as importing a
stylesheet with the same content but different URIs.  What about
import loops?</edtext></ednote>

</div3>

<div3>
<head>Stylesheet Inclusion</head>

<p>An XSL stylesheet may include another XSL stylesheet using an
<code>xsl:include</code> element. The <code>xsl:include</code> element
has an <code>href</code> attribute whose value is the URI of a
stylesheet to be included.  A relative URI is resolved relative to the
base URI of the <code>xsl:include</code> element (see <specref
ref="base-uri"/>). The <code>xsl:include</code> element can occur as
the child of the <code>xsl:stylesheet</code> element at any point
after all <code>xsl:import</code> elements.</p>

<p>The inclusion works at the XML tree level.  The resource located by
the <code>href</code> attribute value is parsed as an XML document,
and the children of the <code>xsl:stylesheet</code> element in this
document replace the <code>xsl:include</code> element in the including
document.  Also any <code>xsl:import</code> elements in the included
document are moved up in the including document to after any existing
<code>xsl:import</code> elements in the including document. Unlike
with <code>xsl:import</code>, the fact that rules or definitions are
included does not affect the way they are processed.</p>

<ednote><edtext>What happens when a stylesheet directly or indirectly
includes itself?</edtext></ednote>

</div3>

<div3>
<head>Embedding Stylesheets</head>

<p>Normally an XSL stylesheet is a complete XML document with the
<code>xsl:stylesheet</code> element as the document element. However an XSL
stylesheet may also be embedded in another resource. Two forms of
embedding are possible:</p>

<slist>

<sitem>the XSL stylesheet may be textually embedded in a non-XML
resource, or</sitem>

<sitem>the <code>xsl:stylesheet</code> element may occur in an XML
document other than as the document element.</sitem>

</slist>

<p>In the second case, the possibility arises of documents with inline
style, that is documents that specify their own style. XSL does not
define a specific mechanism for this. This is because this can be done
by means of a general purpose mechanism for associating stylesheets
with documents provided that:</p>

<slist>

<sitem>the mechanism allows a part of a resource to be specified as
the stylesheet, for example by using a URI with a fragment identifier,
and</sitem>

<sitem>the mechanism can itself can be embedded in the document, for
example as a processing instruction.</sitem>

</slist>
<p>It is not in the scope of XSL to define such a mechanism.</p>
<note>
<p>This is because the mechanism should be independent of any one stylesheet
mechanism.</p>
</note>
<p>The xsl:stylesheet element may have an ID attribute that specifies a unique
identifier.</p>

<note><p>In order for such an attribute to be used with the
<code>id</code> XPointer location term, it must actually be declared
in the DTD as being an ID.</p></note>

<p>The following example shows how inline style can be accomplished
using the <code>xml:stylesheet</code> processing instruction mechanism
for associating a stylesheet with an XML document.  The URI uses an
XPointer in a fragment identifier to locate the
<code>xsl:stylesheet</code> element.</p>

<eg><![CDATA[<?xml version="1.0"?>
<?xml:stylesheet type="text/xsl" href="#id(style1)"?>
<!DOCTYPE doc SYSTEM "doc.dtd">
<doc>
<head>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/TR/WD-xsl" id="style1">
<xsl:import href="doc.xsl"/>
<xsl:template match="id(foo)">
 <fo:block font-weight="bold"><xsl:process-children/></fo:block>
</xsl:template>
</xsl:stylesheet>
</head>
<body>
<para id="foo">
...
</para>
</body>
</doc>
]]></eg>

<note><p>The <code>type</code> pseudo-attribute in the
<code>xml:stylesheet</code> processing instruction identifies the
stylesheet language, not the content type of the resource of which the
stylesheet is a part.</p></note>

</div3>
</div2>

<div2>
<head>Extensibility</head>

<p>This section will describe an extensibility mechanism for the tree
construction process.</p>

<issue id="issue-construct-extensibility"><p>Should there be some
extensibility mechanism for the tree construction process?  If so, how
should it work?  Should it be language independent?</p></issue>

</div2>

</div1>

&fo;

</body>
<back>
<div1>
<head>DTD for XSL Stylesheets</head>

<p>The following entity can be used to construct a DTD for XSL
stylesheets that create instances of a particular result DTD.  Before
referencing the entity, the stylesheet DTD must define a
<code>result-elements</code> parameter entity listing the allowed
result element types.  For example:</p>

<eg><![CDATA[<!ENTITY % result-elements "
  | fo:sequence
  | fo:block
">]]></eg>

<p>The stylesheet DTD may also need to define additional attributes
for <code>xsl:attribute-set</code>.</p>

<eg><![CDATA[<!ENTITY % instructions "
  | xsl:process-children
  | xsl:process
  | xsl:for-each
  | xsl:value-of
  | xsl:number
  | xsl:choose
  | xsl:if
  | xsl:contents
  | xsl:invoke
  | xsl:text
">

<!ENTITY % template "
 (#PCDATA
  %instructions;
  %result-elements;)*
">

<!ENTITY % space-att "xml:space (default|preserve) #IMPLIED">
 
<!ELEMENT xsl:stylesheet
 (xsl:import*,
  (xsl:include
  | xsl:id
  | xsl:strip-space
  | xsl:preserve-space
  | xsl:define-macro
  | xsl:define-attribute-set
  | xsl:define-constant
  | xsl:template)*)
>

<!ATTLIST xsl:stylesheet
  result-ns NMTOKEN #IMPLIED
  default-space (preserve|strip) "preserve"
  indent-result (yes|no) "no"
  id ID #IMPLIED
  xmlns:xsl CDATA #FIXED "http://www.w3.org/TR/WD-xsl"
  %space-att;
>

<!-- Used for attribute values that are URIs.-->
<!ENTITY % URI "CDATA">

<!-- Used for attribute values that are patterns.-->
<!ENTITY % pattern "CDATA">

<!-- Used for attribute values that are a priority. -->
<!ENTITY % priority "NMTOKEN">

<!ELEMENT xsl:import EMPTY>
<!ATTLIST xsl:import href %URI; #REQUIRED>

<!ELEMENT xsl:include EMPTY>
<!ATTLIST xsl:include href %URI; #REQUIRED>

<!ELEMENT xsl:id EMPTY>
<!ATTLIST xsl:id
  attribute NMTOKEN #REQUIRED
  element NMTOKEN #IMPLIED
>

<!ELEMENT xsl:strip-space EMPTY>
<!ATTLIST xsl:strip-space element NMTOKEN #REQUIRED>

<!ELEMENT xsl:preserve-space EMPTY>
<!ATTLIST xsl:preserve-space element NMTOKEN #REQUIRED>

<!ELEMENT xsl:template %template;>
<!ATTLIST xsl:template
  match %pattern; #REQUIRED
  priority %priority; #IMPLIED
  %space-att;
>

<!ELEMENT xsl:attribute-set EMPTY>

<!ATTLIST xsl:attribute-set
  xsl:use NMTOKENS #IMPLIED
>

<!ELEMENT xsl:process-children EMPTY>

<!ELEMENT xsl:value-of EMPTY>
<!ATTLIST xsl:value-of expr CDATA #IMPLIED>

<!ENTITY % conversion-atts '
   format CDATA "1"
   xml:lang NMTOKEN #IMPLIED
   letter-value (alphabetic|other) #IMPLIED
   digit-group-sep CDATA #IMPLIED
   n-digits-per-group NMTOKEN #IMPLIED
   sequence-src %URI; #IMPLIED
'>

<!ELEMENT xsl:number EMPTY>
<!ATTLIST xsl:number
   level (single|multi|any) "single"
   count CDATA #IMPLIED
   from CDATA #IMPLIED
   %conversion-atts;
>

<!ELEMENT xsl:process EMPTY>
<!ATTLIST xsl:process
  select %pattern; #REQUIRED
>

<!ELEMENT xsl:for-each %template;>
<!ATTLIST xsl:for-each
  select %pattern; #REQUIRED
  %space-att;
>

<!ELEMENT xsl:if %template;>
<!ATTLIST xsl:if
  test %pattern; #REQUIRED
  %space-att;
>

<!ELEMENT xsl:choose (xsl:when+, xsl:otherwise?)>
<!ATTLIST xsl:choose %space-att;>

<!ELEMENT xsl:when %template;>
<!ATTLIST xsl:when
  test %pattern; #REQUIRED
  %space-att;
>

<!ELEMENT xsl:otherwise %template;>
<!ATTLIST xsl:otherwise %space-att;>

<!ELEMENT xsl:define-attribute-set (xsl:attribute-set)>
<!ATTLIST xsl:define-attribute-set
  name NMTOKEN #REQUIRED
>

<!ELEMENT xsl:define-constant EMPTY>
<!ATTLIST xsl:define-constant 
  name NMTOKEN #REQUIRED
  value CDATA #REQUIRED
>

<!-- xsl:macro-arg cannot occur after any other elements or
any non-whitespace character -->

<!ELEMENT xsl:define-macro
 (#PCDATA
  %instructions;
  %result-elements;
  | xsl:macro-arg)*
>

<!ATTLIST xsl:define-macro
  name NMTOKEN #REQUIRED
  %space-att;
>

<!ELEMENT xsl:macro-arg EMPTY>
<!ATTLIST xsl:macro-arg
  name NMTOKEN #REQUIRED
  default CDATA #IMPLIED
>

<!-- This is allowed only within xsl:define-macro -->
<!ELEMENT xsl:contents EMPTY>

<!-- xsl:arg cannot occur after any other elements or
any non-whitespace character -->

<!ELEMENT xsl:invoke
 (#PCDATA
  %instructions;
  %result-elements;
  | xsl:arg)*
>

<!ATTLIST xsl:invoke
  macro NMTOKEN #REQUIRED
  %space-att;
>

<!ELEMENT xsl:arg EMPTY>
<!ATTLIST xsl:arg
  name NMTOKEN #REQUIRED
  value CDATA #REQUIRED
>

<!ELEMENT xsl:text (#PCDATA)>
<!ATTLIST xsl:text %space-att;>
]]></eg>
</div1>

<div1>
<head>References</head>
<div2>
<head>Normative References</head>
<blist>

<bibl id="XML" key="W3C XML">World Wide Web Consortium. <emph>Extensible
Markup Language (XML) 1.0.</emph> W3C Recommendation. See <loc
href="http://www.w3.org/TR/1998/REC-xml-19980210">http://www.w3.org/TR/1998/REC-xml-19980210</loc></bibl>

<bibl id="XMLNAMES" key="W3C XML Names">World Wide Web
Consortium. <emph>Namespaces in XML.</emph> W3C Working Draft. See
<loc
href="http://www.w3.org/TR/WD-xml-names">http://www.w3.org/TR/WD-xml-names</loc></bibl>

</blist>
</div2>
<div2>
<head>Other References</head>

<blist>

<bibl id="CSS2" key="CSS2">World Wide Web Consortium.  <emph>Cascading
Style Sheets, level 2 (CSS2)</emph>.  W3C Recommendation.  See <loc
href="http://www.w3.org/TR/1998/REC-CSS2-19980512"
>http://www.w3.org/TR/1998/REC-CSS2-19980512</loc></bibl>

<bibl id="DSSSL" key="DSSSL">International Organization
for Standardization, International Electrotechnical Commission.
<emph>ISO/IEC 10179:1996.  Document Style Semantics and Specification
Language (DSSSL)</emph>.  International Standard.</bibl>

</blist>

</div2>
</div1>
<inform-div1>
<head>Examples</head>
<p>The following is a simple but complete stylesheet.</p>

<eg><![CDATA[<?xml version='1.0'?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/TR/WD-xsl"
                xmlns:fo="http://www.w3.org/TR/WD-xsl/FO"
                result-ns="fo"
                indent-result="yes">
<xsl:template match='/'>
 <fo:page-sequence font-family="serif">
  <fo:simple-page-master name='scrolling'/>
  <fo:queue queue-name='body'>
   <xsl:process-children/>
  </fo:queue>
 </fo:page-sequence>
</xsl:template>

<xsl:template match="title">
 <fo:block font-weight="bold">
  <xsl:process-children/>
 </fo:block>
</xsl:template>

<xsl:template match="p">
 <fo:block>
  <xsl:process-children/>
 </fo:block>
</xsl:template>

<xsl:template match="emph">
 <fo:sequence font-style="italic">
  <xsl:process-children/>
 </fo:sequence>
</xsl:template>

</xsl:stylesheet>]]></eg>

<p>With the following source document</p>

<eg><![CDATA[<doc>
<title>An example</title>
<p>This is a test.</p>
<p>This is <emph>another</emph> test.</p>
</doc>]]></eg>

<p>it would produce the following result</p>

<eg><![CDATA[<fo:page-sequence xmlns:fo="http://www.w3.org/TR/WD-xsl/FO"
  font-family="serif">
<fo:simple-page-master name="scrolling"/>
<fo:queue queue-name="body">
<fo:block font-weight="bold">An example</fo:block>
<fo:block>This is a test.</fo:block>
<fo:block>This is <fo:sequence
  font-style="italic">another</fo:sequence> test.</fo:block>
</fo:queue>
</fo:page-sequence>]]></eg>

</inform-div1>

<inform-div1>
<head>Design Principles</head>

<p>In the design of any language, trade-offs in the solution space are
necessary.  To aid in making these trade-offs the follow design
principles were used:</p>

<slist>
<sitem>XSL should support browsing, printing, and interactive editing and
design tools</sitem>
<sitem>XSL should be capable of specifying presentations for traditional and
Web environments</sitem>
<sitem>XSL should support interaction with structured information, as well
as presentation of it.</sitem>
<sitem>XSL should support all kinds of structured information, including both
data and documents.</sitem>
<sitem>XSL should support both visual and non-visual presentations.</sitem>
<sitem>XSL should be a declarative language.</sitem>
<sitem>XSL should be optimized to provide simple specifications for common
formatting tasks and not preclude more sophisticated formatting tasks.</sitem>
<sitem>XSL should provide an extensibility mechanism</sitem>
<sitem>The number of optional features in XSL should be kept to a minimum.</sitem>
<sitem>XSL should provide the formatting functionality of <emph>at
least</emph> DSSSL and CSS</sitem>
<sitem>XSL should leverage other recommendations and standards, including
XML, XLL, DOM, HTML and ECMAScript.</sitem>
<sitem>XSL should be expressed in XML syntax.</sitem>
<sitem>XSL stylesheets should be human-readable and reasonably clear.</sitem>
<sitem>Terseness in XSL markup is of minimal importance.</sitem>
</slist>
</inform-div1>
<inform-div1>
<head>Acknowledgements</head>
<p>The following have contributed to authoring this draft:</p>
<slist>
<sitem>Sharon Adler, Inso Corporation</sitem>
<sitem>Anders Berglund, Inso Corporation</sitem>
<sitem>Paul Grosso, ArborText</sitem>
<sitem>Eduardo Gutentag, Sun Microsystems</sitem>
<sitem>Chris Lilley, W3C</sitem>
<sitem>Chris Maden, O'Reilly &amp; Associates</sitem>
<sitem>Jonathan Marsh, Microsoft Corporation</sitem>
<sitem>Henry S. Thompson, University of Edinburgh</sitem>
<sitem>Paul Trevithick, Bitstream</sitem>
<sitem>Norman Walsh, ArborText</sitem>
<sitem>Steve Zilles, Adobe</sitem>
</slist>
</inform-div1>
</back>
</spec>
