Share to: share facebook share twitter share wa share telegram print page

XPath 2.0

XPath 2.0 is a version of the XPath language defined by the World Wide Web Consortium, W3C. It became a recommendation on 23 January 2007.[1] As a W3C Recommendation it was superseded by XPath 3.0 on 10 April 2014.

XPath is used primarily for selecting parts of an XML document. For this purpose the XML document is modelled as a tree of nodes. XPath allows nodes to be selected by means of a hierarchic navigation path through the document tree.

The language is significantly larger than its predecessor, XPath 1.0, and some of the basic concepts such as the data model and type system have changed. The two language versions are therefore described in separate articles.

XPath 2.0 is used as a sublanguage of XSLT 2.0, and it is also a subset of XQuery 1.0. All three languages share the same data model (the XDM), type system, and function library, and were developed together and published on the same day.

Data model

Every value in XPath 2.0 is a sequence of items. The items may be nodes or atomic values. An individual node or atomic value is considered to be a sequence of length one. Sequences may not be nested.

Nodes are of seven kinds, corresponding to different constructs in the syntax of XML: elements, attributes, text nodes, comments, processing instructions, namespace nodes, and document nodes. (The document node replaces the root node of XPath 1.0, because the XPath 2.0 model allows trees to be rooted at other kinds of node, notably elements.)

Nodes may be typed or untyped. A node acquires a type as a result of validation against an XML Schema. If an element or attribute is successfully validated against a particular complex type or simple type defined in a schema, the name of that type is attached as an annotation to the node, and determines the outcome of operations applied to that node: for example, when sorting, nodes that are annotated as integers will be sorted as integers.

Atomic values may belong to any of the 19 primitive types defined in the XML Schema specification (for example, string, boolean, double, float, decimal, dateTime, QName, and so on). They may also belong to a type derived from one of these primitive types: either a built-in derived type such as integer or Name, or a user-defined derived type defined in a user-written schema.

Type system

The XDM type hierarchy

The type system of XPath 2.0 is noteworthy for the fact that it mixes strong typing and weak typing within a single language.

Operations such as arithmetic and boolean comparison require atomic values as their operands. If an operand returns a node (for example, @price * 1.2), then the node is automatically atomized to extract the atomic value. If the input document has been validated against a schema, then the node will typically have a type annotation, and this determines the type of the resulting atomic value (in this example, the price attribute might have the type decimal). If no schema is in use, the node will be untyped, and the type of the resulting atomic value will be untypedAtomic. Typed atomic values are checked to ensure that they have an appropriate type for the context where they are used: for example, it is not possible to multiply a date by a number. Untyped atomic values, by contrast, follow a weak typing discipline: they are automatically converted to a type appropriate to the operation where they are used: for example with an arithmetic operation an untyped atomic value is converted to the type double.

Path expressions

The location paths of XPath 1.0 are referred to in XPath 2.0 as path expressions. Informally, a path expression is a sequence of steps separated by the "/" operator, for example a/b/c (which is short for child::a/child::b/child::c). More formally, however, "/" is simply a binary operator that applies the expression on its right-hand side to each item in turn selected by the expression on the left hand side. So in this example, the expression a selects all the element children of the context node that are named <a>; the expression child::b is then applied to each of these nodes, selecting all the <b> children of the <a> elements; and the expression child::c is then applied to each node in this sequence, which selects all the <c> children of these <b> elements.

The "/" operator is generalized in XPath 2.0 to allow any kind of expression to be used as an operand: in XPath 1.0, the right-hand side was always an axis step. For example, a function call can be used on the right-hand side. The typing rules for the operator require that the result of the first operand is a sequence of nodes. The right hand operand can return either nodes or atomic values (but not a mixture). If the result consists of nodes, then duplicates are eliminated and the nodes are returned in document order, an ordering defined in terms of the relative positions of the nodes in the original XML tree.

In many cases the operands of "/" will be axis steps: these are largely unchanged from XPath 1.0, and are described in the article on XPath 1.0.

Other operators

Other operators available in XPath 2.0 include the following:

