[Accessibility conventions are described at the bottom of the page]
*** This is a free preview excerpt of a commercial publication. ***

3. XPath data model
[> 4.][< 2.4.1][^^^]
3.0 The need for abstractions
[> 3.0.1][> 4.][< 3.][^^][^^^]
Dealing with information, not markup
[[1] - all input and output information manipulated in an abstract fashion
 [1] - separate node structures of information:
[[2] - source trees (example on [Figure 2.1])
[[3] - the main source tree is optional in XSLT 2
 [3] - [T1.0]the main source tree is required in XSLT 1
 [3] - multiple additional source documents may be read as separate node structures
][2] - operation tree (stylesheet example on [Figure 2.2])
 [2] - result tree (example on [Figure 2.3])
[[3] - [T2.0]multiple result trees can be created using XSLT 2
]][1] - knowledge of input markup and control of output markup out of the hands of the transform writer
[[2] - the writer deals with nodes of information, not characters of markup
]]
Traversing a source document or transform document predictably
[[1] - XML syntax processed into an abstract data model tree of nodes
[[2] - documents are described according to a data model for the XML markup
[[3] - interpreted in terms of the XML Information Set
[[4] - [http://www.w3.org/TR/xml-infoset/]
][3] - [P2.0]maintained in terms of a formal XPath data model
[[4] - [http://www.w3.org/TR/xpath-datamodel/]
]][2] - all nodes created are typed, and have a value that can be used as a string of text
 [2] - some nodes have an associated name, while other nodes are unnamed
 [2] - [P2.0]some nodes have types based on W3C Schema post-schema validation infoset
[[3] - [http://www.w3.org/TR/xmlschema-1/#d0e504]
][2] - the processor performs all operations using the node tree, not the document directly
[[3] - the actual markup used in input instances is not preserved
 [3] - there are no constraints or requirements of the XML source in that any well-formed markup chosen by the author of an XML document is represented abstractly in the tree
]][1] - XPath node tree navigation
[[2] - the transform can navigate around the source node tree in many directions
 [2] - thirteen axes of direction that can be traversed relative to the context (current) node
 [2] - the transform is responsible for specifying which source nodes get processed when and how
]]
The XPath data model and the DOM data model are different
[[1] - the Document Object Model (DOM) is a data model of the information including the syntax in an XML document
 [1] - XPath is a data model of the information not including the syntax in an XML document
]
Consider an XML document comprised of 26 empty and non-empty elements named "A" through "Z" (without any text or new-line characters of any kind):
[Example 3-1:
01  <A><B><C/></B><D/><E/><F><G><H/></G><I/><J><K/><L><M/><N/></L><O/>
02  <P/><Q><R/><S/></Q></J><T/><U><V/></U></F><W/><X/><Y><Z/></Y></A>
]
The following depicts this document's complete node tree (not showing namespaces):
[Figure 3.1: Nodes found along axes of different directions
A large node tree is shown with about 6 levels of hierarchy. Dotted lines, one for each of 11 of the 13 possible axes, surround collections of the nodes (some dotted lines wholly enclosing other dotted lines), each representing those nodes along that axis.
]
[[1] - the root of the tree is at the top
 [1] - the leaves of the tree are towards the bottom
 [1] - the context node in this example is in the center with the bold circle
 [1] - the dotted lines completely surround the nodes of the tree that are members of each axis relative to the context node
]
3.0.1 Data types
[> 3.0.2][> 4.][< 3.0][^][^^][^^^]
[P1.0]XPath 1.0 treats node values as strings and has a limited number of data types
[[1] - boolean, number, string, node set and result tree fragment
]
[P2.0]XPath 2.0 introduces data types based on the W3C Schema data type hierarchy:
[Figure 3.2: W3C XML Schema data type hierarchy
]
When referenced in transforms, types must be namespace qualified:
[[1] - e.g. xmlns:xs="http://www.w3.org/2001/XMLSchema"
[[2] - any prefix can be used
]]
[P2.0]Types allowed for casting are value constructors when used with function syntax:
[[1] -
<xsl:variable name="meetingStart" as="xs:dateTime" 
              select="xs:dateTime('2005-12-04T11:00:00Z')"/>
]
[P2.0]Some types are only available in schema-aware versions of the processor
[[1] - e.g. NOTATION and most XSD derived types
]
3.0.2 Sequence types
[> 3.0.3][> 4.][< 3.0.1][^][^^][^^^]
A sequence type is a declaration combination of data type and cardinality
[[1] - item() - union of any node type or atomic value
 [1] - node() - any node (tree construction - see [Chapter 3. XPath data model])
[[2] - seven types of tree nodes described in this chapter
 [2] - e.g. element(), attribute(), text(), etc.
 [2] - three types of named tree nodes described in this chapter
 [2] - e.g. element(name), attribute(name), processing-instruction(name)
 [2] - two types of typed tree nodes described in this chapter
 [2] - e.g. element(name,type), attribute(name,type)
 [2] - two types of declared tree nodes described in this chapter
 [2] - e.g. schema-element(name), schema-attribute(name)
 [2] - qualified document nodes described in this chapter
 [2] - e.g. document-node(element-name-type-declaration-test)
 [2] - user-defined globally-declared types
 [2] - e.g. mySchema:zip-code
][1] - xs:anyAtomicType - any atomic value (lexical construction - see [Figure 3.2])
[[2] - W3C Schema data types
 [2] - e.g. xs:string, xs:integer, xs:duration, xs:gMonth, etc.
 [2] - XPath 2 data types
 [2] - e.g. xs:dayTimeDuration, xs:yearMonthDuration
 [2] - e.g. xs:untypedAtomic - an atomic value without a type
]]
Non-zero cardinality specified using Kleene operators "+", "?" and "*", for example:
[[1] - empty-sequence() - zero to zero (i.e. no items of any kind)
 [1] - xs:string - exactly one string (i.e. mandatory)
 [1] - xs:string? - zero or one strings (i.e. optional)
 [1] - xs:string+ - one or more strings (i.e. mandatory and repeatable)
 [1] - xs:string* - zero or more strings (i.e. optional and repeatable)
 [1] - element( email )+ - one or more <email> elements
 [1] - element( email )? - zero or one <email> elements
 [1] - xs:item()* - zero or more items of any type
]
The following data types are not allowed as sequence types
[[1] - xs:anyType (un-validated element node)
 [1] - xs:untyped (un-validated attribute node content)
 [1] - xs:anySimpleType (lists and unions only)
[[2] - includes xs:IDREFS, xs:NMTOKENS and xs:ENTITIES
 [2] - includes user-defined list and union types
]]
3.0.3 Constructing result trees
[> 3.0.4][> 4.][< 3.0.2][^][^^][^^^]
Building a result predictably
[[1] - created as an abstract tree of nodes
[[2] - the result node tree is constructed using nodes from the operation and source trees, and nodes synthesized by operation tree expressions
 [2] - result is described according to the same data model for XML markup as is used for input
 [2] - the processing of a template builds a portion of the result as sub-tree of nodes reflecting the output information
 [2] - the interpretation of a result template is reliable and reproducible
[[3] - the processor acts on instructions the same way every time
 [3] - some aspects (e.g. order of attribute) is implementation-dependent
]][1] - one-pass construction of the result tree
[[2] - no "going back and changing" anything in the result tree
 [2] - created in a single pass in result parse-order
][1] - serialization instantiates markup syntax
[[2] - the emission of the result node tree (if so desired)
 [2] - in XML markup according to the standard
[[3] - the transform writer does not control which markup constructs are used for representing XML information
 [3] - the processor can make arbitrary decisions as long as the end result is well formed
][2] - using alternative markup or syntax conventions if made available by the processor (e.g.: interpretation of a colloquial vocabulary into a binary format)
]]
3.0.4 XPath data model
[> 4.][< 3.0.3][^][^^][^^^]
The XPath productions covered in this chapter are:
[[1] - [(: :)]
[[2] - commenting XPath expressions
][1] - [if ( ) then else ]
[[2] - XPath choice statement
][1] - [for ... return ... ]
[[2] - XPath tuple statement
][1] - [empty-sequence()]
[[2] - the empty sequence sequence type
][1] - [/ ]
[[2] - location path address steps
][1] - [$ ]
[[2] - variable references
][1] - [( )]
[[2] - parenthesized expressions
]]
The XSLT instructions covered in this chapter are:
[[1] - [<xsl:strip-space>]
[[2] - indicate those source tree nodes in which white-space-only text nodes are not to be preserved.
][1] - [<xsl:preserve-space>]
[[2] - indicate those source tree nodes in which white-space-only text nodes are to be preserved
]]
The XPath functions covered in this chapter are:
[[1] - [last]()
[[2] - the number of nodes in the context/current node list
][1] - [position]()
[[2] - the ordinal number of the current node in the context/current node list
][1] - [. ]
[[2] - context item
]]

*** This is a free preview excerpt of a commercial publication. ***

This is an accessible version of Crane's commercial training material. The content has been specifically designed to assist screen reader software in viewing the entire textual content. Figures are replaced with text narratives.

Navigation hints are in square brackets:
[Tx.x] and [Fx.x] are textual representations of the applicability icons;
[digit] indicates list depth for nested lists;
[link [URL]] indicates the URL of a hyperlink if different than link;
[EXAMPLE] indicates an example listing of code;
[FIGURE] indicates the presence of a figure replaced by its description;
[>] jumps forward;
[<] jumps backward;
[^] jumps to start of the section;
[^^] jumps to the start of the chapter;
[^^^] jumps to the table of contents.
Suggestions for improvement are welcome: [info@CraneSoftwrights.com]
Book sales: [http://www.CraneSoftwrights.com/links/trn-acc.htm]
Information: [http://www.CraneSoftwrights.com/links/info-acc.htm]
This content is protected by copyright and, as there are no means to protect this accessible version from plagiarism, please do not make any commercial edition available to others.

+//ISBN 978-1-894049::CSL::Courses::PTUX//DOCUMENT Practical Transformation Using XSLT and XPath 2011-02-11 21:00UTC//EN
Practical Transformation Using XSLT and XPath
Fourteenth Edition - 2011-02-11
ISBN 978-1-894049-24-5
Copyright © Crane Softwrights Ltd.