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

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


        xmlns:soap=“http://schemas.xmlsoap.org/soap/envelope/”

        xmlns:xs=“http://www.w3.org/2001/XMLSchema”>

  

   

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

               xmlns:soap=“”>

     Hello

   

  


Expression
Result
in-scope-prefixes(/soap:Envelope)
(“xs”,
“soap”,
“xml”)
(in any order)
in-scope-prefixes(//*:inputString)
(“xs”,
“”,
“xsi”,
“xml”)
(in any order)

Usage

Like the namespace axis that it replaces, this function is unlikely to be needed every day of the week. It is generally needed only when dealing with documents that use namespace prefixes as part of the content of elements and attributes (and not only in forming the names of elements and attributes). I have also seen situations where it is necessary simply to detect whether a particular namespace is declared, regardless whether or not it is actually used. For example, you might want to find all your stylesheets that declare the namespace
http://icl.com/saxon
because you have decided to migrate from Saxon 6.5 (which uses this namespace) to Saxon 9.x (which does not). You could find these using the query:

collection(“stylesheets”)[//*[“http://icl.com/saxon” =

                                   for $p in in-scope-prefixes(.)

                                   return namespace-uri-for-prefix($p, .)]]

See Also

namespace-uri-for-prefix()
on page 839

resolve-QName()
on page 864

insert-before

The
insert-before()
function returns a sequence constructed by inserting an item, or a sequence of items, at a given position within another sequence.

For example,
insert-before((“a”,“b”,“c”), 2, “X”)
returns
(“a”, “X”, “b”, “c”)
.

Signature

Argument
Type
Meaning
sequence-1
item()*
The original sequence
position
xs:integer
The position in the original sequence where the new items are to be inserted
sequence-2
item()*
The items that are to be inserted
Result
item()*
The constructed sequence

Effect

Remember that sequences are immutable: despite its name, this function doesn't modify the supplied sequence; it constructs a new sequence containing items copied from the two input sequences.

The returned sequence consists of all items in
sequence-1
whose position is less than the specified
position
, followed by all items in
sequence-2
, followed by all remaining items in
sequence-1
. Positions, as always, are numbered starting at one. It's not an error if
position
is outside the actual range of positions in the sequence.

In other words, the result is the same as the value of the expression:

$sequence-1[position() lt $position],

$sequence-2,

$sequence-1[position() ge $position]

Examples

Expression
Result
insert-before(1 to 5, 4, (99, 100))
(1, 2, 3, 99, 100, 4, 5)
insert-before(1 to 5, 0, 99)
(99, 1, 2, 3, 4, 5)
insert-before(1 to 5, 10, 99)
(1, 2, 3, 4, 5, 99)

Usage

Although functions are provided to insert items into and remove items from a sequence, there is no function to replace the item at a given position
$p
. To achieve this, you can write:

insert-before(remove($seq, $p), $p, $new-item)

or perhaps more simply:

$seq[position() lt $position],

$new-item,

$seq[position() gt $position]

See Also

remove()
on page 861

,
operator on page 634 in Chapter 10

iri-to-uri

iri-to-uri()
converts an IRI (Internationalized Resource Identifier) into a URI by percent-encoding special characters according to the rules of RFC 3986 and RFC 3987.

For example,
iri-to-uri(‘http://www.wikipedia.org/Gerhard Schröder’)
returns
http://www.wikipedia.org/Gerhard%20Schr%C3%B6der
.

Other books

The Heretic by David Drake, Tony Daniel
Playing by Heart by Anne Mateer
Nice Girls Don't Ride by Roni Loren
The Horned Viper by Gill Harvey
Perfectly Matched by Heather Webber
Behind the Candelabra: My Life With Liberace by Scott Thorson, Alex Thorleifson
Taking the Fall by Monday, Laney
Mr. Shivers by Bennett, Robert Jackson