Relationship between xpath and xslt

CITX - XPath and XSLT

relationship between xpath and xslt

Each association> produces a element with the association name. Each 2 XSL/Transform" 3. XSLT and XPointer specify how the context is determined for XPath . an axis, which specifies the tree relationship between the nodes selected by the location . lxml supports XPath , XSLT and the EXSLT extensions through libxml2 and .. The other major difference regards the capabilities of both path languages.

Indeed, the document element is a literal result element as it, too, is not an instruction. The default namespace cannot be used for this purpose. The namespace URI associated with the prefix must be the value http: It is a common practice to use the prefix xsl to identify the XSLT vocabulary, though this is only convention and any valid prefix can be used. The stylesheet must also declare the version of XSLT required by the instructions used therein.

In an implicit stylesheet where the XSLT namespace is declared in an element that is not an XSLT instruction, the namespace-qualified attribute declaration must be used as prefix: The version number is a numeric floating-point value representing the latest version of XSLT defining the instructions used in the stylesheet. It need not declare the most capable version supported by the XSLT processor.

relationship between xpath and xslt

For better performance reasons, a processor may choose to not consider a top-level instruction until there is need within the stylesheet to use it. All other instructions are found somewhere in a result tree template and are not executed until that point at which the processor is asked to add the instruction to the result tree.

Instructions themselves are never added to the result tree.

Some XSLT instructions are control constructs used by the processor to manage our stylesheets. The wrapper and top-level elements declare our globally scoped constructs.

  • Your Answer
  • What is XSLT?
  • Site Navigation

Procedural and process-control constructs give us the ability to selectively add only portions of templates to the result, rather than always adding an entire template. Logically-oriented constructs give us facilities to share the use of values and declarations within our own stylesheet files. Physically-oriented constructs give us the power to share entire stylesheet fragments. Other XSLT instructions are result tree value placeholders. We declare how a value is calculated by the processor, or obtained from a source tree, or both calculated by the processor from a value from a source tree.

The value calculation is triggered when the XSLT processor is about to add the instruction to the result tree.

The outcome of the calculation which may be nothing is added to the result tree. All other instructions engage customized non-standard behaviors and are specified using extension elements in a standardized fashion. These elements use namespace prefixes declared by our stylesheets to be instruction prefixes. Extension instructions may be either control constructs or result tree value placeholders. Consider the simple example in our stylesheets used earlier in this chapter where the following instruction is used: When the expression is a location in the source tree, as is this example, the value returned is the value of the first location identified using the criteria.

When that location is an element, the value returned is the concatenation of all of the PCDATA text contained therein.

This example instruction is executed in the context of the root of the source document being the focus. The child of the root of the document is the document element. The expression requests the value of the child named "greeting " of the root of the document, hence, the value of the document element named "greeting ".

For any source document where "greeting " is not the document element, the value returned is the empty string. For any source document where it is the document element, as is our example, the value returned is the concatenation of all PCDATA text in the entire instance.

A literal result element is any element in a stylesheet that is not a top-level element and is not either an XSLT instruction or an extension instruction. A literal result element can use the default namespace or any namespace not declared in the stylesheet to be an instruction namespace.

When the XSLT processor reads the stylesheet and creates the abstract nodes in the stylesheet tree, those nodes that are literal result elements represent the nodes that are added to the result tree.

Though the definition of those nodes is dictated by the XML syntax in the stylesheet entity, the syntax used does not necessarily represent the syntax that is serialized from the result tree nodes created from the stylesheet nodes.

Literal result elements marked up in the stylesheet entity may have attributes that are targeted for the XML processor used by the XSLT processor, targeted for the XSLT processor, or targeted for use in the result tree. Some attributes are consumed and acted upon as the stylesheet file is processed to build the stylesheet tree, while the others remain in the stylesheet tree for later use.

Those literal result attributes remaining in the stylesheet tree that are qualified with an instruction namespace are acted on when they are asked to be added to the result tree. The collection of literal result elements and other instructions being contained therein comprises the XSLT template for that instruction.

A template can contain only literal result elements, only instruction elements, or a mixture of both. The behavior of the stylesheet can ask that a template be added to the result tree, at which point the nodes for literal result elements are added and the nodes for instructions are executed. Consider again the simple example in our stylesheets used earlier in this chapter where the following template is used: A template rule is a declaration to the XSLT processor of a template to be added to the result tree when certain conditions are met by source locations visited by the processor.

Template rules are either top-level elements explicitly written in the stylesheet or built-in templates assumed by the processor and implicitly available in all stylesheets.

This attribute is an XPath pattern expression, which is a subset of XPath expressions in general. The pattern expression describes preconditions of source tree nodes. The stylesheet writer is responsible for writing the preconditions and other attribute values in such a way as to unambiguously provide a single written or built-in template for each of the anticipated source tree conditions.