Operators Effect
+, -, *, div, mod, idiv Arithmetic on numbers, dates, and durations
=, !=, <, >, <=, >= General comparison: compare arbitrary sequences. The result is true if any pair of items, one from each sequence, satisfies the comparison
eq, ne, lt, gt, le, ge Value comparison: compare single items
is Compare node identity: true if both operands are the same node
<<, >> Compare node position, based on document order
union, intersect, except Compare sequences of nodes, treating them as sets, returning the set union, intersection, or difference
and, or boolean conjunction and disjunction. Negation is achieved using the not() function.
to defines an integer range, for example 1 to 10
instance of determines whether a value is an instance of a given type
cast as converts a value to a given type
castable as tests whether a value is convertible to a given type

Conditional expressions may be written using the syntax if (A) then B else C.

XPath 2.0 also offers a for expression, which is a small subset of the FLWOR expression from XQuery. The expression for $x in X return Y evaluates the expression Y for each value in the result of expression X in turn, referring to that value using the variable reference $x.

Function library

The function library in XPath 2.0 is greatly extended from the function library in XPath 1.0. (Bold items are available in XPath 1.0)

The functions available include the following:

Purpose Example Functions
General string handling lower-case, upper-case, substring, substring-before, substring-after, translate, starts-with, ends-with, contains, string-length, concat, normalize-space, normalize-unicode
Regular expressions matches, replace, tokenize
Arithmetic count, sum, avg, min, max, round, floor, ceiling, abs
Dates and times adjust-dateTime-to-timezone, current-dateTime, day-from-dateTime, month-from-dateTime, days-from-duration, months-from-duration, etc.
Properties of nodes name, node-name, local-name, namespace-uri, base-uri, nilled
Document handling doc, doc-available, document-uri, collection, id, idref
URIs encode-for-uri, escape-html-uri, iri-to-uri, resolve-uri
QNames QName, namespace-uri-from-QName, prefix-from-QName, resolve-QName
Sequences insert-before, remove, subsequence, index-of, distinct-values, reverse, unordered, empty, exists
Type checking one-or-more, exactly-one, zero-or-one

Backwards compatibility

Because of the changes in the data model and type system, not all expressions have exactly the same effect in XPath 2.0 as in 1.0. The main difference is that XPath 1.0 was more relaxed about type conversion, for example comparing two strings ("4" > "4.0") was quite possible but would do a numeric comparison; in XPath 2.0 this is defined to compare the two values as strings using a context-defined collating sequence.

To ease transition, XPath 2.0 defines a mode of execution in which the semantics are modified to be as close as possible to XPath 1.0 behavior. When using XSLT 2.0, this mode is activated by setting version="1.0" as an attribute on the xsl:stylesheet element. This still doesn't offer 100% compatibility, but any remaining differences are only likely to be encountered in unusual cases.

Support

Support for XPath 2.0 is still limited.

References

  1. ^ "XML and Semantic Web W3C Standards Timeline" (PDF). 4 February 2012.

This information is adapted from Wikipedia which is publicly available.

Read other articles:

Tineola bisselliella Tarma, o tignola,[1] è il nome comunemente utilizzato per indicare alcune specie di lepidotteri appartenenti alla famiglia Tineidae, le cui larve si nutrono di tessuti come lana, seta e anche cotone, oltre ad altre tipologie di sostanze contenenti cheratina. Si nutre talvolta anche di capelli umani e può rifugiarsi negli armadi e cibarsi dei vestiti presenti. Indice 1 Varietà e caratteristiche 2 Nutrimento 3 Ciclo vitale 4 Difesa dai danni 5 Note 6 Altri progetti …

كامبرلاند هيل     الإحداثيات 41°58′15″N 71°27′35″W / 41.970833333333°N 71.459722222222°W / 41.970833333333; -71.459722222222  تقسيم إداري  البلد الولايات المتحدة[1]  التقسيم الأعلى مقاطعة بروفيدانس  خصائص جغرافية  المساحة 8.753595 كيلومتر مربع8.807735 كيلومتر مربع (1 أبريل 2010)  ارتف

國立臺灣大學電機資訊學院类型學院建立日期1997年隶属國立臺灣大學下属電機工程學系資訊工程學系光電工程學研究所電信工程學研究所電子工程學研究所資訊網路與多媒體研究所生醫電子與資訊學研究所資訊電子研究中心物聯網研究中心奈米機電系統研究中心綠色電能研究中心院长張耀文副院长吳宗霖林恭如逄愛君教师数227人(2019年1月)学生数3585人(2019年1月)本科生1353

