The xtpxlib-common component contains the following XSLT modules. The ones used most frequently are general.mod.xsl
and href.mod.xsl
.
Module/Pipeline | Description |
---|---|
compare.mod.xsl | XSL library module with support for comparing XML documents/elements: |
date-time.mod.xsl | XSLT library module containing functions for working with dates and times. |
format-output.mod.xsl | XSLT library with functions for formatting output/strings. |
general.mod.xsl | XSLT library module with general constants and code. |
href.mod.xsl | XSLT library module with functions for the generic handling of href-s (filenames/paths). |
macrodefs.mod.xsl | Module for handling macro definitions. |
message.mod.xsl | Message related templates. |
mimetypes.mod.xsl | MIME type conversion related functions. |
parameters.mod.xsl | Takes an XML document with parameters and turns this into a parameter map. |
simple-macros.mod.xsl | (DEPRECATED) Support code for simple macro expansion in strings, e.g. $NAME. |
uuid.mod.xsl | UUID related functions. |
compare.mod.xsl
XSL library module with support for comparing XML documents/elements:
Named template | Description |
---|---|
xtlc:compare-documents | Compares two XML documents with each other: |
date-time.mod.xsl
File: xslmod/date-time.mod.xsl
XSLT library module containing functions for working with dates and times.
When language based, it only distinguishes between Dutch and non-Dutch (which now means: English).
Function | Description |
---|---|
xtlc:day-in-year-number() | Computes the day number in the year: January 1 is 1, December 31 is 365 (or 366 in leap years). |
xtlc:days-in-month() | Computes the number of days in a particular month. If values are out of range it returns 0. |
xtlc:format-date-as-text() | Formats a date as a string with the month name in full. |
xtlc:format-date-as-text-short() | Formats a date as a string with the month name in short. |
xtlc:is-leap-year() | Returns true when a given year is a leap year |
xtlc:month-name() | Returns the name of a month. |
xtlc:month-name-short() | Returns the name of a month in short (abbreviated to 3 characters). |
xtlc:to-date() | Creates a date from its components. |
xtlc:unix-epoch() | Computes the UNIX "epoch" code (number of seconds since 1-1-1970) for a given date/time. |
xtlc:week-number() | Computes the ISO week number for a given date. |
xtlc:weekday-name() | Returns the name of a month. |
xtlc:weekday-number() | The number of the weekday (1=Monday, 7=Sunday). |
xtlc:day-in-year-number() as xs:integer
Computes the day number in the year: January 1 is 1, December 31 is 365 (or 366 in leap years).
xtlc:days-in-month() as xs:integer
Computes the number of days in a particular month. If values are out of range it returns 0.
xtlc:month-name-short() as xs:string
Returns the name of a month in short (abbreviated to 3 characters).
xtlc:unix-epoch() as xs:decimal
Computes the UNIX "epoch" code (number of seconds since 1-1-1970) for a given date/time.
format-output.mod.xsl
File: xslmod/format-output.mod.xsl
XSLT library with functions for formatting output/strings.
When language based, we only distinguish between Dutch and non-Dutch (usually English).
Function | Description |
---|---|
xtlc:duration2str() | Turns a day/time duration into a more readable string, e.g. 1d3h40m12s |
xtlc:format-amount() | Formats an amount by adding a € sign and always use double digits. |
xtlc:format-double() | Formats a double as a string with a given amount of digits. |
xtlc:size2str() | Turns an integer (e.g. a file size) into a (rounded) number using a Kb /Mb /Gb suffix. |
xtlc:duration2str() as xs:string
Turns a day/time duration into a more readable string, e.g. 1d3h40m12s
xtlc:format-amount() as xs:string
Formats an amount by adding a € sign and always use double digits.
general.mod.xsl
XSLT library module with general constants and code.
Named template | Description |
---|---|
xtlc:raise-error | Stops any processing by raising an error. |
Function | Description |
---|---|
xtlc:att2str() | Turns an attribute into a string representation, suitable for display (e.g. name="value" ). |
xtlc:capitalize() | Capitalizes a string (makes the first character uppercase). |
xtlc:char-repeat() | Returns a string with a single character repeated a given number of times. |
xtlc:count-leading-whitespace() | Counts the number of whitespace characters at the beginning of a string |
xtlc:elm2str() | Turns an element into a descriptive string (the element with all its attributes, excluding schema references). |
xtlc:item2element() | Tries to find the element belonging to a given item. |
xtlc:items2str() | Creates a string from a sequence of items. |
xtlc:prefix-to-length() | Prefixes a string with a given character so it will get at least a given length. |
xtlc:q() | Returns the input string quoted ("$in" ) |
xtlc:str2bln() | Safe conversion of a string into a boolean. |
xtlc:str2filename-safe() | Replaces all characters in a string that are not allowed in filenames with another character. |
xtlc:str2filename-safe() | Replaces all characters in a string that are not allowed in filenames with an underscore. |
xtlc:str2id() | Turns a string into a valid identifier, adding a prefix. |
xtlc:str2id() | Turns a string into a valid identifier. |
xtlc:str2int() | Safe conversion of a string to an integer. |
xtlc:str2regexp() | Turns a string into a regular expression that matches the input exactly. Optionally anchors the regular expression so the match will be on this string only (result starts with ^ and ends with $ ). |
xtlc:str2regexp() | Turns a string into a regular expression that matches the input exactly. |
xtlc:str2seq() | Converts a string with a list of words into a sequence of words. |
xtlc:text2lines() | Converts text into separate lines. |
xtlc:att2str() as xs:string
Turns an attribute into a string representation, suitable for display (e.g. name="value"
).
xtlc:char-repeat() as xs:string
Returns a string with a single character repeated a given number of times.
xtlc:count-leading-whitespace() as xs:integer
Counts the number of whitespace characters at the beginning of a string
xtlc:elm2str() as xs:string
Turns an element into a descriptive string (the element with all its attributes, excluding schema references).
xtlc:item2element() as element()?
Tries to find the element belonging to a given item.
When the item is of type xs:string
or xs:anyURI
, it is assumed to be a document reference. The root element of this is returned.
When the item is of type document-node()
, the root element of this document is returned
You can choose whether to produce an error message or ()
when the item cannot be resolved.
xtlc:items2str() as xs:string
Creates a string from a sequence of items.
Useful for easy creation of messages consisting of multiple parts and pieces.
xtlc:prefix-to-length() as xs:string
Prefixes a string with a given character so it will get at least a given length.
xtlc:str2bln() as xs:boolean
Safe conversion of a string into a boolean.
When $in
is empty or not convertible into a boolean, $default
is returned.
xtlc:str2filename-safe() as xs:string
Replaces all characters in a string that are not allowed in filenames with another character.
xtlc:str2filename-safe() as xs:string
Replaces all characters in a string that are not allowed in filenames with an underscore.
xtlc:str2id() as xs:string
Turns a string into a valid identifier, adding a prefix.
All characters that are not allowed in an identifier are converted into underscores.
When the result does not start with a letter or underscore, the prefix id-
is added.
xtlc:str2id() as xs:string
Turns a string into a valid identifier.
All characters that are not allowed in an identifier are converted into underscores.
When the result does not start with a letter or underscore, the prefix id-
is added.
xtlc:str2int() as xs:integer
Safe conversion of a string to an integer.
When $in
is empty or not convertible to an integer, $default
is returned.
xtlc:str2regexp() as xs:string
Turns a string into a regular expression that matches the input exactly. Optionally anchors the regular expression so the match will be on this string only (result starts with ^
and ends with $
).
xtlc:str2regexp() as xs:string
Turns a string into a regular expression that matches the input exactly.
xtlc:str2seq() as xs:string*
Converts a string with a list of words into a sequence of words.
xtlc:text2lines() as xs:string*
Converts text into separate lines.
Uses the LF as separator; CRs are removed.
href.mod.xsl
XSLT library module with functions for the generic handling of href-s (filenames/paths).
Function | Description |
---|---|
xtlc:href-add-encoding() | Percent encodes all "strange" characters (%xx ). Any existing percentage encodings will be kept as is. |
xtlc:href-canonical() | Makes an href canonical (remove any .. and . directory specifiers). |
xtlc:href-concat() | Performs a safe concatenation of href components: |
xtlc:href-decode-uri() | Reverse function of encode-fo-uri(). Translates percent encodings (%xx ) into their actual characters. |
xtlc:href-ext() | Returns the extension part of an href. |
xtlc:href-is-absolute() | Returns true if the href is considered absolute. |
xtlc:href-name() | Returns the (file)name part of an href. |
xtlc:href-name-noext() | Returns the (file)name part of an href without its extension. |
xtlc:href-noext() | Returns the complete href path without its extension. |
xtlc:href-path() | Returns the path part of an href. |
xtlc:href-protocol() | Returns the protocol part of an href (without the :// ). |
xtlc:href-protocol() | Returns the protocol part of an href (without the :// ) or a default value when none present. |
xtlc:href-protocol-add() | Adds a protocol specifier (written without the trailing :// , e.g. http ) to an href. |
xtlc:href-protocol-present() | Returns true when an href has a protocol specifier (e.g. file:// or http:// ). |
xtlc:href-protocol-remove() | Removes the protocol part from an href. |
xtlc:href-relative() | Computes a relative href from one document to another. |
xtlc:href-relative-from-path() | Computes a relative href from a directory path to a document. |
xtlc:href-result-doc() | Transforms an href into something xsl:result-document/@href can use. |
xtlc:href-add-encoding() as xs:string
Percent encodes all "strange" characters (%xx
). Any existing percentage encodings will be kept as is.
xtlc:href-canonical() as xs:string
Makes an href canonical (remove any .. and . directory specifiers).
xtlc:href-concat() as xs:string
xtlc:href-decode-uri() as xs:string
Reverse function of encode-fo-uri(). Translates percent encodings (%xx
) into their actual characters.
xtlc:href-is-absolute() as xs:boolean
Returns true
if the href is considered absolute.
An href is considered absolute when it starts with a /
or \
, contains a protocol specifier (e.g. file://
) or starts with a Windows drive letter (e.g. C:
).
xtlc:href-name-noext() as xs:string
Returns the (file)name part of an href without its extension.
xtlc:href-protocol() as xs:string
xtlc:href-protocol() as xs:string
Returns the protocol part of an href (without the ://
) or a default value when none present.
xtlc:href-protocol-add() as xs:string
Adds a protocol specifier (written without the trailing ://
, e.g. http
) to an href.
xtlc:href-protocol-present() as xs:boolean
Returns true when an href has a protocol specifier (e.g. file://
or http://
).
xtlc:href-relative() as xs:string
xtlc:href-relative-from-path() as xs:string
Computes a relative href from a directory path to a document.
macrodefs.mod.xsl
File: xslmod/macrodefs.mod.xsl
Module for handling macro definitions.
A macro definition is a simple name=value
construct. They are passed around in maps (map(xs:string, xs:string)
).
The xtlc:expand-macrodefs()
function expands macro definition references within strings by using ${…}
or {$…}
. To prevent the expansion of these constructions, simply double the opening curly brace. All referenced macro definitions must exist, otherwise an error will be raised.
Macro definitions can reference other macro definitions.
Additionally, you can modify the value of a macro by appending one or more flags (separated by colons), for instance ${MACRO:cap:fnsx}
. For more information on the available flags, refer to the $xtlc:macrodef-flag-*
global variables.
There are a number of standard macros that can be used. See the $xtlc:macrodef-standard-*
global variables.
Named template | Description |
---|---|
xtlc:expand-macro-definitions | Expands macro definitions in text nodes and/or attribute values. |
xtlc:macrodefs-as-comment | Outputs a simple comment showing the contents of $macrodef-map . |
Function | Description |
---|---|
xtlc:expand-macrodefs() | Expands macro definition references in a string against the macro definitions in $macrodef-map . Checks for circular references. |
xtlc:get-standard-macrodef-map() | Returns a map with standard macro definitions. See the $xtlc:macrodef-standard-* global variable definitions. |
xtlc:merge-macrodefs() | Merges multiple macro definition maps, taking care that newer definitions override existing ones. Will return an empty map if the input is the empty sequence. |
xtlc:expand-macro-definitions
Expands macro definitions in text nodes and/or attribute values.
The template checks for <:macrodefs>
elements that are the first child of any element. If so, any <:macrodef>
children are used to define (or override) macro definitions. These elements can be in any namespace.
See also xsdmod/macrodefs.mod.xsd
.
You can customize its functionality by using the template parameters.
xtlc:macrodefs-as-comment
Outputs a simple comment showing the contents of $macrodef-map
.
xtlc:expand-macrodefs() as xs:string
Expands macro definition references in a string against the macro definitions in $macrodef-map
. Checks for circular references.
xtlc:get-standard-macrodef-map() as map(xs:string, xs:string)
Returns a map with standard macro definitions. See the $xtlc:macrodef-standard-*
global variable definitions.
message.mod.xsl
A message is a standardized piece of XML used for inserting (error, debug, etc.) messages into XML documents.
Named template | Description |
---|---|
xtlc:msg-create | Generates a standard xtlc:message element. |
xtlc:msg-create as element(xtlc:message)
Generates a standard xtlc:message
element.
Parameter | Type | Rq? | Default | Description |
---|---|---|---|---|
extra-attributes | attribute()* | () | Any extra attributes to add to the message. | |
extra-contents | element()* | () | Any extra elements to add to the message. | |
msg-parts | item()+ | yes |
| Message to show (parts will be concatenated by xtlc:items2str() ). |
status | xs:string | yes |
| The status of the message. Must be one of the $xtlc:status-* constants as defined in general.mod.xsl. |
mimetypes.mod.xsl
File: xslmod/mimetypes.mod.xsl
MIME type conversion related functions.
These conversions work with an external MIME type/extension table.
Function | Description |
---|---|
xtlc:ext2mimetype() | Turns an href extension (e.g. xml') into the correct MIME type ('text/xml' ). |
xtlc:mimetype2ext() | Turns a MIME type (e.g. 'text/xml' ) into a corresponding href extension ('xml' ). |
parameters.mod.xsl
File: xslmod/parameters.mod.xsl
Takes an XML document with parameters and turns this into a parameter map.
More information here.
Function | Description |
---|---|
xtlc:expand-text-against-parameters() | Expands parameter references in $text (either {$...} or ${...} ) against the parameters in $parameter-map . If a parameter has multiple values, only the first one is used. |
xtlc:parameters-get() | Tries to locate a <parameters> element (in any namespace) underneath $root-item and processes the child <parameter> and <group> elements in here into a parameter map. |
xtlc:expand-text-against-parameters() as xs:string
Expands parameter references in $text
(either {$...}
or ${...}
) against the parameters in $parameter-map
. If a parameter has multiple values, only the first one is used.
xtlc:parameters-get() as map(xs:string, xs:string*)
Tries to locate a <parameters>
element (in any namespace) underneath $root-item
and processes the child <parameter>
and <group>
elements in here into a parameter map.
The <value>
elements are filtered according to the entries in $filters
.
Parameter references in values (either {$...}
or ${...}
). are expanded. If a parameter has multiple values, only the first one is used.
simple-macros.mod.xsl
File: xslmod/simple-macros.mod.xsl
(DEPRECATED) Support code for simple macro expansion in strings, e.g. $NAME.
Consider using macrodefs.mod.xsl instead! There are bugs in the macro expansion (that will not be solved for now).
To stop a macro from expanding, double the $ character ($$NAME becomes $NAME).
What is expanded must be in a map formatted as map{macro: expansion}, e.g. map{'NAME': 'thenameofthething'}
Macros in the string must start with the xtlc:simpleMacroStart character ($).
Function | Description |
---|---|
xtlc:expand-simple-macros() | Expands simple macro's in a string with values. All macros to expand must start with $xtlc:simple-macro-start-character ($), for instance: $DATE. |
xtlc:expand-simple-macros() | Expands simple macro's in a string with values. See xtlc:expand-simple-macros#3 |
xtlc:expand-simple-macros() as xs:string
Expands simple macro's in a string with values. All macros to expand must start with $xtlc:simple-macro-start-character ($), for instance: $DATE.
The substitution values are in a map. The keys must be the macro strings. For instance: map{'DATE': '2023-04-04', 'TIME': '16:04:35'}
uuid.mod.xsl
Works only in Saxon PE or EE (not in the free HE), because we are calling an underlying Java function.
Function | Description |
---|---|
xtlc:get-uuid() | Returns a random unique UUID (by calling an underlying Java function) |
xtlc:is-real-uuid() | Checks whether a string contains a "real" UUID (conforms to the UUID formatting rules). |