Jump to content of transcoded page.

This is a text-only page produced by the demo version of Usablenet Assistive: the actual content starts below this notice. For more details go to Lift Assistive Help Center.

W3C

An XPath Functions Module

W3C First Public Working Draft 11 August 2008

This version:
http://www.w3.org/TR/2008/WD-xpath-functions-20080811/
Latest version:
http://www.w3.org/TR/xpath-functions/

Editor:
John M. Boyer, IBM

This document is also available in these non-normative formats: diff-marked HTML .

The English version of this specification is the only normative version. Non-normative translations may also be available.


Abstract

This XPath functions module provides a base collection of XPath 1.0 functions that are useful across many modules of XForms.

Status of this Document

This section describes the status of this document at the time of its publication. Other documents may supersede this document. A list of current W3C publications and the latest revision of this technical report can be found in the W3C technical reports index at http://www.w3.org/TR/.

This document is a Working Draft of the W3C. This document has been produced by the W3C Forms Working Group as part of the Forms Activity within the W3C Interaction Domain. The authors of this document are the W3C Forms Working Group participants.

Publication as a Working Draft does not imply endorsement by the W3C Membership. This is a draft document and may be updated, replaced or obsoleted by other documents at any time. It is inappropriate to cite this document as other than work in progress.

Comments on this document are welcome. Please send discussion comments to www-forms@w3.org. Please send formal comment about this document to the public editor mailing list www-forms-editor@w3.org. ( archive).

This document was produced by a group operating under the 5 February 2004 W3C Patent Policy. The Working Group maintains a public list of any patent disclosures made in connection with the deliverables of the group; that page also includes instructions for disclosing a patent. An individual who has actual knowledge of a patent which the individual believes contains Essential Claim(s) must disclose the information in accordance with section 6 of the W3C Patent Policy.


2 XPath Function Library

The function library for XPath expressions includes the entire [XPath 1.0] Core Function Library, including operations on node-sets, strings, numbers, and booleans. The following sections define additional functions that are required to implement by this module. Other modules of the consuming profile may add more functions to the function library. Also, a number of useful community extensions are defined at [EXSLT]

2.1 Data Integrity Functions

2.1.1 The is-card-number() Function

boolean is-card-number(string?)

If the string parameter conforms to the pattern restriction of zero or more numeric digits, then this function applies the algorithm described in [Luhn Patent] and returns true if the string is empty or if the number in the string satisfies the Luhn formula. Otherwise, false is returned. If the parameter is omitted, it defaults to the string-value of the current context node.

Examples:

is-card-number(.)

returns true if and only if the context node contains a string that contains zero or more digits and satisfies the formula.

is-card-number('4111111111111111')

returns true. Other examples of string constants that will return true are : 5431111111111111, 341111111111111 and 6011601160116611.

is-card-number('123')

returns false.

2.1.2 The digest() Function

string digest(string, string, string?)

This function accepts a string of data, a string indicating a cryptographic hashing algorithm, and an optional string indicating an encoding method. The data string is serialized as UTF-8, the hash value is then computed using the indicated hash algorithm, and the hash value is then encoded by the indicated method, and the result is returned by the function. The following table presents the keywords for the second string parameter and the corresponding hash algorithms:

KeywordsHash AlgorithmStatus
MD5The MD5 hash algorithm defined in [MD5] Required
SHA-1The SHA-1 hash algorithm defined in [SHA2] Required
SHA-256The SHA-256 hash algorithm defined in [SHA2] Required
SHA-384The SHA-384 hash algorithm defined in [SHA2] Optional
SHA-512The SHA-512 hash algorithm defined in [SHA2] Optional
Any other NCNameReserved. Their use results in an exception (see 2 XPath Function Library for the exception type) Required
QNameButNotNCNameAn implementation-specific hash algorithm is used. If the implementation does not support the indicated hash algorithm, then an exception occurs (see 2 XPath Function Library for the exception type). Required

This recommendation defines the values hex and base64 for the third string parameter that indicates the encoding method. If the parameter is missing, then the default is base64. The hex and base64 encoding methods of this function correspond to the encodings defined in [XML Schema part 2] for the datatypes hexBinary and base64Binary, respectively. Any other string value given for the encoding method is unsupported.

digest('abc', 'SHA-1', 'hex')

returns a9993e364706816aba3e25717850c26c9cd0d89d.

digest('abc', 'MD5', 'hex')

returns 900150983cd24fb0d6963f7d28e17f72.

digest('abc', 'SHA-256', 'hex')

returns ba7816bf8f01cfea414140de5dae2223b00361a396177a9cb410ff61f20015ad

2.1.3 The hmac() Function

string hmac(string, string, string, string?)

This function accepts a string for a key or shared secret, a string of data, a string indicating a cryptographic hashing algorithm, and an optional string indicating an encoding method. The key and data strings are serialized as UTF-8, and they are subjected to the HMAC algorithm defined in [HMAC] and parameterized by the the hash algorithm indicated by the third parameter. The result is encoded with the method indicated by the fourth parameter, and the result is returned by the function.

The following table presents the keywords for the third string parameter and the corresponding hash algorithms:

KeywordsHash AlgorithmStatus
MD5The MD5 hash algorithm defined in [MD5] Required
SHA-1The SHA-1 hash algorithm defined in [SHA2] Required
SHA-256The SHA-256 hash algorithm defined in [SHA2] Required
SHA-384The SHA-384 hash algorithm defined in [SHA2] Optional
SHA-512The SHA-512 hash algorithm defined in [SHA2] Optional
Any other NCNameReserved. Their use results in an exception (see 2 XPath Function Library for the exception type) Required
QNameButNotNCNameAn implementation-specific hash algorithm is used. If the implementation does not support the indicated hash algorithm, then an exception occurs (see 2 XPath Function Library for the exception type). Required