Торос — термін, який має кілька значень. Ця сторінка значень містить посилання на статті про кожне з них.Якщо ви потрапили сюди за внутрішнім посиланням, будь ласка, поверніться та виправте його так, щоб воно вказувало безпосередньо на потрібну статтю.@ пошук посилань саме …

هذه المقالة يتيمة إذ تصل إليها مقالات أخرى قليلة جدًا. فضلًا، ساعد بإضافة وصلة إليها في مقالات متعلقة بها. (أبريل 2019) جيسيكا تايلور معلومات شخصية الميلاد 23 يونيو 1980 (43 سنة)  برستون  مواطنة المملكة المتحدة  الحياة العملية المهنة مغنية  اللغات الإنجليزية  تعديل مصدر…

Africans who escaped from slavery in the Colony of Jamaica Jamaican MaroonsRegions with significant populations Jamaica Sierra LeoneLanguagesJamaican Patois, KromantiReligionJamaican Maroon religionRelated ethnic groupsCoromantee, Jamaicans of African descent, Sierra Leone Creoles, Maroon people Jamaican Maroons descend from Africans who freed themselves from slavery on the Colony of Jamaica and established communities of free black people in the island's mountainous interior, primaril…

Este artigo não cita fontes confiáveis. Ajude a inserir referências. Conteúdo não verificável pode ser removido.—Encontre fontes: ABW  • CAPES  • Google (N • L • A) (Junho de 2016) Gafanhoto-soldado Chromacris speciosa Classificação científica Reino: Animalia Filo: Arthropoda Classe: Insecta Ordem: Orthoptera Família: Romaleidae Género: Chromacris Espécie: C. speciosa Nome binomial Chromacris speciosa Ninfas de gafanhoto…

Ancient Greek city in Ionia, modern Turkey For other uses, see Magnesia (disambiguation). Magnesia on the MaeanderΜαγνησία ἡ πρὸς ΜαιάνδρῳThe Propylaea of Magnesia on the MaeanderShown within TurkeyShow map of TurkeyMagnesia on the Maeander (Aegean Sea)Show map of Aegean SeaLocationTekin, Aydın Province, TurkeyRegionIoniaCoordinates37°51′10″N 27°31′38″E / 37.85278°N 27.52722°E / 37.85278; 27.52722TypeSettlementHistoryBuilderMagnetian a…

及川雅貴阪神虎 – 背号37投手出生: (2001-04-18) 2001年4月18日(22歲) 日本千葉縣匝瑳市 打擊:左 投球:左 首秀2021年5月28日,代表阪神虎生涯成績 (2023年球季止)勝投-敗投5-4中繼-救援17-0三振-四壞78-38防禦率3.07 球队 橫濱高等學校 阪神虎(2021年-) 及川雅貴(日语:及川 雅貴/およかわ まさき Oyokawa Masaki,2001年4月18日—)是日本千葉縣匝瑳市出身的職業棒

Mexican drug trafficker (1949-2014) El Azul redirects here. For the Junior H and Peso Pluma song, see El Azul (song). In this Spanish name, the first or paternal surname is Esparragoza and the second or maternal family name is Moreno. Juan José Esparragoza MorenoBorn (1949-02-03) February 3, 1949 (age 74)Huixiopa, Badiraguato, Sinaloa, MexicoDied(2014-06-07)June 7, 2014 (unconfirmed)[1]MexicoOther names Aliases: El Azul El AzulJuan RoblesEl HuaracheJuan RobledoArturo B…

