9.8.  XSLT Extension Functions

Several extension functions are available when using the XSLT processor integrated in the pure::variants XML Transformation System for model transformations and model exports. These extension functions are defined in own namespaces. Before they can be used in an XSLT script, the corresponding namespaces have to be included using the "xmlns" stylesheet attribute:

<?xml version="1.0" encoding="UTF-8"?> 
<xsl:stylesheet version="1.0"
                xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
                xmlns:pv="http://www.pure-systems.com/purevariants"
                extension-element-prefixes="pv"> 

  ...any script content...

</xsl:stylesheet> 

After including the namespace, the extension functions can be used in XPath expressions using the defined namespace prefix, e.g. F .

The following extension functions are defined in the namespace "http://www.pure-systems.com/purevariants" and provide access to the pure::variants model information.

Table 9.10. Extension functions providing model information

FunctionDescription

nodeset models()

Get all input models known to the transformer, i.e. the opened variant description model, and all Feature and Family Models of the Configuration Space without any modifications. See Section 5.9.2, “ Variant Result Models ” for more information about the transformation input.

Note: In the pure::variants Server Edition this function returns an empty set. Access to the input models of the transformation is not supported in the pure::variants Server Edition.

nodeset model-by-id(string)

Get all variant Result Models known to the transformer having the given id. The Result Models are derived from the models of the Configuration Space describing a single concrete solution drawn from the solution family. See Section 5.9.2, “ Variant Result Models ” for more information about the transformation input.

nodeset model-by-name(string)

Get all Variant Result Models known to the transformer having the given name. The Variant Result Models are derived from the models of the Configuration Space describing a single concrete solution drawn from the solution family. See Section 5.9.2, “ Variant Result Models ” for more information about the transformation input.

nodeset model-by-type(string)

Get all Variant Result Models known to the transformer having the given type. The Variant Result Models are derived from the models of the Configuration Space describing a single concrete solution drawn from the solution family. Valid types are ps:vdm , ps:cfm , and ps:ccm . See Section 5.9.2, “ Variant Result Models ” for more information about the transformation input.
boolean hasFeature(string) Return true if the feature, given by its unique name or id, is in the variant.
boolean hasComponent(string) Return true if the component, given by its unique name or id, is in the variant.
boolean hasPart(string) Return true if the part, given by its unique name or id, is in the variant.
boolean hasSource(string) Return true if the source, given by its unique name or id, is in the variant.
boolean hasElement(string id) Return true if the element, given by its unique id, is in the variant.
boolean hasElement(string name,string class,string type?) Return true if the element, given by its unique name, class, and (optionally) type, is in the variant.
nodeset getElement(string id) Return the element given by its unique id.
nodeset getElement(string name,string class,string type?) Return the element given by its unique name, class, and (optionally) type.
nodeset getChildrenTargets(string id) Return the full qualified ids of the children elements of the element with the given id.
nodeset getChildrenTargets(nodeset element) Return the full qualified ids of the children elements of the given element.
nodeset getChildrenTargets(string ename,string eclass,string etype?) Return the full qualified ids of the children elements of the element given by its unique name, class, and (optionally) type.
boolean hasAttribute(string id) Return true if the attribute, given by its unique id, is in the variant.
boolean hasAttribute(nodeset element,string name) Return true if the attribute, given by its name and the element it belongs to, is in the variant.
boolean hasAttribute(string eid,string name) Return true if the attribute, given by its name and the id of the element it belongs, to is in the variant.
boolean hasAttribute(string ename,string eclass,string etype?,string name) Return true if the attribute, given by its name and the unique name, class, and (optionally) type of the element it belongs to, is in the variant.
nodeset getAttribute(string id) Return the attribute given by its unique id.
nodeset getAttribute(nodeset element,string name) Return the attribute given by its name and the element it belongs to.
nodeset getAttribute(string eid,string name) Return the attribute given by its name and the id of the element it belongs to.
nodeset getAttribute(string ename,string eclass,string etype?,string name) Return the attribute given by its name and the unique name, class, and (optionally) type of the element it belongs to.
boolean hasAttributeValue(nodeset attribute) Return true if the given attribute has a value.
boolean hasAttributeValue(string id) Return true if the attribute given by its unique id has a value.
boolean hasAttributeValue(nodeset element,string name) Return true if the attribute, given by its name and the element it belongs to, has a value.
boolean hasAttributeValue(string eid,string name) Return true if the attribute, given by its name and the id of the element it belongs to, has a value.
boolean hasAttributeValue(string ename,string eclass,string etype?,string name) Return true if the attribute, given by its name and the unique name, class, and (optionally) type of the element it belongs to, has a value.
nodeset getAttributeValue(nodeset attribute) Return the values of the given attribute.
nodeset getAttributeValue(string id) Return the values of the attribute given by its unique id.
nodeset getAttributeValue(nodeset element,string name) Return the values of the attribute given by its name and the element it belongs to.
nodeset getAttributeValue(string eid,string name) Return the values of the attribute given by its name and the id of the element it belongs to.
nodeset getAttributeValue(string ename,string eclass,string etype?,string name) Return the values of the attribute given by its name and the unique name, class, and (optionally) type of the element it belongs to.

The following extension functions are defined in the namespace "http://www.pure-systems.com/xmlts" and provide basic information about the current transformation.

Table 9.11. Extension functions providing transformation information

FunctionDescription
string os() Get the target system type. This is either the string "win32", "macosx", or "linux" (default).
string version() Get the transformation system version.
string input-path() Get the transformation input path.
string output-path() Get the transformation output path.
string generate-id() Generate an unique identifier.
nodeset current() Get the node currently being transformed.
nodeset entry-points() Get the transformation entry point list, i.e. a list of full qualified element IDs. Transformation modules can use this list to identify sub-trees of the input models that are to be transformed.
boolean below-entry-point(string id) Return true if the given full qualified element ID denotes an element below a transformation entry point. Transformation modules can use this function to identify sub-trees of the input models that are to be transformed.
nodeset exit-points() Get the transformation exit point list, i.e. a list of full qualified element IDs. Transformation modules can use this list to identify sub-trees of the input models that are to be ignored.
boolean above-exit-point(string id) Return true if the given full qualified element ID denotes an element above a transformation exit point. Transformation modules can use this function to identify sub-trees of the input models that are to be ignored.
nodeset results-for(nodeset nodes?) Get the transformation module results for the given nodes. If no argument is given, then the results for the context node are returned.
nodeset log(string message,number level?) Add a logging message that is shown in the Console View. The first parameter is the message and the second the logging level (0-9). It is recommend to use a logging level between 4 (default) and 8 (detailed tracing). Returns the empty nodeset.
nodeset info(string message,string id?,nodeset related?) Add an info message that is shown in the Problems View resp. as marker on a model element. The first parameter is the message. All other parameters are optional. The second is the ID of the context element of the info (used to place the marker), and the third is a set of IDs of related model elements. Returns the empty nodeset.
nodeset warning(string message,string id?,nodeset related?) Add a warning message that is shown in the Problems View resp. as marker on a model element. The first parameter is the message. All other parameters are optional. The second is the ID of the context element of the info (used to place the marker), and the third is a set of IDs of related model elements. Returns the empty nodeset.
nodeset error(string message,string id?,nodeset related?) Add an error message that is shown in the Problems View resp. as marker on a model element. The first parameter is the message. All other parameters are optional. The second is the ID of the context element of the info (used to place the marker), and the third is a set of IDs of related model elements. Returns the empty nodeset.

Note

Error messages may abort the XSLT script execution and the whole transformation.


Table 9.12. Extension elements for logging and user messages

ElementDescription
<log level="0-9">message</log> Add a logging message that is shown in the Console View. The optional attribute "level" specifies the logging level (0-9). It is recommend to use a logging level between 4 (default) and 8 (detailed tracing).
<info context="element id" related="nodeset">message</info> Add an info message that is shown in the Problems View resp. as marker on a model element. The optional attribute "context" specifies the ID of the context element of the info (used to place the marker). The optional attribute "related" specifies a set of IDs of related model elements.
<warning context="element id" related="nodeset">message</warning> Add a warning message that is shown in the Problems View resp. as marker on a model element. The optional attribute "context" specifies the ID of the context element of the info (used to place the marker). The optional attribute "related" specifies a set of IDs of related model elements.
<error context="element id" related="nodeset">message</error> Add an error message that is shown in the Problems View resp. as marker on a model element. The optional attribute "context" specifies the ID of the context element of the info (used to place the marker). The optional attribute "related" specifies a set of IDs of related model elements.

Note

Error messages may abort the XSLT script execution and the whole transformation.


The following extension functions are defined in the namespace "http://www.pure-systems.com/path" and provide additional file operations.

Table 9.13. Extension functions providing file operations

FunctionDescription
string normalize(string path) Normalized the given path for the current target platform.
string dirname(string path) Get the directory part of the given path.
string filename(string path) Get the file part of the given path.
string basename(string path) Strip the file extension from the given path.
string extension(string path) Get the file extension from the given path.
string absolute(string path) Make the given path absolute (i.e. full path).
string add-part(string path,string part) Add the given part to the path using the platform specific path delimiter.
number size(string file) Get the size (in bytes) of the given file.
number mtime(string path) Get the modification time of the given file or directory.
string cwd() Get the current working directory.
string tempdir() Get the directory for temporary files.
string delimiter() Get the path delimiter of the target platform.
boolean exists(string path) Return true if the given file or directory exists.
boolean is-dir(string path) Return true if the given path points to a directory.
boolean is-file(string path) Return true if the given path points to a file.
boolean is-absolute(string path) Return true if the given path is absolute (i.e. full path).
string to-uri(string path) Get the file URI build from the given path (i.e. file://... ).
string read-file(string uri) Read a file from a given URI and return its content as string.

The following extension functions are defined in the namespace "http://www.pure-systems.com/string" and provide additional string operations.

Table 9.14. Extension functions providing string operations

FunctionDescription
nodeset parse(string xml) Parse the given string as XML and return the resulting node set.
boolean matches(string str,string pattern) Match the regular expression pattern against the given string. Return true if the pattern matches.
nodeset match(string str,string pattern) Match the regular expression pattern against the given string and return the set of sub-matches.
string submatch(string str,string pattern,number n) Match the regular expression pattern against the given string and return the n-th sub-match.
string replace(string str,string pattern,string replacement,number n?) Replace the matches in the given string with the replacement string using the regular expression match pattern. The optional fourth parameter specifies the maximal number of replacements. 0 means all, 1 means to replace only the first, 2 means to replace the first 2 matches etc. Returns the resulting string.
string expand(string str) Expand variables in the given string and return the expanded string. Variables are recognized by the following pattern: $(VARIABLENAME) . See Section 9.9, “ Predefined Variables ” for the list of supported variables.

Further information about XSLT extension functions is available in the external document XML Transformation System .