XSL Library Template Reference $Id: lib.xweb,v 1.13 2005/07/08 10:35:55 xmldoc Exp $ DocBook Open Repository Team 1999 2000 2001 2002 2005 Norman Walsh Introduction This is technical reference documentation for the DocBook XSL Stylesheets; it documents (some of) the parameters, templates, and other elements of the stylesheets. This is not intended to be user documentation. It is provided for developers writing customization layers for the stylesheets, and for anyone who's interested in how it works. Although I am trying to be thorough, this documentation is known to be incomplete. Don't forget to read the source, too :-) General Library Templates dot.count Returns the number of . characters in a string Description copy-string Returns count copies of a string Description string.subst Substitute one text string for another in a string Description The string.subst template replaces all occurances of target in string with replacement and returns the result. xpointer.idref Extract IDREF from an XPointer Description The xpointer.idref template returns the ID portion of an XPointer which is a pointer to an ID within the current document, or the empty string if it is not. In other words, xpointer.idref returns foo when passed either #foo or #xpointer(id('foo')), otherwise it returns the empty string. http://... length-magnitude Return the unqualified dimension from a length specification Description The length-magnitude template returns the unqualified length ("20" for "20pt") from a dimension. length-units Return the units from a length specification Description The length-units template returns the units ("pt" for "20pt") from a length. If no units are supplied on the length, the defauilt.units are returned. length-spec Return a fully qualified length specification Description The length-spec template returns the qualified length from a dimension. If an unqualified length is given, the default.units will be added to it. Unrecognized unit of measure: . length-in-points Returns the size, in points, of a specified length Description The length-in-points template converts a length specification to points and returns that value as an unqualified number. There is no way for the template to infer the size of an em. It relies on the default em.size which is initially 10 (for 10pt). Similarly, converting pixels to points relies on the pixels.per.inch parameter which is initially 90. Unrecognized unit of measure: . pi-attribute Extract a pseudo-attribute from a PI Description The pi-attribute template extracts a pseudo-attribute from a processing instruction. For example, given the PI <?foo bar="1" baz='red'?>, ]]> will return red. This template returns the first matching attribute that it finds. Presented with processing instructions that contain badly formed pseudo-attributes (missing or unbalanced quotes, for example), the template may silently return erroneous results. filename 1 lookup.key Retrieve the value associated with a particular key in a table Description Given a table of space-delimited key/value pairs, the lookup.key template extracts the value associated with a particular key. xpath.location Calculate the XPath child-sequence to the current node Description The xpath.location template calculates the absolute path from the root of the tree to the current element node. / / comment-escape-string Prepare a string for inclusion in an XML comment Description The comment-escape-string template returns a string that has been transformed so that it can safely be output as an XML comment. Internal occurrences of "--" will be replaced with "- -" and a leading and/or trailing space will be added to the string, if necessary. comment-escape-string.recursive Internal function used by comment-escape-string Description The comment-escape-string.recursive template is used by comment-escape-string. prepend-pad Right-pad a string out to a certain length Description This function takes string padVar and pads it out to the string-length length, using string padChar (a space character by default) as the padding string (note that padChar can be a string; it is not limited to just being a single character). This function is a copy of Nate Austin's prepend-pad function in the Padding Content section of Dave Pawson's XSLT FAQ. str.tokenize.keep.delimiters Tokenize a string while preserving any delimiters Description Based on the occurrence of one or more delimiter characters, this function breaks a string into a list of tokens and delimiters, marking up each of the tokens with a token element and preserving the delimiters as text nodes between the tokens. This function is a very slightly modified version of a function from the EXSLT site. The original is available at:
The str.tokenize.keep.delimiters function differs only in that it preserves the delimiters instead of discarding them.
apply-string-subst-map Apply a string-substitution map Description This function applies a "string substitution" map. Use it when you want to do multiple string substitutions on the same target content. It reads in two things: content, the content on which to perform the substitution, and map.contents, a node set of elements (the names of the elements don't matter), with each element having the following attributes: oldstring, a string to be replaced newstring, a string with which to replace oldstring The function uses map.contents to do substitution on content, and then returns the modified contents. This function is a very slightly modified version of Jeni Tennison's replace_strings function in the multiple string replacements section of Dave Pawson's XSLT FAQ. The apply-string-subst-map function is essentially the same function as the apply-character-map function; the only difference is that in the map that apply-string-subst-map expects, oldstring and newstring attributes are used instead of character and string attributes. apply-character-map Apply an XSLT character map Description This function applies an XSLT character map; that is, it cause certain individual characters to be substituted with strings of one or more characters. It is useful mainly for replacing multiple "special" chararacters or symbols in the same target content. It reads in two things: content, the content on which to perform the substitution, and map.contents, a node set of elements (the names of the elements don't matter), with each element having the following attributes: character, a character to be replaced string, a string with which to replace character This function uses map.contents to do substitution on content, and then returns the modified contents. This function is a very slightly modified version of Jeni Tennison's replace_strings function in the multiple string replacements section of Dave Pawson's XSLT FAQ. The apply-string-subst-map function is essentially the same function as the apply-character-map function; the only difference is that in the map that apply-string-subst-map expects, oldstring and newstring attributes are used instead of character and string attributes. read-character-map Read in all or part of an XSLT character map Description The XSLT 2.0 specification describes character maps and explains how they may be used to allow a specific character appearing in a text or attribute node in a final results tree to be substituted by a specified string of characters during serialization. The read-character-map function provides a means for reading and using character maps with XSLT 1.0-based tools. It reads the character-map contents from uri (in full or in part, depending on the value of the use.subset parameter), then passes those contents to the apply-character-map function, along with content, the data on which to perform the character substition. Using the character map "in part" means that it uses only those output-character elements that match the XPATH expression given in the value of the subset.profile parameter. The current implementation of that capability here relies on the evaluate extension XSLT function. Error: To process character-map subsets, you must use an XSLT engine that supports the evaluate() XSLT extension function. Your XSLT engine does not support it.
Relative URI Functions Introduction These functions manipulate relative URI references. The following assumptions must hold true: All URIs are relative. No URI contains the ../ sequence which would effectively move up the hierarchy. If these assumptions do not hold, the results are unpredictable. count.uri.path.depth Count the number of path components in a relative URI Description This function counts the number of path components in a relative URI. trim.common.uri.paths Trim common leading path components from a relative URI Description This function trims common leading path components from a relative URI. The Stylesheet The lib.xsl stylesheet is just a wrapper around these functions.