In an implicitly declared stylesheet, the entire file is considered the template for the template rule for the root of the document. This template rule overrides the built-in rule implicitly available in the XSLT processor. Back to the simple example in our explicitly declared stylesheet used earlier in this chapter, the following template rule is declared: This written rule overrides the built-in rule implicitly available in the XSLT processor.

The template is the same template we were discussing earlier: The XSLT processor begins processing by visiting the root of the document. This gives control to the stylesheet writer. Either the supplied template rule or built-in template rule for the root of the document is processed, based on what the writer has declared in the stylesheet. The writer is in complete control at this early stage and all XSLT processor behavior is dictated what the writer asks to be calculated and where the writer asks the XSLT processor to visit.

Two distinct approaches can be characterized.

What's the difference between XSLT and xPath - avb4you.info Q&A

Choosing which approach to use when depends on your own preferences, the nature of the source information, and the nature of the desired result. I refer to these two approaches as either stylesheet-driven or data-driven, though the former might be misconstrued.

Of course all results are stylesheet-driven because the stylesheet dictates what to do, so the use of the term involves some nuance. By stylesheet-driven I mean that the order of the result is a result of the stylesheet tree having explicitly instructed the adding of information to the result tree.

relationship between xpath and xslt

By data-driven I mean that the order of the result is a result of the source tree ordering having dictated the adding of information to the result tree.

Two instructions are provided for this purpose: The instruction is always empty and therefore does not contain a template. This value calculated can be the result of function execution, the value of a variable, or the value of a node selected from the source tree.

When used in the template of various XSLT instructions the outcome becomes part of the value of a result element, attribute, comment, or processing instruction. This template can contain literal result elements or any instruction to be executed. When processing the given template, the focus of the processor's view of the source tree shifts to the location being visited, thus providing for relative addressing while moving through the information.

These instructions give the writer control over the order of information in the result. The data is being pulled from the source on demand and added to the result tree in the stylesheet-determined order. When collections of nodes are iterated, the nodes are visited in document order. This implements a stylesheet-driven approach to creating the result. An implicitly-declared stylesheet is obliged to use only these "pull" instructions and must dictate the order of the result with the above instructions in the lone template.

relationship between xpath and xslt

In these situations, the writer instructs the XSLT processor to visit source tree nodes and to apply to the result the templates associated with the nodes that are visited. The writer can choose any relative, absolute, or arbitrary location or locations to be visited. Each node visited is pushed through the stylesheet to be caught by template rules. Template rules specify the template to be processed and added to the result tree.

The template added is dictated by the template rule matched for the node being pushed, not by a template supplied by the instruction when a node is being pulled. This distinguishes the behavior as being a data-driven approach to creating the result, in that the source determines the ultimate order of the result.

An implicitly-declared stylesheet can only push information through built-in template rules, which is of limited value. As well, the built-in rules can be mimicked entirely by using pull constructs, thus they need never be used. There is no room in the stylesheet to declare template rules in an implicitly-declared stylesheet since there is no wrapper stylesheet instruction. This document defines a core function library that all XPath implementations must support see [4 Core Function Library].

For a function in the core function library, arguments and result are of the four basic types. The namespace declarations consist of a mapping from prefixes to namespace URIs. The variable bindings, function library and namespace declarations used to evaluate a subexpression are always the same as those used to evaluate the containing expression. The context node, context position, and context size used to evaluate a subexpression are sometimes different from those used to evaluate the containing expression.

Several kinds of expressions change the context node; only predicates change the context position and context size see [2. When the evaluation of a kind of expression is described, it will always be explicitly stated if the context node, context position, and context size change for the evaluation of subexpressions; if nothing is said about the context node, context position, and context size, they remain unchanged for the evaluation of subexpressions of that kind of expression.

XPath expressions often occur in XML attributes. The grammar specified in this section applies to the attribute value after XML 1. Within expressions, literal strings are delimited by single or double quotation marks, which are also used to delimit XML attributes.

Alternatively, the expression can use single quotation marks if the XML attribute is delimited with double quotation marks or vice-versa. One important kind of expression is a location path. A location path selects a set of nodes relative to the context node. The result of evaluating an expression that is a location path is the node-set containing the nodes selected by the location path. Location paths can recursively contain expressions that are used to filter sets of nodes.

A location path matches the production LocationPath. Expressions are parsed by first dividing the character string to be parsed into tokens and then parsing the resulting sequence of tokens. Whitespace can be freely used between tokens.

relationship between xpath and xslt

The tokenization process is described in [3. Every location path can be expressed using a straightforward but rather verbose syntax. There are also a number of syntactic abbreviations that allow common cases to be expressed concisely. This section will explain the semantics of location paths using the unabbreviated syntax. The abbreviated syntax will then be explained by showing how it expands into the unabbreviated syntax see [2.

relationship between xpath and xslt

Here are some examples of location paths using the unabbreviated syntax: