Home  » XPath Extensions

P6R's XPath 2.0 Extension Functions

P6R's XPath 2.0 engine provides several very useful extensions to XPath 2.0. When using XSLT, XML (or even JSON using our JSON enabled DOM parser) to create competitive commercial offerings, these extentions help you speed your way to a final product.

These added functions require the use of the P6R namespace: http://www.p6r.com/XPath/extensions

P6R:base64encode

This function encodes a given byte array into a base64 encoded string. However, all strings in our XPath implementation are stored in a wide character, Unicode representation. The output string can be output into UTF8 format along with all other template output. Note that the input to this function can come from an externally defined variable that can contain any binary data via the use of the p6IXpathVariables::lookupVariable() interface.
Argument    Data Type     Meaning
input       byte array    Function takes a standard XPath expression as input.   
result      byte array    A base64 encoded character string in wide string format.
                          XPath returned type of P6R::P6XPATH_TYPE_STR.

P6R:base64decode

This function removes the base64 encoding of the input string. Warning, care must be taken when using these base64 functions when encoding Unicode strings. On Linux each wide character is represented in 4 bytes while Windows and Solaris use 2 bytes. Thus encoding on Linux and trying to decode on Windows or Solaris will not work properly. (Likewise encoding on Windows or Solaris and trying to decode on Linux will also not work.) The calling application needs to normalize strings, before using this standard base64 algorithm, when passing the base64 result between Linux and other operating systems.
Argument    Data Type     Meaning
input       xs:string     A base64 encoded string 
result      byte array    XPath returned type of P6R::P6XPATH_TYPE_STR.

P6R:match-attribute

This is an extension of the standard lang() function. This method allows the caller to match any attribute of the context node.
Argument         Data Type     Meaning
attribute name   xs:string     To match the lang() function this would be "lang" 
attribute value  xs:string     To match the lang() function this could be "fr-CA"
result           xs:boolean    Base64 allow the encoding of binary data

P6R:matches-with-capture

This is an extension of the XPath matches() function. It takes the exact same parameters as the matches() function but returns a node set as a result instead. The returned node set is composed of the following values: the first value is the matching string, all other values (if any), are substrings of the first value which are captured by the regular expression via back references. If no match occurs, then an empty node set is returned to indicate false. XPath itself does not currently have a way to return the captured strings.
Argument         Data Type     Meaning
attribute input  xs:string     See the XPath 2.0 standard for the standard meaning
attribute regex  xs:string         of these arguments.
atrribute flags  xs:string     (optional)
result           item()*       A node set with zero or more values as defined above

P6R:format-number

This is meant as an alternative to the XSLT format-number() function. The XSLT function is complex and does not allow the explicit selection of a language and locale. The third parameter of this function is a standard locale string, for example: 'en' (for English), 'en_us' (for english in the United states, and 'fr_ca' (for French Canadian). In addition, XSLT's version of this function does not provide a way to space pad the resulting number so as to facilitate vertically aligning numbers in a column. P6R's version of this function provides the same basic width control of the swprintf function.
Argument       Data Type                   Meaning
numeric        xs:double or xs:integer     any one of the numeric values is valid
               or xs:decimal or xs:float     
format         xs:string                   a standard format string as used in p6i18n::swprintf function (e.g., %d,%f)
locale         xs:string                   (optional) indicates language and locale (e.g., en_us)
result         xs:string                   The format parameter expanded with the 'numeric' parameter