An unprefixed name: a string in the value space of the schema type xs:NCName. An xs:NCName representing a namespace prefix, which must be in scope for the element on which it appears. Except where the set of allowed values of an attribute is specified using the italicized name string or char , leading and trailing whitespace in the attribute value is ignored.
In the case of an attribute value template , this applies to the effective value obtained when the attribute value template is expanded. XPath comments delimited by Unless the element is required to be empty, the model element contains a comment specifying the allowed content.
The allowed content is specified in a similar way to an element type declaration in XML; sequence constructor means that any mixture of text nodes, literal result elements , extension instructions , and XSLT elements from the instruction category is allowed; other-declarations means that any mixture of XSLT elements from the declaration category is allowed, together with user-defined data elements.
The element is prefaced by comments indicating if it belongs to the instruction category or declaration category or both. The category of an element only affects whether it is allowed in the content of elements that allow a sequence constructor or other-declarations.
This example illustrates the notation used to describe XSLT elements. This example defines a non-existent element xsl:example-element. The element is classified as an instruction. It takes the following attributes:. A mandatory select attribute, whose value is an XPath expression. An optional debug attribute, whose value must be yes , true , or 1 to indicate true , or no , false , or 0 to indicate false.
The content of an xsl:example-element instruction is defined to be a sequence of zero or more xsl:variable and xsl:param elements, followed by an xsl:sequence element. The rules in the element syntax summary both for the element structure and for its attributes apply to the stylesheet content after preprocessing as described in 3.
Attributes are validated as follows. These rules apply to the value of the attribute after removing leading and trailing whitespace. If the processor is able to detect the error statically for example, when any XPath expressions within the curly brackets can be evaluated statically , then the processor may optionally signal this as a static error.
Special rules apply if the construct appears in part of the stylesheet that is processed with forwards compatible behavior : see 3. The use of this term implies that stylesheet authors should not use the construct, and that the construct may be removed in a later version of this specification. The syntax summaries described in this section are normative. XSLT defines a set of standard functions which are additional to those defined in [Functions and Operators 3.
A list of these functions appears in G. The signatures of these functions are described using the same notation as used in [Functions and Operators 3. The names of many of these functions are in the standard function namespace.
This document does not specify any application programming interfaces or other interfaces for initiating a transformation. This section, however, describes the information that is supplied when a transformation is initiated. Except where otherwise indicated, the information is required.
The execution of a stylesheet necessarily involves two activities: static analysis and dynamic evaluation. Static analysis consists of those tasks that can be performed by inspection of the stylesheet alone, including the binding of static variables , the evaluation of [xsl:]use-when expressions see 3.
Dynamic evaluation consists of tasks which in general cannot be carried out until a source document is available. Dynamic evaluation is further divided into two activities: priming the stylesheet, and invoking a selected component.
Priming the stylesheet provides the dynamic context for evaluation, and supplies all the information needed to establish the values of global variables. Invoking a component such as a template or function causes evaluation of that template or function to produce a result, which is an arbitrary XDM value. The raw result of the invocation is the immediate result of evaluating the sequence constructor contained in the target template or function, modified by applying the function conversion rules to convert the immediate result to the type declared in the as attribute of the xsl:template or xsl:function declaration, if present.
This raw result may optionally be post-processed to construct a result tree, to serialize the result, or both, as described in 2. Implementations may allow static analysis and dynamic evaluation to be initiated independently, so that the cost of static analysis can be amortized over multiple transformations using the same stylesheet.
Implementations may also allow priming of a stylesheet and invocation of components to be initiated independently, in which case a single act of priming the stylesheet may be followed by a series of independent component invocations.
Although this specification does not require such a separation, this section distinguishes information that is needed before static analysis can proceed, information that is needed to prime the stylesheet, and information that is needed when invoking components.
The language is designed to allow the static analysis of each package to be performed independently of other packages, with only basic knowledge of the properties of components made available by used packages. Beyond this, the specification leaves it to implementations to decide how to organize this process.
When packages are not used explicitly, the entire stylesheet is treated as a single package. The following information is needed prior to static analysis of a package :. The location of the package manifest , or in the absence of a package manifest, the stylesheet module that is to act as the principal stylesheet module of the package.
The complete package is assembled by recursively expanding the xsl:import and xsl:include declarations in the principal stylesheet module, as described in 3. Information about the packages referenced from this package using xsl:use-package declarations.
The information needed will include the names and signatures of public components exported by the referenced package. A set possibly empty of values for static parameters see 9. These values are available for use within static expressions notably in [xsl:]use-when expressions and shadow attributes as well as non-static expressions in the stylesheet. Conceptually, the output of the static analysis of a package is an object which might be referred to without constraining the implementation as a compiled package.
Prior to dynamic evaluation, all the compiled packages needed for execution must be checked for consistency, and component references must be resolved. This process may be referred to, again without constraining the implementation, as linking. A set possibly empty of values for non-static stylesheet parameters see 9. These values are available for use within expressions in the stylesheet. A supplied value is converted if necessary to the declared type of the stylesheet parameter using the function conversion rules.
Non-static stylesheet parameters are implicitly public , which ensures that all the parameters in the stylesheet for which values can be supplied externally have distinct names. Static parameters, by contrast, are local to a package. This item acts as the context item when evaluating the select expression or sequence constructor of a global variable declaration within the top-level package , as described in 5.
The global context item may also be available in a named template when the stylesheet is invoked as described in 2. In previous releases of this specification, a single node was typically supplied to represent the source document for the transformation.
This node was used as the target node for the implicit call on xsl:apply-templates used to start the transformation process now called the initial match selection , and the root node of the containing tree was used as the context item for evaluation of global variables now called the global context item.
This relationship between the initial match selection and the global context item is likely to be found for compatibility reasons in a transformation API designed to work with earlier versions of this specification, but it is no longer a necessary relationship; the two values can in principle be completely independent of each other.
Stylesheet authors wanting to write code that can be invoked using legacy APIs should not rely on the caller being able to supply different values for the initial match selection and the global context item. The value given to the global context item and the values given to stylesheet parameters cannot be nodes in a streamed document. This rule ensures that all global variables can freely navigate within the relevant tree, with no constraints imposed by the streamability rules. The global context item is potentially used when initializing global variables and parameters.
If the initialization of any global variables or parameter depends on the context item, a dynamic error can occur if the context item is absent. It is implementation-defined whether this error occurs during priming of the stylesheet or subsequently when the variable is referenced; and it is implementation-defined whether the error occurs at all if the variable or parameter is never referenced.
The error can be suppressed by use of xsl:try and xsl:catch within the sequence constructor used to initialize the variable or parameter. It cannot be suppressed by use of xsl:try around a reference to the global variable. In a library package , the context item , context position , and context size used for evaluation of global variables will be absent , and the evaluation of any expression that references these values will result in a dynamic error.
This will also be the case in the top-level package if no global context item is supplied. If a context item is available within a global variable declaration, then the context position and context size will always be 1 one. For maximum reusability of code, it is best to avoid use of the context item when initializing global variables and parameters. Instead, all external information should be supplied using named stylesheet parameters. Especially when these use namespaces to avoid conflicts, there is then no risk of confusion between the information supplied externally to different packages.
When a stylesheet parameter is defined in a library package, it is possible for a using package to supply a value for the parameter by overriding the parameter declaration within an xsl:override element. If the using package is the top-level package then the overriding declaration can refer to the global context item. A mechanism for obtaining a document node and a media type, given an absolute URI. The total set of available documents modeled as a mapping from URIs to document nodes forms part of the context for evaluating XPath expressions, specifically the doc FO30 function.
The XSLT document function additionally requires the media type of the resource representation, for use in interpreting any fragment identifier present within a URI Reference. The set of documents that are available to the stylesheet is implementation-dependent , as is the processing that is carried out to construct a tree representing the resource retrieved using a given URI.
Once a stylesheet is primed, the values of global variables remain stable through all component invocations. In addition, priming a stylesheet creates an execution scope FO30 during which the dynamic context and all calls on deterministic FO30 functions remain stable; for example two calls on the current-dateTime FO30 function within an execution scope are defined to return the same result.
Parameters passed to the transformation by the client application when a stylesheet is primed are matched against stylesheet parameters see 9. A stylesheet parameter is visible if it is not masked by another global variable or parameter with the same name and higher import precedence.
If the parameter is a static parameter then the value must be supplied prior to the static analysis phase. The value which can be any sequence of items is referred to as the initial match selection. The processing then corresponds to the effect of the xsl:apply-templates instruction.
The initial match selection will often be a single document node, traditionally called the source document of the transformation; but in general, it can be any sequence.
If the initial match selection is an empty sequence, the result of the transformation will be empty, since no template rules are evaluated. Processing proceeds by finding the template rules that match the items in the initial match selection , and evaluating these template rules with a focus based on the initial match selection. The template rules are evaluated in final output state. The following information is needed when dynamic evaluation is to start with a template rule :.
The initial match selection. An API that chooses to maintain compatibility with previous versions of this specification should allow a method of invocation in which a singleton node is provided, which is then used in two ways: the node itself acts as the initial match selection , and the root node of the containing tree acts as the global context item. In searching for the template rule that best matches the items in the initial match selection , the processor considers only those rules that apply to the initial mode.
If no initial mode is supplied explicitly, then the initial mode is that named in the default-mode attribute of the explicit or implicit xsl:package element of the top-level package or in the absence of such an attribute, the unnamed mode. A named or unnamed mode M is eligible as an initial mode if one of the following conditions applies, where P is the top-level package of the stylesheet:.
M is explicitly declared in an xsl:mode declaration within P , and has public or final visibility either by virtue of its visibility attribute, or by virtue of an xsl:expose declaration. M is named in the default-mode attribute of the explicit or implicit xsl:package element of P. M is declared in a package used by P , and is given public or final visibility in P by means of an xsl:accept declaration.
The effective value of the declared-modes attribute of the explicit or implicit xsl:package element of P is no , and M appears as a mode-name in the mode attribute of a template rule declared within P. Parameters, which will be passed to the template rules used to process items in the input sequence. The parameters consist of two sets of QName, value pairs, one set for tunnel parameters and one for non-tunnel parameters, in which the QName identifies the name of a parameter and the value provides the value of the parameter.
Either or both sets of parameters may be empty. If a parameter is supplied that is not declared or used, the value is simply ignored. These parameters are not used to set stylesheet parameters. A supplied value is converted if necessary to the declared type of the template parameter using the function conversion rules. Details of how the result of the initial template is to be returned. For details, see 2. The raw result of the invocation is the result of processing the supplied input sequence as if by a call on xsl:apply-templates in the specified mode: specifically, each item in the input sequence is processed by selecting and evaluating the best matching template rule, and converting the result if necessary to the type declared in the as attribute of that template using the function conversion rules ; and the results of processing each item are then concatenated into a single sequence, respecting the order of items in the input sequence.
If the initial mode is declared-streamable , then a streaming processor should allow some or all of the items in the initial match selection to be nodes supplied in streamable form, and any nodes that are supplied in this form must then be processed using streaming.
Since the global context item cannot be a streamed node, in cases where the transformation is to proceed by applying streamable templates to a streamed input document, the global context item must either be absent, or must be something that differs from the initial match selection.
The design of the API for invoking a transformation should provide some means for users to designate the unnamed mode as the initial mode in cases where it is not the default mode.
A stylesheet can process further source documents in addition to those supplied when the transformation is invoked. These additional documents can be loaded using the functions document see The following information is needed in this case:.
Optionally, the name of the initial named template which is to be executed as the entry point to the transformation. If no template name is supplied, the default template name is xsl:initial-template.
The selected template must exist within the stylesheet. Optionally, a context item for evaluation of this named template, defaulting to the global context item if it exists.
This is constrained by any xsl:context-item element appearing within the selected xsl:template element. The initial named template is evaluated with a singleton focus based on this context item if it exists, or with an absent focus otherwise. Parameters, which will be passed to the selected template rule. Details of how the result of the initial named template is to be returned.
The raw result of the invocation is the result of evaluating the initial named template , after conversion of the result to the type declared in the as attribute of that template using the function conversion rules , if such conversion is necessary.
The initial named template is evaluated in final output state. The name and arity of a stylesheet function which is to be executed as the entry point to the transformation. In the design of a concrete API, the arity may be inferred from the length of the parameter list. A list of values to act as parameters to the initial function. The number of values in the list must be the same as the arity of the function.
A supplied value is converted if necessary to the declared type of the function parameter using the function conversion rules. Details of how the result of the initial function is to be returned. The raw result of the invocation is the result of evaluating the initial function , after conversion of the result to the type declared in the as attribute of that function using the function conversion rules , if such conversion is necessary. The initial function like all stylesheet functions is evaluated with an absent focus.
If the initial function is declared-streamable , a streaming processor should allow the value of the first argument to be supplied in streamable form, and if it is supplied in this form, then it must be processed using streaming.
When a transformation is invoked by calling an initial function , the entire transformation executes in temporary output state , which means that calls on xsl:result-document are not permitted.
There are three ways the result of a transformation may be delivered. This applies both to the principal result, described here, and also to secondary results, generated using xsl:result-document.
The raw result a sequence of values may be returned directly to the calling application. A result tree may be constructed from the raw result. By default, a result tree is constructed if the build-tree attribute of the unnamed output definition has the effective value yes.
An API for invoking transformations may allow this setting to be overridden by the calling application. If result tree construction is requested, it is performed as described in 2. Alternatively, the raw result may be serialized as described in 2. The decision whether or not to serialize the result is determined by the rules of transformation API provided by the processor , and is not influenced by anything in the stylesheet. This specification does not constrain the design of application programming interfaces or the choice of defaults.
In previous versions of this specification, result tree construction was a mandatory process, while serialization was optional. When invoking stylesheet functions directly, however, result tree construction and serialization may be inappropriate as defaults. These considerations may affect the design of APIs. In previous versions of XSLT, results were delivered either in serialized form as a character or byte stream , or as a tree. In the latter case processors typically would use either their own tree representation, or a standardized tree representation such as the W3C Document Object Model DOM see [DOM Level 2] , adapted to the data structures offered by the programming language in which the API is defined.
To deliver a raw result, processors need to define a representation not only of XDM nodes but also of sequences, atomic values, maps and even functions. As with the return of a simple tree, this may involve a trade-off between strict fidelity to the XDM data model and usability in the particular programming language environment.
It is not a requirement that an API should return results in a way that exposes every property of the XDM data model; for example there may be APIs that do not expose the precise type annotation of a returned node or atomic value, or that fail to expose the base URI or document URI of a node, or that provide no way of determining whether two nodes in the result sequence are the same node in the sense of the XPath is operator. The way in which maps and functions and where XPath 3.
It is recommended that an API should be capable of returning any XDM value without error, and that there should be minimal loss of information if the raw results output by one transformation are subsequently used as input to another transformation. If a result tree is to be constructed from the raw result , then this is done by applying the rules for the process of sequence normalization SER30 as defined in [XSLT and XQuery Serialization].
This process takes as input the serialization parameters defined in the unnamed output definition of the top-level package ; though the only parameter that is actually used by this process is item-separator. In particular, sequence normalization is carried out regardless of any method attribute in the unnamed output definition.
The sequence normalization process either returns a document node, or raises a serialization error. The content of the document node is not necessarily well-formed the document node may have any number of element or text nodes among its children.
More specifically, the process raises a serialization error if any item in the raw result is an attribute node, a namespace node, or a function including a map, but not an array: arrays are flattened. The tree that is constructed is referred to as a final result tree. If the raw result is an empty sequence, the final result tree will consist of a document node with no children. The item-separator property has no effect if the raw result of the transformation is a sequence of length zero or one, which in practice will often be the case, especially in a traditional scenario such as transformation of an XML document to HTML.
If there is no item-separator , then a single space is inserted between adjacent atomic values; for example if the raw result is the sequence 1 to 5 , then sequence normalization produces a tree comprising a document node with a single child, the child being a text node with the string value 1 2 3 4 5.
If there is an item-separator , then it is used not only between adjacent atomic values, but between any pair of items in the raw result. For example if the raw result is a sequence of two element nodes A and B , and the item-separator is a comma, then the result of sequence normalization will be a document node with three children: a copy of A , a text node whose string value is a single comma, and a copy of B.
The raw result may optionally be serialized as described in 26 Serialization. The serialization is controlled by the serialization parameters defined in the unnamed output definition of the top-level package. The first phase of serialization, called sequence normalization SER30 , takes place for some output methods but not others. The effect of serialization is to generate a sequence of octets, representing the serialized result in some character encoding.
The default location is the location identified by the base output URI. In previous versions of this specification it was stated that when the raw result of the initial template or function is an empty sequence, a result tree should be produced if and only if the transformation generates no secondary results that is, if it does not invoke xsl:result-document. This provision is most likely to have a noticeable effect if the transformation produces serialized results, and these results are written to persistent storage: the effect is then that a transformation producing an empty principal result will overwrite any existing content at the base output URI location if and only if the transformation produces no other output.
If the transformation generates more than one final result tree, then typically each one will be allocated a URI relative to this base URI. In practice, therefore, users wanting to control transformation in the browser using this processing instruction are obliged to use this unregistered media type.
So, for example, if the stylesheet in Example 2 above were available as "example2. Chat WhatsApp. For more details on this topic, see XPath. Retrieved November 7, Proceedings of Extreme Markup Languages. Retrieved 28 October Retrieved August 8, Retrieved 21 January Retrieved 23 October Retrieved 23 November Retrieved Retrieved 22 October Retrieved 14 August Balisage: The Markup Conference Proceedings. Retrieved 15 February Retrieved 19 October Collectives on Stack Overflow. Learn more.
Asked 9 years, 2 months ago. Active 9 years, 2 months ago. Viewed 4k times. Is it as easy as putting the templates one below another in a single combined XSLT? Improve this question. Please, edit the question and provide the source XML document. The first transformation can be improved. Also it seems possible to even eleiminate the need for the second transformation.
Add a comment. Active Oldest Votes. The answer is: It depends If you have multiple XSL Templates then it is possible that it was intended for them to be applied sequentially to the XML - so, for example, if you have 3 XSLT's, it could be that the first is applied to the original document, the second to the result of the first transformation, and the third to the result of the second transformation.
Improve this answer. Perfect thank you is was this bit i was looking for If you have multiple XSL Templates then it is possible that it was intended for them to be applied sequentially to the XML - so, for example, if you have 3 XSLT's, it could be that the first is applied to the original document, the second to the result of the first transformation, and the third to the result of the second transformation. Yes that's it! XSLT variables seem like a good idea, but they do not work here.
The reason is that when you assign a value to a variable in a template, the value is known only within that template statically, at compile time. Even if the variable is defined globally, the assigned value is not stored in a way that lets it be dynamically known by other templates at runtime. Using a parameterized template is another way to modify a template's behavior. But determining the amount of indentation space to pass as the parameter remains the crux of the problem.
At the moment, then, there does not appear to be any good way to control the indentation of HTML formatted output. That would be inconvenient if you needed to display or edit the HTML as plain text. When you view stylizer1c. Note - The sample document described in this section is article2. The result is stylizer2. Note - Although the list and note in the XML file are contained in their respective paragraphs, it really makes no difference whether they are contained or not; the generated HTML will be the same either way.
But having them contained will make them easier to deal with in an outline-oriented editor. Next, modify the PARA template to account for the fact that we are now allowing some of the structure elements to be embedded with a paragraph:.
This modification uses the same technique you used for section headings. The only difference is that SECT elements are not expected within a paragraph. However, a paragraph could easily exist inside another paragraph-for example, as quoted material. In this case, the value of the type attribute is tested, and the list that is generated changes depending on whether the value is ordered or unordered. Single quotes are required around the attribute values.
By now, you should have the idea that templates are independent of one another, so it does not generally matter where they occur in a file. So from this point on, we will show only the template you need to add. For the sake of comparison, they're always added at the end of the example stylesheet.
Order does make a difference when two templates can apply to the same node. In that case, the one that is defined last is the one that is found and processed. In that template, you would use the HTML option to generate an alphabetic enumeration, instead of a numeric one.
The last remaining structure element is the NOTE element. Add the following template to handle that. That brings us to the major reason for that special output tag we added early in the stylesheet:.
That conversion is important, because most browsers do not recognize the empty tags. Here is a list of the affected tags:. The only remaining tags in the ARTICLE type are the inline tags-the ones that do not create a line break in the output, but instead are integrated into the stream of text they are part of.
Inline elements are different from structure elements in that inline elements are part of the content of a tag. If you think of an element as a node in a document tree, then each node has both content and structure. The content is composed of the text and inline tags it contains. The structure consists of the other elements structure elements under the tag. Note - The sample document described in this section is article3. The result is stylizer3. Next, comment out the text-node normalization.
It has served its purpose, and now you are to the point that you need to preserve important spaces:. Try the program without this modification to see the result. Here, you generate the appropriate inline tag using the name of the current element. Those curly braces cause the text inside the quotes to be processed as an XPath expression instead of being interpreted as a literal string.
Here, they cause the XPath name function to return the name of the current node. Curly braces are recognized anywhere that an attribute value template can occur.
Attribute value templates are defined in section 7. For more information, see section 7.
0コメント