This recommendation defines the values hex and base64 for the fourth string parameter that indicates the encoding method. If the parameter is missing, then the default is base64. The hex and base64 encoding methods of this function correspond to the encodings defined in [XML Schema part 2] for the datatypes hexBinary and base64Binary, respectively. Any other string value given for the encoding method is unsupported.

hmac('Jefe', 'what do ya want for nothing?', 'SHA-1', 'hex')

returns effcdf6ae5eb2fa2d27416d5f184df9c259a7c79

hmac('Jefe', 'what do ya want for nothing?', 'MD5', 'hex')

returns 750c783e6ab0b503eaa86e310a5db738

hmac('Jefe', 'what do ya want for nothing?', 'SHA-256', 'hex')

returns 5bdcc146bf60754e6a042426089575c75a003f089d2739839dec58b964ec3843

2.2 Date and Time Functions

2.3 Conditional Functions

2.3.2 The choose() Function

object choose(boolean, object, object)

This function provides a conditional test that chooses an object to return based on the boolean parameter. If the boolean parameter is true, then the first object is returned, otherwise the second object is returned. Each of the object parameters can be of any XPath datatype as described in [XPath 1.0], and this function does no type conversion of the parameter it chooses to return.

Note:

All parameters of an XPath function are evaluated, so the parameter that is not returned by this function is still evaluated, and its result is discarded by this function.

Note:

Form authors and design tools are encouraged to use this function instead of the function if() described in Section 2.3.1 The if() Function, which has been deprecated. Because this function returns an object instead of a string, migrating from if() to choose() may occasionally require conversion of the return result using the string() function.

Example:

choose(count(x) > 0, x, y)

Returns the node-set of matching x if it is non-empty and the node-set matching y otherwise.

choose(@x, @x, 0)

If the context node of the function contains attribute x, then the nodeset containing that attribute is returned. Otherwise, the number 0 is returned.

2.3.6 The current() Function

node-set current()

Returns the context node used to initialize the evaluation of the containing XPath expression.

Example:

For the following XML data:

<data xmlns="">
	<converter>
		<amount>100</amount>
		<currency>jpy</currency>
	</converter>

	<convTable date="20040212" currency="cdn">
		<rate currency="eur">0.59376</rate>
		<rate currency="mxn">8.37597</rate>
		<rate currency="jpy">80.23451</rate>
		<rate currency="usd">0.76138</rate>
	</convTable>
</data>	

If the evaluation context node of the following XPath expression is data, then the result of the expression is the converted currency amount:

converter/amount * convTable/rate[@currency = current()/converter/currency]
Editorial note  
An example of the current() function must be moved to the calculate module.

Editorial note  
An example of the current() function must be moved to repeat module.

2.4 Math Functions

3 Glossary Of Terms

QNameButNotNCName

[Definition: A QName that is not an NCName. In 2006, the W3C named this a PrefixedName. ]

A References

A.1 Normative References

HMAC
RFC 2104 - HMAC: Keyed-Hashing for Message Authentication, H. Krawczyk, M. Bellare, R. Canetti, 1997. Available at http://www.ietf.org/rfc/rfc2104.txt
Luhn Patent
Computer for Verifying Numbers, H. P. Luhn, U.S. Patent 2,950,048, 1960.
MD5
RFC 1321: The MD5 Message-Digest Algorithm, R. Rivest, 1992. Available at http://www.ietf.org/rfc/rfc1321.txt
RFC 2119
RFC 2119: Key words for use in RFCs to Indicate Requirement Levels, S. Bradner, 1997. Available at http://www.ietf.org/rfc/rfc2119.txt.
SHA2
SECURE HASH STANDARD. FIPS PUB 180-2, August 2002. Available at http://csrc.nist.gov/publications/fips/fips180-2/fips180-2.pdf
Unicode Collation Algorithm
Unicode Technical Standard #10, Unicode Collation Algorithm, Available at: http://www.unicode.org/unicode/reports/tr10/.
XPath 1.0
XML Path Language (XPath) Version 1.0, James Clark, Steve DeRose, 1999. W3C Recommendation available at: http://www.w3.org/TR/1999/REC-xpath-19991116.
XML Schema part 2
XML Schema Part 2: Datatypes, Paul V. Biron, Ashok Malhotra, 2004. W3C Recommendation available at: http://www.w3.org/TR/2004/REC-xmlschema-2-20041028/.

A.2 Informative References

EXSLT
EXSLT Web site. Available at http://www.exslt.org.
XPath 2.0
XML Path Language (XPath) 2.0, Anders Berglund, Scott Boag, Don Chamberlin, Mary F. Fernández, Michael Kay, Jonathan Robie, and Jérôme Siméon, 2007. W3C Recommendation available at: http://www.w3.org/TR/2007/REC-xpath20-20070123/.

C Production Notes (Non-Normative)

This document was encoded in the XMLspec DTD v2.6. The XML sources were transformed using diffspec and xmlspec stylesheets, version 2.6. The XML Schema portion of the Appendix was rendered into HTML with the xmlverbatim XSLT stylesheet (used with permission). The primary tool used for editing was XMLSpy. The XML was transformed using the XSLT processor in Java 6. The editor(s) use the W3C CVS repository and the W3C IRC server for collaborative authoring.

Text Only Options

Top of page


Text Only Options

Open the original version of this page.

     

Usablenet Assistive is a UsableNet product. Usablenet Assistive Main Page.