Sauce made primarily from tomatoes For the table sauce referred to in some countries as tomato sauce, see Ketchup. For the pasta sauce mainly used in Italian cuisine, see Neapolitan sauce. Tomato sauceFresh tomato sauceAlternative namesSalsa Roja, SugoTypeSaucePlace of originMexico[1]Region or stateAztec EmpireMain ingredientsTomatoesVariationsSalsa picante, Arrabbiata sauce Cookbook: Tomato sauce  Media: Tomato sauce Tomato sauce (also known as salsa roja in Spanish, sauce toma…

British-born New Zealand archaeologist This biography of a living person needs additional citations for verification. Please help by adding reliable sources. Contentious material about living persons that is unsourced or poorly sourced must be removed immediately from the article and its talk page, especially if potentially libelous.Find sources: Charles Higham archaeologist – news · newspapers · books · scholar · JSTOR (September 2023) (Learn how an…

Статтю «Исик-Кель» створено в рамках Місяця Азії(1 листопада — 30 листопада 2017 року) Ця стаття є частиною Проєкту:Екологія (рівень: II, важливість: Середня) Портал «Екологія»Мета проєкту — покращувати усі статті, присвячені екології й охороні природи. Ви можете покращити цю

Railway station near Rosh HaAyin, Israel For the currently open railway station in Rosh HaAyin, see Rosh HaAyin North railway station. Rosh HaAyin South railway stationתחנת הרכבת ראש העין דרוםThe disused platforms in 2017General informationCoordinates32°06′15″N 34°56′05″E / 32.10417°N 34.93472°E / 32.10417; 34.93472Owned byIsrael RailwaysLine(s)Eastern RailwayPlatforms2Tracks3HistoryOpened1915Closed13 April 2003 The Station and its surround…

France-related events during the year of 2023 ← 2022 2021 2020 2019 2018 2023 in France → 2024 2025 2026 2027 2028 Decades: 2000s 2010s 2020s See also:Other events of 2023History of France  • Timeline  • Years Events in the year 2023 in France. Incumbents President – Emmanuel Macron (REM) Prime Minister – Élisabeth Borne (REM) Government – Borne government Events January 11 January – Six people are injured in a knife attack at Paris's Gare du …

Danza de los DragonesFecha 129 DC - 131 DC (3 años)Lugar PonienteCasus belli Enfrentamiento entre Aegon II Targaryen y Rhaenyra Targaryen por el trono.Resultado Muerte de los pretendientes Rhaenyra I y Aegon IIAscenso de Aegon III al trono.Consecuencias Muerte de los dragones Declive de la Casa TargaryenBeligerantes Los Negros Casa Targaryen por RhaenyraCasa VelaryonCasa Arryn Casa Stark Casa TullyCasa GreyjoyCasa BlackwoodCasa FreyCasa Bar EmmonCasa BeesburyCasa BruneCasa CaswellCasa CeltigarC…

Air sodaJenisair minum, Minuman berkarbonasi dan minuman ringan PenyiapanKarbonasi [sunting di Wikidata]lbs Air soda atau air berkarbonasi (Inggris: carbonated water, club soda, soda water, atau sparkling water) adalah air yang dikarbonasikan dan dibuat bersifat effervescent dengan penambahan gas karbon dioksida di bawah tekanan. Air soda mendapatkan namanya dari garam natrium yang dikandungnya mengatakan senyawa 'bergaram' menambah kualitas yang berbeda bagi sejumlah minuman beralkohol dan …

NYU College of Arts & ScienceTypePrivateEstablished1832; 191 years ago (1832)Parent institutionNew York UniversityDeanWendy SuzukiStudents7,660Address32 Waverly Pl, New York, NY 10003, New York City, New York, 10003, U.S.ColorsMayfair Violet[1]  Websitecas.nyu.edu The New York University College of Arts & Science (CAS) is the primary liberal arts college of New York University (NYU). The school is located near Gould Plaza next to the Courant Institute of Ma…

Japanese manga series by LINK and Kotaro Shono and its franchise World's End HaremCover of the first tankōbon volume, featuring Mira Suō終末のハーレム(Shūmatsu no Hāremu)GenreErotic thriller[1]Harem[2]Science fiction[3] MangaWritten byLINKIllustrated byKotaro ShonoPublished byShueishaEnglish publisherNA: Seven Seas EntertainmentImprintJump Comics+MagazineShōnen Jump+DemographicShōnenOriginal runMay 8, 2016 – May 7, 2023Volumes18 (List of …

This article needs to be updated. Please help update this article to reflect recent events or newly available information. (November 2022) Television channel Federal televisionFederalna televizijaCurrent FTV screen logo used since 2014.CountryBosnia and HerzegovinaNetworkRTVFBiHAffiliatesFederalni RadioHeadquartersSarajevoProgrammingLanguage(s)Bosnian, Croatian, SerbianPicture format16:9 1080i (HDTV)OwnershipOwnerFederation of Bosnia and HerzegovinaKey peopleDžemal Šabić (head of FTV)Sister c…

Kembali kehalaman sebelumnya

Lokasi Pengunjung: 18.217.160.132