XPath Quick Reference

Node Types Nodes can be of the following types:

NodeType Name String Value root Concatenation of alI text nodes in the document element Element name Concatenation of alI text nodes descended from the element attribute Attribute name Attribute value text Text cornrnent Text held within the comment processing Processing Text in the processing instruction after the space after the instruction target targetname narnespace Namespace prefix Namespace URI

Object Types Values in XSLT can be one of the following five types:

Object Type Description boolean true or false number A floating-point number: a double-precision 64-bit format IEEE 754 value Table continued on following page Appendix A

Object Type Description string A sequence of XML characters node set An unordered collection of nodes result tree fragment The root node of a generated node tree

The various object types can be converted to each other by the following rules.

Object Boolean Number String boolean 1 if the boolean is , true' if the boolean is true, O if the true, 'false' if the boolean is false boolean is false number false ifthe A string version of the number is O or number with no leading or NaN, otherwise trailing zeros; 'NaN' if the true number is NaN, , Infinity' if the number is infinity, and '-Infinity' ifthe number is negative infinity string false ifthe The number held string is an empty by the string, as string, otherwise long as it is a valid true XPath number (which doesn't include exponents or grouping separators) ; otherwise NaN

node set true if the node The result of The string value of the first set holds nodes; converting the node in the node set false ifthe string value of the node set is empty first node in the node set to a number result tree true The result of The string value of the re suit fragment converting the tree fragment string value of the re suIt tree fragment to a number

Booleans, numbers, and strings cannot be converted to node sets or result tree fragments.

694 XPath Quick Reference

Paths Paths are made up of a number of steps, separated by / s. Each step is made up of an optional axis (defaults to child), a node test, and any number of predicates (held in square brackets).

Axes Axes dictate the relationship between the context node and the selected nodes. The direction of an axis determines how the posi tion () of a node is calculated - forward axes look at document order, reverse axes look at reverse document order.

Axis Direction Description self Forward Selects the context node itself ehild Forward Selects the children of the context node parent Reverse Selects the parent of the context node attribute Forward Selects the attributes of the context node deseendant Forward Selects the descendants of the context node at any level deseendant- Forward Selects the descendants of the context node, and the or-self context node itself aneestor Reverse Selects the ancestors of the context node aneestor-or-self Reverse Selects the ancestors of the context node, and the context node itself following-sibling Forward Selects the siblings of the context node that follow the context node in document order preeeding-sibling Reverse Selects the siblings of the context node that precede the context node in document order following Forward Selects the nodes (asi de from attribute and namespace nodes) that follow the context node in document order and that are not descendants of the context node preeeding Reverse Selects the nodes (asi de from attribute and namespace nodes) that precede the context node in document order and that are not ancestors of the context node namespaee Forward Selects the namespace nodes on the context node

695 Appendix A

Node Tests Node tests match different kinds of nodes as follows:

Node Test Description node() Matches nodes of all types * Matches elements with any name (or attributes if you're using the attribute axis) name Matches elements with the given name (or attribute if you're using the attribute axis) text( ) Matches text nodes comment () Matches comment nodes processing-instruction() Matches processing instruction nodes processing• Matches processing instruction nodes with the given instruction('target') target

Abbreviated Syntax You can use several abbreviations in XPath expressions, as described in the following table.

Abbreviation Full Equivalent Description self: :node() The context node parent: :node () The parent of the context node II /descendant-or• SuppIies quick access to descendants of the context self: :node () / node @ attribute: : Shortens expressions that access attributes

Operators The operators in XPath can be spIit into four groups:

o Logical operators O Comparisons O Numerical operators O N ode set operators

696 XPath Quick Reference

The precedence of the operators (from lowest to highest) is as follows:

1. or

2. and

3. =, !=

4. <=,<,>=,>

5. +, -

6. *,div,mod

7. unary - 8.

Logical Operators

Operator Description or true if either operand is true when converted to booleans; the right operand is not evaluated if the Ieft operand is true and true if both operands are true when converted to booleans; the right operand is not evaluated ifthe Ieft operand is false

Comparisons

Operator Description Equal to != Not equal to < Less than <= Less than or equal to > Greater than >= Greater than or equal to

Comparisons between node sets and values are true if the comparison is true for the string value of any node in the node set. .

697 Appendix A

The numeric comparisons «, <=, >, and >=) can only be used to do numeric comparisons - you can't use them to test whether one string is alphabetically less than another string.

Numerical Operators

Operator Description + Addition Subtraction * Multiplication div Floating-point division mod Remainder from integer division unary - Negation

Node Set Operator

Operator Description Creates a union of two node sets

Functions XPath and XSLT together define the following functions: boolean() Syntax: boolean boolean (object) See also: string (), number ()

Converts the argument to a boolean value (either true or false). Usually this is done automatically, for example in test attributes. ceiling()

Syntax: number ceiling (number) See also: floor (), round ()

Rounds the argument up to the nearest integer. For negative numbers, this means rounding nearer to 0, so ceiling (-1. 5) is -1.

698 XPath Quick Reference concat() Syntax: string concat (string, string+)

Concatenates the strings passed as arguments into a single string. contains() Syntax: boolean contains (string, string) See also: starts-with ()

Returns true if the string passed as the first argument contains the string passed as the second argument or if the second argument is an empty string, and false otherwise. count() Syntax: number count (node-set) See also: last ( ), posi tion (),

Counts the number of nodes in the node set passed as the argument. current() Syntax: node-set current ( ) See also: the path .

Returns the current node - the node that's current1y being processed within the or as opposed to the context node, which is the node currently being looked at within an XPath. document() Syntax: node-set document (object, node-set?)

If the first argument is a string, returns the node found at the URL specified by that string (usualIy the root node of a document). The URL is resolved relative to the location of the file containing the first node in the node set passed as the second argument (which is usualIy used to resolve the URL relative to the source document). If the second argument is- missing, the URL is resolved relative to the stylesheet itself. If the first argument is a node set, then the result is a node set containing alI the nodes that are retrieved by calling the document () function with the string values of the nodes in the node set. element-available( ) Syntax: boolean element-available (string) See also: function-available ( ),

699 Appendix A

Returns true if the processor supports the extension element or new XSLT instruction named by the string passed as the argument. The string should be a qualified name, with a prefix.

false() Syntax: boolean false ( ) See also: true ( ), boolean ( )

Returns false.

floorO Syntax: number floor (number) See also: ceiling (), round ()

Rounds the number down to the nearest integer. If the number is negative, then it gets rounded away from zero, so floor (-1.5) returns -2. format-number( ) Syntax: string format-number (number, string, string?) See also: number (), ,

Returns the number passed as the first argument formatted according to the format pattern passed as the second argument. The format pattern usually contains # to mean an optional digit, O to indicate a required digit, . to indicate the decimal point, and , to indicate a grouping separator. For example, format-number (1234.5, '#, ##0.00' ) returns 1,234.50. If the third argument is specified, it gives the name of a decimal format, declared with the element, which can de fine other characters to be used instead of #, O, " and function-avai lable() Syntax: boolean function-available (string) See also: element-available ( )

Returns true if the processor supports the function named by the argument string. The string usually includes a prefix to test for the availability of extension functions. generate-id( ) Syntax: string generate-id (node-set?)

Returns an ID for the first node in the node set passed as the argument which is both unique and a valid XML ID. If no argument is given, it returns a unique ID for the context node. The unique IDs are not stable - they are different from processor to processor, and even for the same processor operating over the same stylesheet with the same source XML document.

700 XPath Quick Reference idO Syntax: node-set id (object) See also: key ( )

Retums the nodes with the XML IDs specified by the argument. If the argument is a string, then it's split up at the whitespace, and the function retums aH the nodes in the current document that have any of the IDs. If the argument is a node set, the same is done but with the string values of each of the nodes in the node set. You have to have declared an attribute as an ID function within a DTD for the id ( ) attribute to work, and the context node must be in the same document as the nodes that you want to retrieve. key(}

Syntax: node-set key(string, object) See also: id (),

Retums the nodes that are indexed by the value specified by the second argument in the key named by the first argument. If the second argument is a node set, then aH the nodes with any of the values are retumed. You have to have declared the key with an declaration, and the context node must be in the same document as the nodes that you want to retrieve. langO Syntax: boolean lang (string)

Retums true if the language of the context node (as specified with the : lang attribute) matches the language specified by the argument. This test is aware of sub languages and is case-insensitive, so for example lang ( 'en ') would retum true even ifthe context node's language was specified as EN-US. lastO Syntax: number last () See also: posi tion (), count ( )

