Read XSLT 2.0 and XPath 2.0 Programmer's Reference, 4th Edition Online
Authors: Michael Kay
Usage
This function is often used in conjunction with
in-scope-prefixes()
, which finds the prefixes of all the in-scope namespaces for an element as a sequence of strings.
Note that if the requirement is to resolve a lexical QName to obtain an
xs:QName
value, the
resolve-QName()
function provides an easier way of doing this.
See Also
in-scope-prefixes()
on page 808
resolve-QName()
on page 804
namespace-uri-from-QName
The function
namespace-uri-from-QName()
returns the namespace URI part of an
xs:QName
value.
Signature
Argument | Type | Meaning |
value | xs:QName? | The xs:QName value whose namespace URI part is required. If the supplied value is an empty sequence, an empty sequence is returned. |
Result | xs:anyURI? | The namespace URI part of the xs:QName . |
Effect
Given an expanded QName (that is, an instance of type
xs:QName
), this function returns the namespace URI part of the value. If the
xs:QName
is in no namespace, it returns a zero-length URI.
Examples
Expression | Result |
namespace-uri-from-QName(QName(‘http://mhk.me.uk/some.uri’,‘invoice’)) | “http://mhk.me.uk/some.uri” |
namespace-uri-from-QName(node-name(@xml:space)) | “http://www.w3.org/XML/1998/namespace” |
The second example assumes that the context node has an attribute called
xml:space
.
See Also
QName()
on page 858
local-name-from-QName()
on page 826
nilled
The
nilled()
function returns true if applied to an element that (a) specifies
xsi:nil=“true”
, and (b) has been successfully validated against a schema.
Signature
Argument | Type | Meaning |
input | node()? | The node being tested |
Result | xs:boolean? | True for an element that has the nilled property |
Effect
If the input is an element node that has the attribute
xsi:nil=“true”
and that has been subjected to schema validation, the function returns true.
If the input is an element node that does not have an
xsl:nil
attribute, or that has the value
xsi:nil=“false”
, or if it is an element node that has not been assessed against a schema, the function returns false.
The function returns the empty sequence if it is applied to a node other than an element, or if the argument is an empty sequence.
Examples
Assume the context node is the following element:
and that it is validated against the following schema:
xmlns:xsi=“http://www.w3.org/2001/XMLSchema-instance”>
Expression | Result |
nilled(title) | true |
nilled(first) | false |
nilled(middle) | false |
nilled(last) | false |
Usage
The
xsi:nil
attribute is an explicit way of saying that a value is absent. Although its meaning is entirely up to the application, the intended purpose is to distinguish unknown data (a person's title is unknown) from data known to be empty (a person is known to have no middle name). When an element that has
xsi:nil
set to true is validated, it is given the
nilled
property in the data model, and this function allows this property to be tested. For most practical purposes, using the
nilled()
function achieves the same as testing the
xsi:nil
attribute directly, so long as you are sure that the element has been validated.
The
nilled
property is present in the data model primarily to support the rules for type matching: a
nilled
element will not match a type of the form
element(N
,
T)
, but it will match
element(N, T?)
. These rules are given in Chapter 11, in the section
Matching Elements and Attributes
on page 672. This function is provided to allow direct access to this property.