By John E. Simpson
Price: $29.99 USD
£17.50 GBP
Cover | Table of Contents | Colophon
Why should I care about XPath and XPointer? What do they even do?
<house_pet_hazards>
<hazard type="cleanup">
<name>hairballs</name>
<guilty_party species="cat">Dilly</guilty_party>
<guilty_party species="cat">Nameless</guilty_party>
<guilty_party species="cat">Katie</guilty_party>
</hazard>
<hazard type="cleanup">
<name>miscellaneous post-ingestion surprises</name>
<guilty_party species="cat">Dilly</guilty_party>
<guilty_party species="cat">Katie</guilty_party>
<guilty_party species="dog">Kianu</guilty_party>
<guilty_party species="snake">Mephisto</guilty_party>
</hazard>
<hazard type="phys_jeopardy">
<name>underfoot instability</name>
<guilty_party species="cat">Dilly</guilty_party>
<guilty_party species="snake">Mephisto</guilty_party>
</hazard>
</house_pet_hazards>Why should I care about XPath and XPointer? What do they even do?
<house_pet_hazards>
<hazard type="cleanup">
<name>hairballs</name>
<guilty_party species="cat">Dilly</guilty_party>
<guilty_party species="cat">Nameless</guilty_party>
<guilty_party species="cat">Katie</guilty_party>
</hazard>
<hazard type="cleanup">
<name>miscellaneous post-ingestion surprises</name>
<guilty_party species="cat">Dilly</guilty_party>
<guilty_party species="cat">Katie</guilty_party>
<guilty_party species="dog">Kianu</guilty_party>
<guilty_party species="snake">Mephisto</guilty_party>
</hazard>
<hazard type="phys_jeopardy">
<name>underfoot instability</name>
<guilty_party species="cat">Dilly</guilty_party>
<guilty_party species="snake">Mephisto</guilty_party>
</hazard>
</house_pet_hazards>(element bottle
[...instructions...])bottle element in the source document. You
can also navigate to various portions of the source document based on
SELECT emp_id, emp_name FROM emp_table WHERE emp_id = "73519"
WHERE clause and the boldfaced portion of the
XQuery query):
{for $b in document("emp_table.xml")//employee[emp_id = "73519"]
return
<p>{ emp_id }{ emp_name }</p>
}<p> <emp_id>73519</emp_id> <emp_name>DeGaulle,Charles</emp_name> </p>
WHERE clause is based on
XPath, it's not quite XPath as
you will come to understand it. (The XPath-based portion of the above
XQuery statement is in boldface.) Second, XQuery's
approach to returning an XML result from an XML source conflicts with
the approach taken by the XSLT spec for the same purpose. And third
is the XQuery syntax itself, which though vaguely resembling
XML, is not exactly XML. The
"meaning" of an XQuery query is
bound up not in elements and attributes but in special element text
content delimited by curly braces (the <?xml-stylesheet type="text/xsl" href="battleinfo.xsl"?>
<battleinfo conflict="WW2">
<name>Guadalcanal</name>
<!-- Note: Add dates, units, key personnel -->
<geog general="Pacific Theater">
<islands>
<name>Guadalcanal</name>
<name>Savo Island</name>
<name>Florida Islands</name>
</islands>
</geog>
</battleinfo><?xml-stylesheet type="text/xsl" href="battleinfo.xsl"?>
<battleinfo conflict="WW2">
<name>Guadalcanal</name>
<!-- Note: Add dates, units, key personnel -->
<geog general="Pacific Theater">
<islands>
<name>Guadalcanal</name>
<name>Savo Island</name>
<name>Florida Islands</name>
</islands>
</geog>
</battleinfo>
taxcut
/
/taxcuts
/taxcuts/taxcut
taxcuts
element whose names are "taxcut"
2001
"2001"
/taxcuts/taxcut[attribute::year="2001"]
taxcuts
element, as long as those child elements are named
"taxcut" and have a
year attribute whose value is the string
"2001"
/taxcuts/taxcut[@year="2001"]
", then a string within it must be enclosed in
single quotation marks or apostrophes: '. If you
prefer to enclose attribute values in single quotes, the embedded
string(s) must appear in double quotes.
"a
string" and "a
string" are functionally identical. The
former is simply more convenient and legible.
select, applied to the
xsl:value-of element (which is empty) and others.
The value of this attribute is an XPath expression. So you might see
code such as the following:
<xsl:value-of select="fallacy[type='pathetic']"/>
http://www.w3.org/TR/REC-xml-names. The QName
of a node, in general, is the identifier for the node as it actually
appears in an instance document, including any namespace prefix. For
example, an element whose start tag is
<concerto> has a QName of
"concerto"; if the start tag were
<mml:concerto>, the QName would be
"mml:concerto."
<ChangeInMyPocket> <Quarters quantity="1"/> <Dimes quantity="1"/> <Nickels quantity="1"/> <Pennies quantity="3"/> <!-- No vending-machine purchase in my immediate future --> </ChangeInMyPocket>
quantity attributes (or any three,
two, or one of them) and the comment; or just the root node and the
comment; or just the Quarters element, the
Pennies element, and the
quantity attribute of the
Nickels element. The nodes in the resulting
node-set need not share any significant formal relationship in the
context of the document itself. But in all cases, these nodes
suddenly acquire relationships to others in a given node-set, simply
by virtue of their membership in that node-set.
ChangeInMyPocket, Quarters,
Nickels, Dimes, and
Pennies elements). A location path returning all
the quantity attributes and the comment would also
have a context size of 5.
ChangeInMyPocket element, the
region=" NW
SE" (note leading blank spaces and multiple spaces
between the "NW" and "SE"), its
normalized value would be "NW
SE". Also note, though, that this normalization
depends on the attribute's type, as declared in a
DTD or schema. If the attribute type is CDATA, those interior blank
spaces would be assumed to be significant and not normalized.
Therefore, if the region attribute is (say) of
type NMTOKENS, the interior whitespace is collapsed; if
it's CDATA, the whitespace remains.
|
Node type
|
String-value
|
|---|---|
|
Root
|
Concatenated value of all text nodes in the document
|
|
Element
|
Concatenated value of all text nodes within the scope of the
element's start and end tags, including the text
nodes contained by any descendant elements
|
<xsl:value-of select="expression"/><a xlink:href="xpointer(expression)">Table of Contents</a>"I should have been a pair of ragged claws" 119.725
<xsl:value-of select="expression"/><a xlink:href="xpointer(expression)">Table of Contents</a>"I should have been a pair of ragged claws" 119.725
/customers/customer/invoice/item/quantity
customers
element, and step 2, to the customer elements that
are children of that root element.
invoice children of each
customer element. The first and second
customer elements have two and one such children,
respectively; the third customer element has no
invoice children, and as a result this
customer effectively drops out of consideration as
a match for further location steps. For purposes of content retrieved
by this location path, in other words, axis::nodetest[predicate][
and ]) that enclose it.
|. In that section, you saw this example:
/customers/customer/invoice | /customers/customer/cust_info
customers element (thereby excluding from
consideration any content in the document that precedes or follows
the root element), then to customer children of
the root element, and finally to invoice children
of those customer children.
invoice | cust_info
invoice
children of the context node for the compound location path as a
whole. Likewise, the second selects all cust_info
children of the context node for the compound location path as a
whole — not all cust_info
children of the invoice elements selected by the
first location path. The results of the two selections are simply
unioned together into a single node-set.
function_name(arg1, ...)
function_name(arg1, ...)
gapper(prong)
gapper is the function name and
prong, a single argument provided (or
"passed") to the function. Under
many circumstances, you wouldn't pass a function
like this the literal token p,
r, o, n,
g; rather, this is just a placeholder, a reminder
to you of what you do pass to it. In this form, the
function syntax is called a
prototype. When you actually use (or
"call" or
"invoke") a function,
you
typically substitute a literal value for each argument. So an actual
call to our hypothetical string
string1, string2, and so on.
nodeset
boolean
number
number1, number2, and so on.
anytype
?
my_func( ) function might come with a prototype
such as my_func(string?). This would mean that
when you call |
Operator
|
Description
|
Example
|
|---|---|---|
+ |
Adds two values
|
(//weight)[1] + (//weight)[2] |
- |
Subtracts one value from another
|
(//weight)[3] - (//weight)[1] |
* |
Multiplies one value times another
|
(//weight)[3] * 5 |
div |
Divides one value by another
|
(//weight)[3] div 1016.0469 |
mod |
Returns the remainder after dividing one value by another
|
(//weight)[3] mod 1016.0469 |
div and
mod operators could use bit more explanation.
div operator at all? Why not
just use the
more familiar forward slash character, /, to
divide one value by another?
http://www.vbxml.com.
<!-- Basic astrological data for T's and J's signs -->
<?xml-stylesheet type="text/xsl" href="astro.xsl"?>
<astro xmlns:xlink="http://www.w3.org/1999/xlink">
<sign start-date="12-22" end-date="01-20">
<name type="main">Capricorn</name>
<name type="alt">The Sea-Goat</name>
<!-- capricorn.gif corresponds to Unicode 3.0 #x2651 -->
<symbol xlink:type="simple" xlink:href="capricorn.gif"/>
<ruling_planet>Saturn</ruling_planet>
<ruling_planet>Earth</ruling_planet>
<energy>Feminine</energy>
<quality>Cardinal</quality>
<anatomy>
<part>Bones</part>
<part>Knees</part>
</anatomy>
</sign>
<sign