|
|
Home | Loader API | Interfaces | File List | Index | |
P6R's XSLT 2.0 implementation uses the following P6R's components: XPath 2.0 (P6R::p6IXpathExpression), DOMXML (P6R::p6DOMXML), SAX2 (P6R::p6ISAX2XMLReader), and JSON (P6R::p6IJSONReader). Thus this XSLT processor can also use XML or JSON as its source document (the XSLT templates are still in XML).
P6R's XPath 2.0 implementation also allows an application to extend the XSLT Processor's behavior via the XPath interface P6R::p6IXpathVariables (which allows an application to define their own functions and variables that are recognized in an XPath expression). The calling application creates its own implementation of the P6IXPathVariables interface and then calls the P6R::p6IXSLT::setExternalFunctions() method. This is significant that now an application can define its own global variables which can change each time they are referenced. These external variables can be used for many purposes including with Compiled templates (see below).
Please note that this documentation does not provide details on the XSLT, XPath, XML, or JSON languages (references are included for that). This documentation describes how to use the P6R components that implement the standards as well as to point out unique features of our products.
1) M.Kay, "XSLT 2.0 Programmer's Reference", 3rd Edition, 2004, Wiley Publishing Inc., ISBN: 0-7645-6909-0.
2) M.Kay, XPath 2.0, Programmer's Reference, Wiley Publishing Inc, 2004, ISBN 0-7645-6910-4.
3) N.Bradley, "The XSL Companion", 2000, Addison-Wesley, ISBN: 0-201-67487-4.
4) http://www.w3.org/TR/xslt20/, the XSLT W3C specification
XSLT and XPath for JSON - https://www.p6r.com/articles/2008/05/06/xslt-and-xpath-for-json/
<xsl:output method=’json’/> - https://www.p6r.com/articles/2008/11/02/xsloutput-methodjson/
The implementation of <xsl:strip-space> and <xsl:preserve-space> is done while the DOM tree is being built from streaming XML input. Thus these functions do not incur any significant performance penality. The white space stripping is done by calling the methods P6R::p6IDOMXML::stripSpace() and P6R::p6IDOMXML::preserveSpace() from our XML DOM parser.
Our XSLT processor allows the caller to compile a template once and use it over and over again to generate pages. See Section "Compiled Templates and Multiple Threads" below.
A detailed document on this topic has been published at the following URL: https://www.p6r.com/articles/2008/09/03/compiled-tempates-for-xslt-20/
The following XSLT functions have not yet been implemented: format-number() (try using the P6R:format-number() XPath extension function which is specified in the XPath documentation), unparsed-entity-public-id(), and unparsed-entity-uri(). The function "unparsed-text()" is implemented but it only supports "UTF-8" and "iso-8859-1" encodings.
The following elements have not yet been implemented in P6R's XSLT 2.0 implementation: 'decimal-format', 'document', 'import-schema', 'namespace-alias', and 'number' (see our XSLT extensions for an alternative to xsl:number). These elements are simply ignored if encountered by the P6R XSLT 2.0 processor.
In addition, the sequence constructor part of a 'perform-sort' element has not yet been implemented. So the "select=" attribute must be defined for the 'perform-sort' element to work properly. Also, "Built-in Template Rules" are not yet implemented (M.Kay, p.70).
In addition, the current implementation does not yet have a full URI resolver so only relative URIs to files on disk is supported. A full URI resolver will be included in the near future.
In the xsl:output element the following methods are supported: { xml, html, xhtml, text, json }. Only the following attributes are supported for the xsl:output element: { name, method, omit-xml-declaration, standalone, use-character-maps }. The 'encoding' attribute is currently set to UTF-8.
These added elements require the use of the P6R namespace: http://www.p6r.com/XSLT/extensions
1) <p6r:number value="" format="" lang="" /> This element is similar to the <xsl:number> element. This element is always empty. It should only appear in a sequence constructor.
NAME VALUE Meaning value Expression An XPath expression that evaluates to a sequence of zero or more integers. (required) This is the number(s) to be formatted. lang Expression Indicates the language to use when formatting the number string. (optional) format xs:string A standard format string as used in P6R::p6i18n::formatString() function (e.g., %1$,%2$, ). (optional)
As a simple example:
<p6r:number value='(1,44,33)' format='Hi there-%1$-what is %2$ new?,%3$' /> <p6r:number value='(1,44,33)' format='Hi there-%3$-what is %2$ new?,%1$' /> The first number element produces: 'Hi there-1-what is 44 new?,33' The second number element produces: 'Hi there-33-what is 44 new?,1', allowing control over position.
P6R has restricted support for Attribute Value Templates [1, p.116] because of our compiled templates feature. Many XSLT elements allow some of there attributes to be passed in as part of the "enviroment" BEFORE template compilation. This way an XSLT element can be parameterized. For example, the sort element allows many of its attributes (e.g., order = { ascending | descending }, and collation = { uri }) to be determined at compile time via parameters to the compile/transform call.
The problem with this type of value expansion is that it can only happen once with compiled templates. Using the XSLT sort element as an example, the same template would have to be compiled with both values for the "order" attribute just in case that attribute could be set by a user at a Web UI. Instead of using these "hard coded" values we allow the calling application to use the XSLT processor's ability to define external, global variables. These application controlled variables can change at any time and can be defined differently for each instance of a running XSLT processor.
Again using the sort element for an example, we would change all appearences of the "order" attribute to reference a global variable that is NOT defined in the XSLT style sheet. When the XSLT processor runs into such a reference it calls the P6R::P6IXPathVariables::lookupVariable() method of an object that is defined by the application. This object makes it self known by calling the XSLT processors P6R::p6IXSLT::setExternalFunctions() method to register.
Once the P6R::P6IXPathVariables object is registered, the application can dynamically return the value for the "order" attribute as it sees fit based on whatever external input it can access (e.g., a file, a socket). The XSLT sort element also allows the caller to set a collation string via an attribute value template. Just as we did with the order attribute, the calling application can use different collations based on if it is running on a Windows or Unix operating system or if some web user has selected a different language to view an XSLT generated page.
The P6R XSLT processor does support references to variables inside non-XSLT elements (e.g., an attribute of an HTML element making reference to an XSLT variable: <A href='{$lv4}'>Hi There</A> , here a URL is defined by the XSLT variable "{$lv4}".
A QName is essentially the result of resolving an XML prefix to its URI value. For example, given the element: "<html:h2>", where the "html" name space has the associated name space definition: xmlns:html='http://www.w3.org/1999/xhtml', the QName must represent that URI and the 'local' part of the name which is 'h2'. There is no standard on how this is done so we have the following algorthm:
The encoding is simple: (1) all '/' characters are replaced with '&' (2) all ':' characters are replaced with '-', and (3) the name of the extension function or element name is placed at the very end of the string with a "&p-" connector.
So for our example above its QName would be: 'http-&&www.w3.org&1999&xhtml&p-h2'. Anything that has a namespace prefix is translated into a QName by the XSLT compiler. In the Section above, P6R's XSLT Element Extensions, we defined our own version of the 'number' XSLT element, which requires the use of the 'http://www.p6r.com/XSLT/extensions' namespace URI. Every time the XSLT compiler sees an element defined as '<P6R:number>' with the matching xmlns:P6R='http://www.p6r.com/XSLT/extensions' definition, it will translate the reference into the element: 'http-&&www.p6r.com&XSLT&extensions&p-number' which is the string that the XSLT run-time processor is expecting.
This translation is done because the actual prefix used (e.g., 'P6R', 'html') is meaningless. Equality comparison must be done by matching URIs and the local part of the name. Please refer to any of the references listed in the Section, XSLT References, above.
All 'collation' and 'lang' attributes of XSLT elements (e.g., sort, key, for-each-group) can be full XPath expressions in P6R's XSLT processor. This allows then to obtain values from source documents as well as external functions (see Section "Attribute Value Templates" above).