Retums the index of the last node in the list that's currently being looked at (or the number of nodes that are currently being looked at, depending on how you like to view it). local-name( }

Syntax: string local-name (node-set?) See also: name (), namespace-uri ()

Retums the local name of the first node in the node set - the part of the name after any prefix that there might be. If no argument is passed, then retums the local name of the context node.

701 Appendix A

name()

Syntax: string name (node-set?) See also: local-name (), namespace-uri ()

Returns the fuB name of the first node in the node set, including the prefix for its namespace as declared in the source document. If no argument is passed, then returns the fuB name of the context node.

namespace-uri( )

Syntax: string namespace-uri (node-set?) See also: name ( ), local-name ( )

Returns the namespace URI for the first node in the node set, or an empty string if the node is in no namespace. If no argument is passed, then returns the namespace URI of the context node. normalize-space( )

Syntax: string normalize-space (string?) See also: string (),

Returns the argument string with leading and trailing whitespace stripped, and any sequences of whitespace converted to single spaces. If no argument string is specified, then it returns the normalized string value of the context node. not()

Syntax: boolean not (boolean) See also: true ( ), false (), boolean ()

Returns false if the argument is true, and true if the argument is false. number()

Syntax: number number (object?) See also: string (), boolean (), format-number (),

Converts the argument to a number; if no argument is given, returns the numerical value of the context node. You don't usually need to use this function because values are converted to numbers automatically if they need to be numbers. position()

Syntax: number posi tion ( ) See also: last (), count (),

702 XPath Quick Reference

Returns the position of the context node amongst the list of nodes that are currentIy being looked at. Unlike the numbers generated through , the posi tion () function depends on the order in which nodes are processed regardless of their original order in the source document.

roundO Syntax: number round (number) See also: floor (), cei ling ()

Rounds the argument number to the nearest integer. If the number is exacdy between two integers, then it rounds up (the same as cei ling ( )). starts-with( ) Syntax: boolean starts-with (string, string) See also: contains ( )

Returns true if the first argument string starts with the second argument string, or if the second argument string is empty, and returns false otherwise.

stringe) Syntax: string string(object?) See also: boolean ( ) , number ( )

Converts the argument to a string; if no argument is given, returns the string value of the context node. You don't normally need to use this function because values are converted to strings automatically if they need to be strings. string-Iength( ) Syntax: number string-length (string?) See also: substring ()

Returns the length of the string passed as the argument. If no argument is passed, then returns the length of the string value of the context node. substring( ) Syntax: string substring (string, number, number?) See also: substring-before (), substring-after ()

Returns a sub string of the first argument string starting from the number passed as the second argument and a number of characters long equal to the third argument number. If the third argument isn't specified, then it returns the rest of the string, to the last character. The first character in the string is numbered 1.

703 Appendix A

substring-after( ) Syntax: string substring-after (string, string) See also: substring-before (), substring ()

Retums the substring of the first argument string that occurs after the second argument string. If the second string is not contained in the first string, or if the second string is empty, then it retums an empty string.

substring-before( ) Syntax: string substring-before (string, string) See also: substring-after (), substring ()

Retums the substring of the first argument string that occurs before the second argument string. If the second string is not contained in the first string, or if the second string is empty, then it retums an empty string.

sum() Syntax: number sum(nade-set)

Retums the sum of the values of the nodes in the node set. If any of the nodes' values isn't numeric, then this function retums NaN. Ifthe node set is empty, it retums O.

system-property( ) Syntax: abject system-property (string) See also: element-available ( ), function-available ( )

Supplies information about the processor that's being used to run the stylesheet. The argument string specifies the kind of information that's retumed. There are three standard arguments:

o xsl: vers ion - the version of XSLT supported by the processor (usually 1. O in current XSLT processors)

O xsl :vendor - the name ofthe vendor ofthe XSLT processor O xsl : vendor-url - a URL for the vendor of the XSLT processor

Processors can support their own system properties. For example, MSXML supports the system property msxs 1 : ver sion which returns the version of MSXML that' s being used. translate( ) Syntax: string translate (string, string, string)

Returns the first argument string with all occurrences of the characters in the second argument string replaced by their corresponding characters in the third string. If a character in the second string doesn't have a corresponding character in the third string, then the character is deleted from the first string.

704 XPath Quick Reference true() Syntax: boolean true ( ) See also: false ( ), boolean ( )

Retums true. unparsed-entity-uri( )

Syntax: string unparsed-enti ty-uri (string)

Retums the URI of the unparsed entity whose name is passed as the argument. Unparsed entities are declared within DTDs as a way of pointing to non-XML files, but they aren't very common nowadays.

705

XSLT Quick Reference

XSLT Elements This section describes each of the XSLT 1.0 elements in alphabetical order. The syntax for each element is shown, followed by a description. Within the syntax descriptions, attributes that are attribute value templates are indicated by curly braces ( { } ) within the attribute value. Required attributes and default values are shown in bold. xsl:apply-imports Syntax:

See also: ,

The instruction tells the XSLT processor to take the current node and try to find a template in an imported stylesheet that (a) is in the same mode as the current template and (b) matches the current node. If the processor locates a template, it uses that template to process the current node; otherwise it uses the default templates.

The instruction must be within an element, and is not allowed as a descendant of an - the current node at the point at which the instruction is used must be the same as the current node of the template it's in. Appendix B

xsl :apply-templates Syntax:

(xsl:sort I xsl:with-param)*

See also: , , , , ,

The instruction tells the processor to gather together a set of nodes and to process each of the nodes by finding a template that matches it and using that template. The nodes that the processor applies templates to are selected by the path held in the select attribute. If the select attribute is missing, then the processor applies templates to the child nodes of the current node.

The nodes are processed in the order determined by the elements that are contained by the instruction. See the description of for details. If there are no elements within the instruction, the processor goes through the nodes in document order (the order in which they appeared in their document).

The only templates that can match the nodes to which the processor applies templates are those whose mode attribute has the same value as the value of the mode attribute on the . If the instruction doesn't have a mode attribute, then the only templates that are applied are those without a mode attribute.

The templates that are used are passed the parameters specified by the elements within the instruction. See the description of for details.

xsl:attribute Syntax:

template

See also: ,

The instruction creates an attribute. When adding attributes to an element, any instructions must come before any instructions that add content to the element. The instruction can also be included within an element; see the description of for details.

708 XSLT Quick Reference

The name of the attribute that's created is determined by its name and namespace attributes. The name attribute gives the qualified name for the attribute and the namespace attribute gives the namespace for the attribute. If the name held in the name attribute doesn't include a prefix and the namespace attribute has a value, then the generated attribute will be given a prefix generated by the XSLT processor.

If the namespace attribute is missing, then the qualified name specified by the name attribute is used to identify the namespace for the attribute - the namespace associated with the qualified name's prefix. If the qualified name doesn't have a prefix, then the attribute is in no namespace.

Both the name and namespace attributes are attribute value templates, so their values can be calculated on the fiy.

The value of the created attribute is the re suIt of processing the content of the instruction. The instructions within the must not generate any nodes aside from text nodes. xsl :attri bute-set Syntax:

xsl:attribute*

See also: , , , xsl: use-attribute-sets

The declaration defines a set of attributes that can then aU be added to an element at once through the use-attribute-sets attribute on or , or the xsl :use-attribute-sets attribute on literal result elements. It is located at the top level of the stylesheet, as a child of .

The name attribute holds the qualified name of the attribute set, by which it can be referred to later ono The element contains a number of elements. The use• a t tribute-sets attribute contains a space-delimited list of the qualified names of other attribute sets. The attributes from the used attribute sets are added to this one. xsl :call-template Syntax:

xsl:with-param*

See also: ,

709 Appendix 8

The instruction calls a template by name. The name of the called template is held in the name attribute. The elements held within the are used to define parameters that are passed to the template. See the description of for more details.

xsl:choose Syntax:

(xsl:when+, xsl:otherwise?)

See also: , ,

The instruction is a conditional construct that causes different instructions to be processed in different circumstances. The XSLT processor processes the instructions held in the first element whose test attribute evaluates as true. Ifnone ofthe elements' test attributes evaluate as true, the content of the element, if there is one, is processed. xsl:comment Syntax:

template

See also:

The instruction generates a comment node. The instructions within the element determine the value of the comment. These instructions must not generate any nodes apart from text nodes, and the text nodes that they generate must not contain two hyphens next to each other ('--'), as this sequence isn't allowed in comments. xsl:coPY Syntax:

template

See also: ,

The instruction creates a shallow copy of the current node. For most nodes, this is equivalent to a deep copy, but for element and root nodes it's slightly different.

710 XSLT Quick Reference

If the current node is an element or root node, the children of the copy are the results of processing the contents of the instruction. If the current node is an element, then any namespace nodes from the original element are copied over. The attributes from the attribute sets named in use• attribute-sets are added to the copied element (along with any attributes that might be added through instructions within the

See also: ,

The instruction creates a deep copy ofwhatever is selected by the expression held in its select attribute. If the expres sion evaluates to a string, number, or boolean, then it creates a text node whose value is that value. If the expres sion evaluates to a node set or a re suit tree fragment, then it creates a deep copy of the nodes in the node set or the result tree fragment. This deep copy includes child nodes, attributes, and namespace nodes. xsl :decimal-format Syntax:

See also: format-number ()

elements de fine methods of interpreting the format pattern strings that are used as the second argument of the format-number () function. They live at the top level of the stylesheet, as children of . There can be many decimal formats, but they must alI have different names, specified by the name attribute. If the name attribute is missing, the decimal format is used as the default decimal format.

When you use the format-number () function, the XSLT processor identifies a decimal format to use to interpret the pattern that you specify as the second argument. Ifthe format-number () function is passed three arguments, the third argument is taken as the name of a decimal format, and that decimal format is used. If the format-number () function is passed two arguments, then the default decimal format is used; if you haven't specified a default decimal format, then the XSLT processor uses one with alI attributes set to their default values. 711 Appendix B

When the XSLT processor formats the number, it looks first to see if it is infinity or not a number. If it is infinity, then the XSLT processor returns the string held in the inf ini ty attribute. If it is not a number, then the XSLT processor returns the string held in the NaN attribute.

If the number is a number, and not infinity, the XSLT processor has to format it according to the pattern string passed as the second argument of format-number () and the decimal format that is identified. The processor splits the pattern into a positive pattern and a negative pattern at the character held by the pattern-separator attribute, which defaults to the semicolon character (;). The minus sign is indicated by the character held by the minus-sign attribute, which defaults to the hyphen character (-), within the negative pattern. If there's no negative pattern, then it defaults to the same as the positive pattern, prefixed by the character held in the minus-sign attribute ofthe decima! format.

If the pattern contains the character held by the percent attribute (which defaults to the percent character, %), then the number being formatted is multiplied by 100 prior to formatting, and that character is included as specified by the pattern. If the pattern contains the character held by the per• mille attribute (which defaults to the per-mille character, 80 or  030;), then the number being formatted is multiplied by 1000 prior to formatting, and that character is included as specified by the pattern.

The remaining pattern string is interpreted to indicate how many digits should occur before and after the decimal point and if the digits should be grouped, and if so what by. Within the pattern, essential digits are indicated by the character held in the zero-digit attribute (which defaults to the zero character, O), and optional digits are indicated by the character held in the digit attribute (which defaults to the hash character, #). The decimal point is the character held in the decimal-point attribute of the decimal format (which defaults to the period character, .). Groups of digits are separated by the character held in the grouping-separator attribute (which defaults to the comma character, ,). xsl :element Syntax:

template

See also:

The instruction creates an element. The name of the element that's created is determined by its name and namespace attributes. The name attribute gives the qualified name for the element and the namespace attribute gives the namespace for the element. If the namespace attribute is missing, then the qualified name specified by the name attribute is used to identify the namespace for the element - the namespace associated with the qualified name's prefix, or the default namespace if it doesn't have a prefix. Both the name and namespace attributes are attribute value templates, so their values can be calculated on the fIy - in fact, this is the only reason you should use rather than a literal re suit element.

Ifthe use-attribute-sets attribute is present, then the attributes held in the attribute sets named within this attribute are added to the created element. Other attributes and the content of the element are generated as the result of processing the content of the instruction.

712 XSL T Quick Reference xsl:fallback Syntax:

template

The element provides alternative processing in the event that an implementation does not support a particular element. When an XSLT processor comes across an instruction that it doesn't understand (such as an XSLT 2.0 instruction or an extension element), it looks for an element amongst its children. If it finds one, it processes the content of that element; if it doesn't, it stops processing and the transformation fails. xsl :for-each Syntax:

(xsl:sort, template)

See also: ,

The instruction tells the XSLT processor to gather together a set of nodes and process them one by one. The nodes are selected by the expres sion held in the select attribute. If there are any elements, these change the order in which the nodes are processed; ifthere aren't any, then they are processed in document order. Each of the nodes is then processed according to the instructions held in the after any elements. xsl:if Syntax:

template

See also: ,

The instruction performs some conditional processing. The content of the is only processed if the expression held in its tes t attribute evaluates to boolean true. xsl:import Syntax:

713 Appendix B

See also: ,

The element imports a stylesheet into this one. This gives you access to aU the declarations and templates within that stylesheet, and aUows you to override them with your own if you need to. The href attribute gives the location of the imported stylesheet. Any elements must be the very first elements within the stylesheet, the first children of the document element.

xsl:include Syntax:

See also:

The element includes a stylesheet in this one. This gives you access to aU the declarations within that stylesheet, exact1y as if they had been specified in your stylesheet. The href attribute gives the location of the included stylesheet. The element is a top-Ievel element, and must appear as a direct child of the document element.

xsl:key Syntax:

See also: key ( )

The element declares a key, which indexes aU the nodes in a document by a particular value. Each key is identified by its name attribute. The nodes that are indexed by a key are those that match the pattern held in its ma tch attribute.

The value by which each node is indexed is specified through the use attribute. The expression held in the use attribute is evaluated for each matched node. If it results in a string, number, or boolean, then that value is used to index the node. If the expression evaluates as a node set, then there are multiple entries for the matched node, one for each of the selected nodes, using the string value of each of those nodes. This enables you to access a node through multiple values using the key () function.

The elements are top-Ievel elements, direct children of the document element. There can be multiple keys with the same name within a stylesheet; they are combined for the purpose of retrieving nodes using the key () function.

714 XSL T Quick Reference xsl:message Syntax:

template

The instruction sends a message to the XSLT processor, which will usually forward the message on to the person running the transformation. If the terminate attribute is present with the value yes, then the transformation ends with the error message, otherwise it continues. The content of the instruction provides the message itself. xsl :namespace-alias Syntax:

The element tells the XSLT processor that a namespace as used in the stylesheet should be substituted by another namespace in the result tree. This is usually used when creating stylesheets that create stylesheets: a namespace alias enables you to create the XSLT elements for the result as literal result elements, without the XSLT processor confusing them with instructions that it should follow.

The stylesheet-prefix attribute holds the prefix associated with the alias namespace within the stylesheet. The resul t-prefix attribute holds the prefix associated with the namespace that should be used instead, in the result (which is usually xsl when generating XSLT). The keyword #defaul t can be used to indicate the default (unprefixed) namespace in either attribute. xsl:number Syntax:

See also: format-number (), posi tion ()

715 Appendix B

The instruction inserts a number into the result tree. The instruction actually has two roles: generating a number and formatting that number.

By default, generates a number based on the position of the current node amongst its similarly named siblings within the source XML document. You can control what number is generated more precisely using the level, count, and from attributes. The level attribute determines what kinds of numbers are generated. The value single numbers nodes amongst their siblings. The value any numbers nodes throughout the source tree. The value mul tiple creates multilevel numbering based on the hierarchical structure of the source tree. Only nodes that match the pattern held in the count attribute will be counted when creating a number. The from attribute holds a pattern matching the node from which numbering should start afresh.

If you already know the number that you want, you can use the val ue attribute to specify the number directly, rather than using the number-generating aspect of .

The number is formatted according to the format pattern held in the format attribute. This works in a different way from the format pattern used by the format-number () function, because it's used to number integers rather than decimal numbers.

The format pattern can hold any punctuation characters and placeholders that indicate where the number should be included and in what format. There are five standard placeholders: 1 for decimal numbers, a for lowercase alphabetical numbers, A for uppercase alphabetical numbers, i for lowercase Roman numbers, and I for uppercase Roman numbers. Processors can support other numbering schemas as well. The lang and letter-value attributes help the processor decide which alphabet and numbering scheme to use.

If the number is large, then the digits may be grouped into groups of the size specified by the grouping• size attribute and separated by the character specified by the grouping-separator attribute.

xsl :otherwise Syntax:

template

See also: ,

The element appears only within an element, containing the instructions that are processed if none of the expressions held in the tes t attributes of the elements evaluate as true.

716 XSL T Quick Reference xsl:output Syntax:

The element descrihes how the result of the transformation should he serialized into a file. The method attrihute has the most effect on the serialization, determining whether the stylesheet creates XML, text, HTML, or some other format defined hy a processor implementer. The media• type and version attrihutes give tighter definition ahout the format heing generated.

The encoding attribute determines the character encoding used during serialization, and defaults to UTF-8 or UTF-16. The indent attrihute determines whether whitespace-only text nodes are added to the result tree in order to make it easier to read; this is yes hy default for HTML and no hy default for XML.

The doctype-public and doctype-system attrihutes hold the puhlic and system identifiers for the result, which are included in a DOCTYPE declaration at the top of the generated file.

When generating XML, a processor wiH add an XML declaration at the start of the output, unless the omi t-xml-declaration attrihute is present with the value yes. Even if this attrihute is present, the XML declaration wiH stiH be added if the encoding is something other than UTF-8 or UTF-16, or if the standalone attribute is present (in which case the XML declaration contains a standalone pseudo• attribute with the specified value).

The cdata-section-elements attribute lists the names of elements in the result whose text content should he wrapped within CDATA sections.

The element should appear at the top level of the stylesheet, as a child of the document element. There can be multiple elements in a stylesheet, in which case they are comhined on an attrihute-hy-attrihute hasis; it is an error for more than one element to specify the same attrihute with different values. xsl:param Syntax:

template

717 Appendix B

See also: , ,

The element declares a parameter for a template (if it's within a template) or for the stylesheet as a whole (if it's at the top level of the stylesheet). The name attribute holds the name of the parameter. The select attribute or the content of the element holds the default value for the parameter, which will be used if no value is explicitly pas sed in to the stylesheet or template for that parameter. It is an error to specify both a select attribute and some content; use the select attribute if you can, otherwise you'll create a result tree fragment. xsl :preserve-space Syntax:

See also:

The element specifies the elements whose child whitespace-only text nodes should be preserved within the source node tree. The elements attribute holds a whitespace-separated list of name tests (which can include specific names, or * to mean any element, for example). Whitespace-only text nodes are preserved by default, so this element is only required if has been used to strip whitespace-only text nodes from the node tree. xsl:processing-instruction Syntax:

template

See also:

The instruction creates a processing instruction whose target is the name held in the name attribute and whose value is the result of processing the template that it contains. The content ofthe element must not result in the generation of any nodes aside from text nodes, and the text nodes that it generates must not contain the string , ? > ' . xsl:sort Syntax:

718 XSLT Quick Reference

See also: ,

The element specifies a method of sorting a set of nodes. For each of the nodes selected in the surrounding or instruction, the element creates a sort key by evaluating the expres sion held in the select attribute with the node as the current node and converting it to a string. The nodes are then sorted according to this sort key and the other attributes on the element.

The data-type attribute determines whether the nodes are sorted by their sort key in alphabetical order (text), in numeric order (number), or in some other order supported by the implementation. The order attribute determines whether the nodes are sorted in ascending order or descending order. The lang and case-order attributes are used ifit's an alphabetical sort; the default language is determined from the system environment, while the case ordering (whether uppercase letters are sorted before lowercase letters or vice versa) is based on the language being used.

If there are multiple elements, then they define sub-sort keys on which nodes are sorted only if they have the same value for their sort key according to the previous sort. xsl :stri p-space Syntax:

See also: , normalize-space ()

The element specifies the elements whose child whitespace-only text nodes are· removed from the node tree when it is created. The elements attribute holds a whitespace-separated list of name tests (which can include specific names, or * to mean any element, for example). The element can override this specification. xsl :stylesheet Syntax:

(xsl:import*, top-level-elements)

See also:

The element is the document element for a stylesheet, and holds an the top-Ievel elements such as global variable and parameter declarations, templates, decimal format and attribute set definitions, key declarations, output declarations, and so ono Any elements that the stylesheet contains must come before anything else within the element. 719 Appendix B

The element must have a version attribute indicating the version of XSLT being used, which for now should always be 1. O. Ifyou're embedding a stylesheet within an XML document, the id attribute can be used as an identifier so that you can point to the stylesheet.

The extension-element-prefixes attribute lists the prefixes ofnamespaces that are used for extension elements. The exclude-result-prefixes attribute lists the prefixes ofnamespaces that shouldn't be included in the result document, which are usually those namespaces that are used in the source XML document. xsl:template Syntax:

(xsl:param*, template)

See also: ,

The element declares a template. Templates can be used in two ways within a stylesheet - they can be applied to nodes or they can be called by name. Each template must specify either a match attribute, so that it can be applied to nodes, or a name attribute, so that it can be called by name.

When templates are applied to a node set using , they might be applied in a particular mode; the mode attribute on indicates the mode in which templates need to be applied for this template to be used. If templates are applied in the relevant mode, then the match attribute is used to determine whether the template can be used with the particular node. The ma tch attribute holds a pattern against which nodes are matched. If a node matches the pattern, then the template can be used to process that node. If there's more than one template that matches a node in the specified mode, then the priority attribute is used to determine which one should be used - the highest priority wins. If no priority is specified explicitly, the priority of a template is determined from its match pattern.

Whether templates are applied or called, they can be passed parameters through the element. To receive a parameter, however, the template must contain an element that declares a parameter of that name. These parameters are given before the body of the template, which is used to process the node and create a result. xsl:text Syntax:

text

720 XSL T Quick Reference

The element is used to add some text to the re suIt tree. Unlike elsewhere within an XSLT stylesheet, whitespace-only text nodes within elements are included, so is the only way to add whitespace-only text nodes to the result tree (aside from those automatically added if you tell the processor to indent the output using the inden t attribute on element is also useful for limiting the amount of space that's included around text when it's added to the re suit.

Ifthe disable-output-escaping attribute is specified with the value yes then the content ofthe element is output without special characters such as < and & being escaped with &1 t; or &. xsl :transform Syntax:

(xsl:import*, top-level-elements)

See also:

The element is an alias for ; see the definition of for details. xsl:value-of Syntax:

See also:

The instruction adds the string value of the selected expres sion to the re suit tree. The select attribute holds the expression that's evaluated. If the re suit is a node set, then adds the string value of the first node in that node set; none of the structure of the node is preserved (you need for that).

Ifthe disable-output-escaping attribute is specified with the value yes then the value is output without special characters such as < and & being escaped with &1 t; or &.

721 Appendix B xsl:variable Syntax:

template

See also:

The element declares a variable. If the element appears at the top level of the stylesheet, as a child of the document element, then it is a global variable with a scope covering the entire stylesheet. Otherwise, it is a local variable with a scape of its following siblings and their descendants.

The name attribute specifies the name of the variable. After declaration, the variable can be referred to within XPath expressions using this name, prefixed with the $ character.

The value of the variable is determined either by the select attribute or by the contents of the element. It is an error to have both a select attribute and some content. If you can, use the select attribute to set the variable; otherwise the variable holds a result tree fragment. xsl:when Syntax:

template

See also: , ,

The element appears within an instruction and specifies a set of processing that could occur and the condition when it occurs. The XSLT processor processes the content of the first within the whose test attribute contains an expression that evaluates as true. xsl:with-param Syntax:

template

See also: , , 722 XSL T Quick Reference

The element specifies the value that should be passed to a template parameter.1t can be used when applying templates with or calling templates with . The name attribute holds the name of the parameter for which the value is being passed.

The value of the parameter is determined either by the select attribute or by the contents of the element. It is an error to have both a select attribute and some content. If you can, use the select attribute to set the parameter; otherwise the parameter will be passed a result tree fragment as its value.

XSLT Attributes There are four attributes from the XSLT namespace that can be added to any literal result element. xsl :extension-element-prefixes Syntax:

template

See also:

The xs 1 : extension -elemen t -pref ixes attribute lists the prefixes of namespaces that are being used for extension elements. This works exact1y like the extension-element-prefixes attribute on , but only within the scope of the literal result element. xsl:exclude-result-prefixes Syntax:

template

See also:

The xsl : exclude-resul t-prefixes attribute lists the prefixes of namespaces that should not be included within the result tree. This works exact1y like the exclude-result-prefixes attribute on , but only within the scope ofthe literal result element.

723 Appendix B

xsl:use-attribute-sets Syntax:

template

See also: , ,

The xsl : use-attribute-sets attribute lists the names of attribute sets that contain attributes that should be added to the literal result element, in exactly the same way as the use-attribute-sets attribute works with and .

xsl :version Syntax:

template

See also:

The xsl : vers ion attribute specifies the version of XSLT that is being used within its content (which is currently always 1. O). This attribute is required on the document element of simplified stylesheets, which have a literal result element as their document element.

724 XSlT Quick Reference

725

10015

XSLT Processors

Saxon http://saxon.sou rceforge. net!

o Java (and "instant" version) O 6.5.1 supports XSLT 1.0/1.1 O 7.0 has limited support for XSLT 2.0 O lots of extension elements and functions

O supports user-defined extension functions in XSLT andJava

O supports TrAX GAXP 1.1 conformant)

Xalan-J http://xml.apache.org/xalan-j/

O Java O current version 2.3.1 O several extension elements and functions O supports user-defined extension functions through Bean Scripting Framework

O supports TrAX GAXP 1.1 conformant) Appendix C

MSXML http://msdn.microsoft.com/xml

o C++ o MSXML3 supports XSLT 1.0 (and WD-xsl) O MSXML4 supports XSLT 1.0 and XML Schema (adds some extensions) O supports user-defined extension functions inJScript,JavaScript, VBScript O some extension elements and functions

Other XSLT Processors

O 4XSLT (Python) - http://4suite.org/ O DGXT (Java) - http://www.datapower.com/products.shtml#dgxt O EZ/X - http://www.activated.com/products/products.html O FastXML (C++) - http://www.geocities.com/fastxml/ O jd.xslt (Java) - http://www.aztecrider.com/xsltl O libxslt (C++) - http://xmlsoft.org/XSLT

O Napa - http://homepage.ntlworld.com/kjjones/ O MDC-XSL (C++) - http://mdc-xsl.sourceforge.netl O OracleXSLT (Java, C, C++) - http://technet.oracle.com/tech/xml/ O Sablotron (C++) - http://www.gingerall.com/charlie/ga/xml/p_sab.xml O TransforMiiX (C++) - http://www.mozilla.org/projects/xsltl O Unicorn XSLT Processor (C++) - http://www.unicorn-enterprises.com/products_uxt.html O Xalan-C (C++) - http://xml.apache.org/xalan-c/ O xesalt (C++) - http://www.inlogix.de/products.html O XMLPartner (C++) - http://www.turbopower.com/products/xmlpartner/ O XML::XSLT (Perl) - http://xmlxslt.sourceforge.netl O XSLJIT (Java)· - http://www.xsljit.com/

O XSLTC (Java)· - http://xml.apache.org/xalan-j/xsltc_usage.html O xt (Java) - http://www.jclark.com/xml/xt.html

• XSLJIT and XSLTC are both compilers rather than interpreters like the rest of the XSLT processors. They compile the XSLT stylesheet intoJava byte code, and you then run thoseJava programs over your XML documents to do the transformation.

728 Tool5

XSLT Editors

Extensions to Other Editors

Vis ual XSLT http://www.activestate.com/ProductsNisua.-X5LT /

o plug-in for Visual Studio .NET O syntax highlighting O auto-completion O preview of the re suit of running the stylesheet (with either the System.xsl .NET component or Xalan) O browsers for navigating through the stylesheet O breakpoints in the source document or the stylesheet O te sting XPath expressions

XSLAtHome http://www.vbxml.com/xslathome/

o plug-in for Macromedia's HomeSite web development tool O syntax highlighting O auto-completion O reformatting

O running XSLT processors

O testing XPath expressions

XSlide http://www.menteith.com/xslide/

o major mode for emacs O syntax highlighting O auto-completion O processing XML files with xt and Saxon

729 Appendix C

XSLT-Process http://xslt-process.sourceforge.netlindex.php

o minor mode for emacs o process XML files with Saxon, Xalan, and otherJava-based XSLT processors O view the results within emacs, within a web browser, or as PDF via FOP O set breakpoints in the source or the stylesheet O watch local and global variables

Mapping Tools

CapeStudio http://capeclear.com/products/capestudio/

O supports mapping from value to value with tables O includes XPath editor for more complicated mappings

Whitehlll Composer http://www.whitehill.com/Products/xslcomposer/

O visual editor for XML to HTML transformations

XMapper http://www.nalasottware.com/DOCS/Xmapper/overview.cfm

O web-based mapping tool

XSLWiz http://www.induslogic.com/products/products2.html

O graphical "funclets" to merge or split information

O supports grouping in mappings

XSLerator http://www.alphaworks.ibm.com/tech/xslerator

O written inJava

730 Tools

Basic Editors

XFlnlty Deslgner http://www.b-bop.com/products_xfinity_designer.htm

o automatic generation of XPaths O integrated HTML viewer for result

XL-5tyler http://www.seeburger.de/xml/

O syntax highlighting O auto-eompletion

O integrated HTML viewer for result

XTrans http://www.simx.com/pub/XTrans/

O syntax highlighting O built-in XPath evaluator O integrated HTML viewer for re suIt

Integrated Development Environments

Cooktop http://xmleverywhere.com/cooktop/

o supports transformations with a whole range of XSLT proeessors O syntax highlighting O some debugging support O ehat with other Cooktop users over the Internet

Komodo http://aspn.activestate.com/ASPN/Downloads/Komodo/

O supportsJavaSeript, Perl, Python, and other languages as well as XSLT O syntax highlighting O auto-eompletion

731 Appendix C

o set breakpoints in the source and stylesheet O view or change global or local variables and parameters

MarrowSoft Xse/erator http://www.vbxml.com/xselerator/default. asp

O syntax highlighting O auto-completion O set breakpoints in the source or stylesheet O step through XSLT instructions O view the values of variables and parameters

Stylus Studio http://www.stylusstudio.com/

O syntax highlighting O auto-completion O construct simple stylesheets based on mappings O set breakpoints O step through, into, and over instructions

O view the values of parameters and variables

XMLOr/g/n http://www.xmlorigin.com/

O syntax highlighting O auto-completion O set breakpoints O supports processing with Xalan, MSXML 3, MSXML 4, and Napa O step through, into, and over instructions O view the values of parameters and variables O watch the results of XPath expressions

732 Tool5

XMLSpy http://www.xmlspy.com/

Q syntax highlighting

Q auto-completion

Q XSLT Designer (bought separately) gives a drag-and-drop interface for construction of HTML pages from an XML document

XSLT Support Tool5

XPath Constructors

XPath 1.0: Interactive Expression Builder http://staff.develop.com/aarons/bits/xpath-builder/

Q web or offline as a browser-based tool

Q dynamically highlights the selected nodes in a source view of an XML document

XPath Tester http://www.fivesight.com/downloads/xpathtester.asp

Q Java-based tool (uses Xalan:J)

Q displays selected nodes within an XML document displayed as a tree structure

XPath Visuailzer http://www.vbxml.com/xpathvisualizer/

Q browser-based tool O evaluate any XPath expres sion (not only location paths)

Q highlights the relevant nodes in a source document

Q set up keys and variables

XSL T Debuggers

XSLDebugger http://www.vbxml.com/xsldebugger/

733 Appendix C

o integrated with XPath Visualizer o step through stylesheet, source, and result in parallel O view the values of parameters and variables

XSL Trace http://www.alphaworks.ibm.com/tech/xsltrace

O Java-based XSL debugger (uses Xalan:J) O step through stylesheets while viewing the source and result O set breakpoints on the source or stylesheet

Zvon XSL Tracer http://www.zvon.org/xxl/XSLTracer/Output!introduction.html

O Perl-based tool (uses Saxon) O step through a transformation with the stylesheet alongside either the source or the result

XSL T Profilers

CatchXSL http://www.xslprofiler.org/

o provides detailed profile of stylesheet performance O uses Saxon or Xalan

XSL Unt http://www.nwalsh.com/xsl/xslint/

o checks stylesheets for basic omissions

XSLT Test Tool http://www.netcrucible.com/xslt/xslt-tool.htm

o runs stylesheets with multiple XSLT processors

XSLTMark http://www.datapower.com/XSLTMark/

o provides benchmarking for XSLT processors

734 Tool5

XSLTUnit http://xsltunit.org/

Q provides unit-testing environment for XSLT

Documentation Generation

XSLDoc http://www.xsldoc.org/

Q generatesJavadoc-style documentation for stylesheets XSLTDoc http://grillade.griotte.com/xml/xsltdoc/xsltdoc.html

Q generates an HTML page summarizing the stylesheet XSLTDoc http://www.jenitennison.com/xsltlutilities

o displays explanation of stylesheet, including automatically-generated descriptions of XPaths

XSLT-Enabled Browsers

Antenna House XSL Formatter http://www.antennahouse.com/

O uses MSXML3 O expects transformation result to be XSL-FO

Internet Explorer http://www.microsoft.com/ie

o uses MSXML3.0 (lE 6.0, or lE 5.0+ if MSXML3 installed in replace mode) O expects transformation result to be HTML

735 Appendix C

Mozilla http://www.mozilla.org

o uses TransforMiix o expects transformation result to be HTML

Netscape http://browsers. netscape .com/

o uses TransforMiix o expects transformation re suit to be HTML

XSmiies http://www.xsmiles.org/

o usesJAXP-compatible processor (default Xalan) o expects transformation result to be XHTML, XSL-FO, SMIL, SVG, or XForms

Server Side Support

AxKit http://www.axkit.org/

o Apache module O uses Sablotron or libxslt

Cocoon http://xml.apache.org/cocoon

o Java servlet O usesJAXP-compatible processor (default Xalan)

736 Tools

UWOBO http://www.cs.unibo.itlhelm/uwobo/

o Java servlet O uses Xalan

XSQL http://otn.oracle.com/tech/xml/xdk-.Java

O Java servlet over SQL database O uses Oracle's XSLT processor

737

Index

A Guide to the Index The index is arranged hierarchically, in alphabetical order, with symbols preceding the letter A. Most second-Ievel entries and many third-Ievel entries also occur as first-Ievel entries. This is to ensure that users will find the information they require however they choose to search for it.

accesslng start t!me example Symbols following-sibling:: axis, 282 . operator, 222 parent:: axis, 282 ! = operator, 169 selecting nodes, 281 & element, 282 escaping characters using entities, 36 addParameter() method &apos Processor object, 572 escaping characters using entities, 36 alphabets > formatting numbers in different alphabets, 353 escaping characters using entities, 36 iterating alphabet string recursive templates, 423 &!t creating alphabetical indexes example, 424 escaping characters using entities, 36 ancestor nodes " representing XML as node tree, 108 escaping characters using entities, 36 using in conditional processing, 155 * name test, 266 ancestor:: axls using XPath to validate XML, 638, 639, 641 location paths, 274 * operator, 222 ancestor·or·self:: axls I operator location paths, 274 location paths, 272 anchors + operator, 222 hypertext links, 379 < operator, 169 Antenna House Formatter <= operator, 169 client-side transformations, 534 = operator, 169 ASP > operator, 169 script for generating HTML, 14 async property > = operator, 169 Document object, 561 ATTLlST declaratlon ID attributes, 363 A attrlbute nodes, 108 adding nodes to result tree, 308 element, 379 attribute sets, 313 compared to element, 601 conditional value attributes, 311 href attribute, 379 optional attributes, 309, 310 id attribute, 379 element, 308 name attribute, 379 attrlbute sets SVG, 601 adding nodes to result tree, 313 transform attribute, 601 element, 313 xlink:href attribute, 601 XSL-FO,313 about attrlbute attrlbute value templates description elements, RDF, 665 dynamic element names, 293 element, 665 namespace declarations, 301 absolute paths flexible node sort order, 340 compared to relative paths, 91 attribute value templates (continued)

attrlbute value templates (contlnued) sending XML to Internet Explorer, 550 generating attribute values, 97 buUt-ln moded templates example,97 processing same node differently in different select attribute, 97 contexts, 146 generating processing instructions, 314 example of using, 146 generating XML from XHTML, 296 buUt-ln templates limitations, 97 built-in moded templates, 146 attrlbute:: axls example of using, 146 location paths, 272, 274 conditional processing, 156 step patterns, 260 matching templates to nodes, 118 attrlbutes, 723 example of using, 119 attributes using XPath, 191 select attribute, 191 test attribute, 191 changing attributes to elements, 26 c choosing between elements and attributes 52 calculatlng numeric recursive templates, 414 designing markup languages, 52 ' compared to extension functions, 416 extension attributes, 496 infinite recursion, avoiding, 414 extensions to attribute values, 491 parameters and, 414 generating attribute values, 96 element, 415, 416 attribute value templates, 97 camel case HTML attributes, 10 naming conventions, XML, 50, 51 pseudo attributes, 39 testing for in conditional processing, 165 carrlage return character example, 166 whitespace characters, 253 location paths, 165 Cascadlng Style Sheets using XPath to validate XML, 646 see CSS. name() function, 647 case Insensltlve searches example string value of node, validating, 648 containsO function, 220 XML attributes, 35 string expressions, XPath, 220 xml:base attribute, 35 translateO function, 220 xml:lang attribute, 35 element, 220 xml:space attribute, 35 case sensltlvlty of XML, 32 XSLT,723 case-order attrlbute axes, XPath, 695 element, 334 ancestor:: axis, 274 CDATA sectlon, 43 ancestor-or-self:: axis, 274 output escaping, disabling, 320 attribute:: axis, 260, 272, 274 cdata-sectlon-elements attrlbute child:: axis, 260, 272, 274 element, 323 descendant:: axis, 274 cellingO functlon, 222, 698 descendant-or-self:: axis, 274 channels following:: axis, 275 describing channels, 669 following-sibling:: axis, 274 RSS document, 668 forward axes, 273 character references location paths, 272 representing characters in XML using Unicode, 36 namespace:: axis, 274 example,37 parent:: axis, 274 characters, XML, 36 preceding:: axis, 275 escaping characters using entities, 36 preceding-sibling:: axis, 274 &,36 reverse axes, 273 &apos,36 self:: axis, 274 >, 36 step patterns, 260 &It, 36 AxKlt ",36 server-side transformations, 533 representing characters in XML using Unicode, 36 character references, 36 chUd nodes representing XML as node tree, 108 B chUd:: axls bltmaps location paths, 272, 274 compared to vector graphics, 583 step patterns, 260 boolean data type Choose statements XML Schema, 61 element, 163 example, 164 boolean expresslons, XPath, 191 element, 163 booleanO functlon, 173, 698 element, 163 Browser Selector element, SVG, 585, 587 pipelines, Cocoon, 541 cx attribute, 585, 592 using different stylesheets for different browsers, 548 cy attribute, 585, 592 element, 549 r attribute, 585, 592 740 containsO function

cl ..s attrlbute comment() node test HTML elements, 12 testing type of node, 244 separating content and presentation, 12 using XPath to validate XML, 639 client-si de transformatlons comments advantages and disadvantages, 534 XML , 41 Antenna House Formatter, 534 comparlson operators, 697 compared to server-side transformations, 535 concat() functlon, 699 DOM,560 generating complex identifiers, 654 checking for parse errors, 562 generating XML from XHTML, 296 creating Document objects, 560 indexing using keys and XPath, 375 creating Processor objects, 567 multHevel grouping, 388 creating Template objects, 566 parsing dates and times example, 216 flags, 561 parsing durations and calculating end times example, 224 loading XML document, 562 string expressions, XPath, 215 dynamic XSLT transformations, 532, 533 concepts hand ling output, 571 compared to properties, 52 continuing processing, 571 replacing part of page, 571 condltlonal processlng, XSL T, 153 Internet Explorer, 534 ancestor nodes, using in processing, 155 Mozilla, 534 attributes, testing for, 165 MSXML, 73, 559 example, 166 location paths, 165 Netscape, 534 built-in templates, using in processing, 156 script for transformations, 534 MSXML, 560 elements, testing for location paths, 161 using parameters in stylesheets, 572 example, 573 introduction, 153 xml-stylesheet processing instruction and, 534 moded templates, using in processing, 156 MSXML,559 example, 158 transforming XML by Internet Explorer, 552 optional elements, processing, 154 XSmiles, 534 example, 157 closepath command, SVG, 595 values, comparing, 168 combining functions and operators, 178 Cocoon comparing node sets and values, 170 configuring, 541 example, 171, 174, 177, 179 creating sul>-sitemap, 545 testing string contents, 176 defining components, 542 testing strings and numbers, 173 defining pipelines, 543 XPath functions, 172 element, 541, 542 XPath operators, 168 element, 541, 543 XML, filtering, 181 element, 541 example, 182 sitemaps, 541 predicates, 181 using different stylesheets for different browsers, 548 element, 163 sending XML to Internet Explorer, 550 example, 164 documentation, 538 element, 163 installing, 536 element, 163 Jakarta Tomcat, 536 element, 160 pipelines, 539 example, 161 genera tors, 539 matchers, 540 condltlonal value attrlbute. selector, 541 adding nodes to result tree, 311 serializers, 540 element, 311 transformers, 540 element, 311 server-side transformations, 533, 535 condltlonal varlables, 211 using parameters in stylesheets, 553 problems with, 212 element, 553 result tree fragments, 213 request parameters, 556 element, 212 code element, 213 apress.com source code downloads, 5 constralnt8 command-IIne utlllty co-occurrence constraints, 652 MSXML,73 container elements, RDF, 668 stylesheet parameters and, 230, 231 element, 668 commands, SVG element, 668 closepath command, 595 element, 668 horizontal lineto command, 595 container element., SVG, 599 lineto command, 595 element, 601 moveto command, 594 element, 599 subpaths, 594 contalns() functlon, 176, 699 vertical lineto command, 595 case insensitive searches example, 220 comment nodeB, 108 parsing durations and calculating end times example, 223 adding nodes to result tree, 314 element, 314 741 content type information, declaring

content type Informatlon, declarlng MSXML,518 element, 321 math:avg() extension function, 519 context attrlbute element, 518 element, 634 Xalan, 519 element, 519 context node element, 519 location paths and, 276 math:avg() extension function, 519 relative paths and, 92 customlzatlon Informatlon context-dependent processlng external XML documents, accessing, 467 document-oriented XML, 128 document() function, 467 identifying elements in different contexts, 130 example, 468 patterns, 130 global parameters, 467 templates, 130 ID attributes, 467 patterns, 129 cx attrlbute processing same node differently in different element, 585, 592 contexts, 144 element, 593 templates, 128 cy attrlbute identifying elements in different contexts, 130 element, 585, 592 unnecessary templates, 132 element, 593 conventlons used In the book, 4 co-occurrence constralnts using XPath to validate XML, 652 XML Schema, 652 D count attrlbute element, 344, 356 data attrlbute countO functlon, 427, 699 element, 621 changing starting number, 351 data elements sorting numerically, 335 putting XML data in stylesheets, 460 using variables as counters in loops, 202 data model, creatlng example, 203 designing markup languages, 47 using XPath to validate XML, 640 data types counters custom extension functions and, 520 using variables as counters in loops, 201 XML Schema, 61 CreateObJectO method boolean data type, 61 creating Document objects, 560 date data type, 61 creating Template objects, 566 dateTime data type, 61 createProcessorO method durations data type, 61 language data type, 61 Template object, 567 time data type, 61 creatlng meta-stylesheet data-type attrlbute element, 657 extensions to attribute values, 491, 492 CSS element, 335, 336, 340 associating stylesheets with XML, 63 date data type xml-stylesheet processing instruction, 63 XML Schema, 61 changing attributes to elements, 26 dateTlme data type compared to XSLT stylesheets, 105 XML Schema, 61 description, 11 element, 673 displaying XML, 62 display property, 62 element, 673 example,64 element, 672 limitations, 64 element, 673 separating content and presentation, 11 element, 673 class attribute, 12 element, 673 example,18 element, 673 using with script for generating HTML, 14 element, 673 Cublc Bezler curves element, 673 element, 596 element, 673 currentO functlon, 699 element, 673 custom extenslon functlons, 518 element, 673 care in using, 520 element, 673 data types and, 520 element, 672 defining in scripting languages, 518 element, 673 ext:minutes() custom extension function, 521 declmal format defining in XSLT, 524 EXSLT initiative, 524 default decimat format, 227 ext:minutes() custom extension function, 526 localization, 227 element, 524 element, 227 element, 525 declmal-separator attrlbute math:avgO extension function, 524 element, 228

742 dynamic XSLT transformations default declmal format, 227 relative URLs, resolving, 473, 474 default namespace returns root nodes, 455 literal result elements, 298 transforming RSS into XML, 687, 689 matching elements in namespaces, 269 document, numberlng across, 355 example, 269 footnotes, 355 namespace declarations, 82, 247 document-orlented XML element, 298 creating multiple result documents from same default prlorlty of templates, 136 stylesheet, 513 patterns, 137 external XML documents, accessing, 455 descendant:: axls customization information, 467 location paths, 274 keys, 463 descendant nodes look up tables, 463 representing XML as node tree, 108 multiple documents, accessing, 478 descendant-or-self:: axls processing, 122 location paths, 274 context-dependent processing, 128 templates, 124 descrlptlon elements, RDF searching XML documents, 361 about attribute, 665 DOM DHTML checking for parse errors, 562 generating attribute values for DHTML, 96 client-side transformations, 560 Dlrectory Generator creating Document objects, 560 pipelines, Cocoon, 539 CreateObjectO method, 560 dlsable-output-escaplng attrlbute example, 563 element, 319, 320 new keyword, 560 element, 319, 320 creating Processor objects, 567 dlsplay property example, 568 displaying XML, 62 creating Template objects, 566 dlv operator, 222 CreateObjectO method, 566 Dlvlded by operator, 222 example, 568 DOCTYPE declaratlon new keyword, 566 associating documents with DTDs, 57 flags on Document object, 561 async, 561 html output method, 322 preserveWhiteSpace, 561 public identifier, 58 resolveExternals, 561 xml output method, 322 validateOnParse, 561 doctype-publlc attrlbute loading XML document, 562 element, 322, 324 NodeList object, 520 doctype-system attrlbute parsers, XML, 29 element, 322, 324 representing XML, 109 document element DSSSL using XPath to validate XML, 636 XSL and, 70 nameO function, 636 DTDs XHTML associating documents with DTDs, 57 element, 34 DOCTYPE declaration, 57 XML elements, 34 validating Markup languages, 57 Document obJect writing DTDs, 58 async property, 561 defining entities, 58, 59 creating, 560 Dublin Core Module CreateObjectO method, 560 meta·information, 672 example, 563 RSS modules, 672 new keyword, 560 duratlons data type 10adO method, 562 parseError property, 562 XML Schema, 61 preserveWhiteSpace property, 561 dx attrlbute resolveExternals property, 561 element, 597 validateOnParse property, 561 dy attrlbute element, 597 see DOM. dynamlc element names document order of nodes, 331 attribute value templates, 293 Document Style Semantlcs and Speclflcatlon namespace declarations, 301 Language translateO function, 294 Dynamlc HTML see DSSSL. Document Type Deflnltlons see DHTML. see DTDs. dynamlc XSL T transformatlons, 532 documentO functlon, 699 client-side transformations, 532, 533 MSXML, 559 external XML documents, accessing, 455 server-side transformations, 532 customization information, 467 Cocoon, 535 search and replace string recursive templates, 458 using parameters in stylesheets, 553 including external content in stylesheet, 472 multiple documents, accessing, 478 743 element nodes

stroke attribute, 593 E stroke-width attribute, 593 Elllpticai arcs element nodes, 108 element, 596 adding nodes to result tree, 292 element dynamic element names, 293 embedding SVG in HTML, 621 generating elements in XHTML namespace, 299 height attribute, 621 matching templates to nodes, 114 src attribute, 621 element, 114 type attribute, 621 using XPath to validate XML, 639 width attribute, 621 • name test, 641 empty elements child element contiguity, testing, 645 using XPath to validate XML, 637 child elements, testing, 640 countO function, 640 • name test, 638 element choices, testing, 644 nodeO node test, 637 element sequence, testing, 642 stringO function, 638 element-only content, testing, 639 textO node test, 638 namespace-uriO function, 642 XML elements, 33 normalize-spaceO function, 640 encodlng attrlbute preceding-sibling:: axls, 645 element, 322, 324, 605 predicates, 646 encodlng, XML, 39 self:: axis, 641 changing XML encoding, 40 element-avallable() functlon, 700 XML declaration, 39 compared to element, 506 end tags testing extension element availability, 506 XML elements, 33 creating multiple result documents from same entltles, deflnlng stylesheet, 516 parameter entities, 58 example of using, 507 writing OTDs, 58 element, 507 example,59 elements entltles, XML, 36 accessing elements by 10, 364 escaping characters using entities, 36 idO function, 365 &,36 resolvlng multiple references, 367 &apos,36 changing attributes to elements, 26 >, 36 choosing between elements and attributes. 52 &It, 36 data elements, 460 ",36 design ing markup languages, 52 Equals operator, 169 extension elements, 498 errata,6 grouping elements, 382 errorCode property identifylng groups, 383 ParseError object. 562 multi-Ievel grouping, 388 errors HTML elements, 9 identifying elements in different contexts, 130 preventing errors with extension elements. 502 patterns, 130 exclude-result-preflxes attrlbute templates, 130 excluding namespaces, 297, 460, 485 iterating over elements, 89 element, 297, 460, 485, 680 example,92 exsl:node-set() extenslon functlon element, 114, 201 converting result tree fragments to node sets, 509 matching elements in namespaces, 267 EXSL T Initiative name tests, 267 defining custom extension functions, 524 optional elements, 154 ext:mlnutes() custom extenslon functlon, 521, 526 presentation of elements, 10 defining in scripting languages, 521 semantic meaning, 10 defining in XSLT, 526 testing for in conditional processing element, 527 location paths, 161 element. 527 top-Ievel elements, 508 JavaScript, 521 XML elements, 33 element, 522 document element, 34 element, 522 empty elements, 33 element, 522 end tags, 33 regular expressions, 521 nested elements, 34 testing function availability, 522 elements attrlbute extenslblllty element, 259 designing markup languages, 49 element, 256, 680 Extenslble Markup Language element, SVG, 587 see XML. cx attribute, 593 Extenslble Stylesheet Language cy attribute, 593 see XSL. fiii attribute, 593 extenslon attrlbutes, 496 rx attribute, 593 definition, 496 ry attribute, 593 744 font-stretch attribute extenslon attrlbutes (contlnued) search and replace string recursive templates, 458 namespace declarations, 497 including external content in stylesheet, 472 element, 497 document() functian, 472 table of attributes, 497 keys, 463 extenslon elements, 498 formatting dates example, 464 compared to top-Ievel elements, 508 key() functian, 465 substring() function, 464 creating multiple result documents from same element, 465 stylesheet, 514 element, 464, 465 example of using, 516 look up tables, 463 element, 515 retrieving referenced information, 473 element, 514 multiple documents, accessing, 478 identifying extension elements, 498 relative URLs, resolving, 473 extension-element-prefixes attribute, 499 search and replace string recursive templates, 456 element, 519 documentO function, 458 element, 519 stopping condition, 457 element, 518 preventing errors with extension elements, 502 element, 502 element, 503 F element, 500 preventing errors with element, 504 false() functlon, 700 element, 500 file attrlbute testing extension element availability, 506 element, 515 creating multiple result documents from same File Generator stylesheet, 516 pipelines, Cocoon, 539 element-avaiiableO function, 506 fllepos property element, 502 ParseError object, 562 extenslon functlons, 484 fIII attrlbute compared to calculating numeric recursive templates, element, 593 416 element, 595 converting result tree fragment to other value types, element, 594 206 element, 590 converting result tree fragments to node sets, 509 element, 591 example, 510 flll-opaclty attrlbute exsl:node-setO extension function, 509 msxsl:node-set() extension function, 509 element, 591 xalan:nodeset() extension function, 509 flll-rule attrlbute custom extension functions, 518 element, 595 defining in scripting languages, 518 Fllter Transformer defining in XSLT, 524 pipelines, Cocoon, 540 description, 484 fllterlng XML flexible node sort values, 343 conditional processing, 181 identitying extension functions, 485 numbering sorted and filtered items, 347 math:avg() extension function, 485 predicates, 181 math:max() extension function, 486 example, 182 namespace declarations, 485 lastO function, 184 qualified names, 485 positionO function, 184 testing function availability, 488 testing position, 184 converting result tree fragments to node sets, 513 flexlble node sort order, 340 example, 489 attribute value templates, 340 function-availableO function, 489 element, 340 xalan:tokenize() extension function, 486 element, 340 extenslon-element-preflxes attrlbute flexlble node sort values, 342 excluding namespaces, 499 extension functions, 343 identitying extension elements, 499 XPath,342 element, 499, 501, 516 floor() functlon, 222, 700 extenslons to attrlbute values, 491 parsing durations and calculating end times example, data-type attribute, 491, 492 224 method attribute, 491, 493 followlng:: axls XHTML output method, 494 location paths, 275 namespace declarations, 492, 494 followlng-slbllng:: axls qualified names, 492, 494 accessing start time example, 282 external XML documents, accesslng, 455 location paths, 274 customization information, 467 font-famlly attrlbute documentO function, 467 element, 596 example, 468 font-slze attrlbute global parameters, 467 element, 596 10 attributes, 467 font-stretch aUri bute document() function, 455 element, 596 745 font-style attribute

font-style attrlbute namespace-uri() function, 247, 642, 702 element, 596 normalize-space{) function, 217, 256, 640, 649, 702 font-varlant attrlbute notO function, 171, 702 element, 596 numberO function, 173, 221, 652, 702 font-welght attrlbute positionO function, 184, 202, 263, 348, 386, 427, element, 596 610,611,703 element, 617 roundO function, 222, 703 footnotes starts-withO function, 176, 703 document, numbering across, 355 string{) function, 173, 638, 650, 703 format attrlbute string-Iength{) function, 215, 650, 703 element, 352, 354, 357 substring{) function, 214, 416, 423, 464, 613, 650, format-numberO functlon, 225, 700 684, 703 duration calculation example, 431 substring-atter{) function, 214, 416, 419, 650, 683, generating SVG with XSLT, 614 704 localization, 227 substring-before{) function, 214, 416, 419, 650, 704 numeric recursive templates for numbering, 409 sum{) function, 202, 335, 427,704 patterns, 226 system-property{) function, 704 repeating numeric recursive templates, 404 translate{) function, 219, 294, 418, 649, 704 sorting numerically, 336 true{) function, 705 element, 227 unparsed-entity-uri{) function, 705 formattlng numbers, 352 values, comparing, 172 example, 174, 177 example, 354 functlons attrlbute large number formatting, 353 element, using different alphabets, 353 519 element, 352 forward axes, 273 from attrlbute G element, 356 element element, SVG, 599 defining custom extension functions, 524 compared to element, 601 ext:minutes{) custom extension function, 527 generating SVG with XSLT, 603, 606, 609, 610, 611, name attribute, 524 615 element, 524 inheriting presentational attributes, 599 element transform attribute, 600, 611 defining custom extension functions, 525 transform definitions, 600 ext:minutesO custom extension function, 527 generate-IdO functlon, 700 select attribute, 525, 527 care in using, 381 functlon-avaliableO functlon, 700 identifying groups, 385, 387 testing function availability, 489 IDs, generating, 380 canverting result tree fragments to node sets, 513 generating IDs for hypertext links, 381, 513 ext:minutesO custom extensian functian, 522 multi-level grouping, 389 math:avgO extension function, 489 global parameters math:maxO extensian function, 489 external XML documents, accessing customization functlons, 172 information, 467 boolean{) function, 173, 698 global varlables, 196 ceilingO function, 222, 698 example of using, 198 combining with operators, 178 including external content in stylesheet, 472 example, 179 shadowing by local variable, 198 concatO function, 215, 375, 388, 654, 699 grammar containsO function, 176, 699 HTML,26 countO function, 202, 335, 351, 427, 640, 699 markup languages, 25 currentO function, 699 graphlcs elements, SVG, 587 documentO function, 455, 467, 472, 473, 478, 687, element, 587, 592 699 element, 587, 593 element-availableO function, 506, 516, 700 element, 588, 598 falseO function, 700 element, 587, 589 floor{) function, 222, 700 element, 588, 594 format-numberO function, 225, 336, 404, 409, 431, element, 587, 593 614, 700 element, 587, 590 function-avaiiableO function, 489, 513, 522, 700 element, 587, 591 generate-idO function, 380, 385, 389, 513, 700 element, 588, 596 idO function, 365, 464, 701 element, 588 keyO function, 370, 375, 383, 464, 655, 687, 701 Greater than operator, 169 langO function, 701 Greater than or equal to operator, 169 lastO function, 184, 701 group-by attrlbute local-name{) function, 247, 701 element, 500 nameO function, 244, 247, 636, 647, 702 746 IDs, generating grouplng elements, 382 CSS, 11, 18 identifying groups, 383 generating HTML using scripts, 13 example, 386