XSLT 2.0 and XPath 2.0 Programmer's Reference, 4th Edition (606 page)

BOOK: XSLT 2.0 and XPath 2.0 Programmer's Reference, 4th Edition
13.25Mb size Format: txt, pdf, ePub

Although this function makes the prefix of a QName available to applications, it should be used with care. It is good practice to allow document originators to choose arbitrary prefixes, and applications should attach significance only to the namespace URI, not to the prefix.

Examples

Consider this source document, validated using a schema-aware processor:


        xmlns:xsi=“http://www.w3.org/2001/XMLSchema-instance”

        xsi:type=“my:dateType”>2008-01-01

Expression
Result
prefix-from-QName(node-name(my:doc))
“my”
prefix-from-QName(node-name(my:doc/@xsi:type))
“xsi”
prefix-from-QName(node-name(my:doc/@security))
()
prefix-from-QName(my:doc/@xsi:type)
“my”
prefix-from-QName(node-name(my:doc/@missing))
()

See Also

local-name-from-QName()
on page 826

namespace-uri-from-QName()
on page 841

QName

The
QName()
function returns a value of type
xs:QName
, given a namespace URI and the lexical form of the name. For example,
QName(“http://www.w3.org/1999/xhtml”, “html”)
returns the name
html
in the XHTML namespace.

Signature

Argument
Type
Meaning
namespace
xs:string?
The namespace URI part of the
xs:QName
. To construct a
QName
that is in no namespace, supply either a zero-length string or an empty sequence.
lexical-qname
xs:string
The lexical form of the QName, with or without a prefix. It must conform to the syntax of a QName as defined in the XML Namespaces specification (which is the same as the lexical space for an
xs:QName
defined in XML Schema).
Result
xs:QName
The newly constructed
xs:QName
.

Effect

A value of type
xs:QName
has two significant parts (a namespace URI, and a local name), and it also retains information about the namespace prefix. This function constructs an
xs:QName
value from these components.

XPath uses the term
lexical QName
to refer to a QName in the form
local-name
or
prefix:local-name
, and
expanded QName
to refer to the underlying value of the QName, in which the prefix has been resolved to a namespace URI by reference to some set of namespace declarations. This function creates an expanded QName directly, without going through the stage of resolving the prefix. The namespace URI of the QName is taken from the
namespace
argument. The local-name part is taken from the
lexical-name
after stripping off any prefix; and the prefix part is taken from the prefix in the
lexical-name
if there is one.

It's an error to supply a prefix without also supplying a namespace URI.

Examples

Expression
Result
QName(“http://www.w3.org/XML/1998/namespace”, “xml:space”)
The
xs:QName
usually written as
xml:space
QName(“http://www.w3.org/2001/XMLSchema-instance”, “xsi:type”)
The
xs:QName
usually written as
xsi:type
QName(“”, “html”)
An
xs:QName
with local name
html
in no namespace
QName(“http://www.w3.org/1999/xhtml”, “html”)
An
xs:QName
with local name
html
in the XHTML namespace, with no prefix

Other books

Mean Ghouls by Stacia Deutsch
Ghost Radio by Leopoldo Gout
The Eye of the Abyss by Marshall Browne
His Tempest by Candice Poarch
Gun Control in the Third Reich by Stephen P. Halbrook
The Magus by John Fowles
Way Out of Control by Caldwell, Tatiana
The Fourth Man by K.O. Dahl