XSLT is a much richer language, and the only reason for preferring XSLT is that it's supported in a wider range of environments (for example, in the browser). Then decide what XSLT processor you want to use. There's a wide choice for XSLT ; a rather narrower choice for XSLT Then look in the documentation for that XSLT processor. > - Native XSLT anchorrestaurantsupply.com The XPath datamodel > is already there anchorrestaurantsupply.com is 'native' thanks to anchorrestaurantsupply.com > - Native C/C++ XSLT processor for LAMP and others You can run anchorrestaurantsupply.com on Linux using Mono. You can run Mono on Apache using mod_mono. No issues with MySQL.
Schema-aware processing with XSLT 2. Frequently used acronyms W3C: To try the examples in this article, you'll need an XSLT 2. For the purpose of this article, I used an evaluation copy of the commercial product Saxon-SA. You can download a free day evaluation license to try the features; see Related topics for details. The finer details of XML Schema language are beyond the scope of this article, but you can refer to Related topics to learn more.
Why write schema-aware stylesheets? Schemas are typically available for well-known XML vocabularies and other large applications.
As the stylesheet writer, however, you are able to maintain the schemas and the types yourself. By doing so, you can extract numerous benefits for the application architecture and the business problem the application is intended to solve.
Validate the input XML documents: This allows type-aware operations to be performed on the nodes in the XSLT stylesheet. Input validation can also ensure that the XSLT stylesheet doesn't process invalid input. Validate the output XML documents: This is one of the biggest benefits of schema-aware XSLT stylesheet design from an overall application architecture point of view.
By validating the output of XSLT transforms before handing over control of the XML stream to some other forward process, you can detect many errors early and avoid errors later in the processing chain. Import the element , attribute, and type information from a schema into the XSLT stylesheet: Using the schema components in the stylesheet allows for enhanced type checking. For example, you can define data types of variables to be built-in or user-defined schema types. You can put XML schemas to use during the compilation of the stylesheet or during the runtime—in other words, when the input XML document is transformed.
The XSLT 2. It's also worth noting that you can write schemas inline in the XSLT stylesheet I'll present an example for this later. This can be useful for small applications or to validate the temporary trees during the course of the transformation. The following examples illustrate the three usages of schemas in stylesheets, as described previously. Listing 1 shows an XML document, named po. Listing 1. Listing 2. You need to be aware of the XML schema syntax to understand this example.
Now, write a simple XSLT 2. Listing 3 shows the code for the stylesheet, which is named printitems1. Listing 3. Transform po. Source document is not a purchase order Processing terminated by xsl: Now invoke the XSLT transformation as follows: Transform -val: Water for Elephants Glass Castle: A Memoir This stylesheet illustrates the idea that you can execute useful processing in the stylesheet only if the input document is validated with the desired schema.
If the XML document is not validated, then the stylesheet won't do anything useful, as illustrated by the first output. Validate the output XML documents The next example demonstrates how you can request the validation of output trees prior to serialization. Listing 4 shows a stylesheet named printitems2. Listing 4. Suppose you want to modify a portion of the stylesheet, as follows: Running the same command line as shown previously produces the following output: Error on line 32 of file: There is no global element declaration for itemsTag, so strict validation will fail Failed to compile stylesheet.
This error occurs during transformation, because the validation of the output tree with the inline schema did not succeed. As demonstrated, you cannot produce an invalid output from the XSLT transformation. Follow another interesting example in Listing 5 for the validation of the output XML tree. This example illustrates how you can request validation of different parts of output tree with different schemas. Listing 5. Transform outputval.
Here the stylesheet acts as a dummy input XML. The above command line produces the following output: Nothing wrong happened here, because validation of tree fragments shown with bold in Listing 5 succeeded without problems with the two inline schemas. Now change the root template xsl: Now run the stylesheet of Listing 5 , with the root template changed as above the command line remaining the same. The output produced by the transformation now is: Validation error on line 47 of file: Run-time errors were reported Since you introduced a validation error in the generated markup, the transformation did not succeed.
This example illustrates that XSLT 2. Import type information from a schema Now look at another example, which uses the schema-defined user types as function parameters. This is a powerful concept and illustrates that you can extend the type system of XSLT in an unlimited way.
Listing 6 shows the schema, named po2. Listing 6. The only difference is that it names the POType type explicitly rather than using it anonymously in the schema.
You will use this type name in the function parameter. Now try to run the ordersummary. Listing 7. Required item type of first argument of my: As a consequence, the element nodes had the xs: The error occurred because the my: Run the transformation as follows: This time, you get the correct output, as shown here: XYZ Ltd.
First, because the input document was validated, the function got the arguments with the correct type. Making XSLT stylesheets schema-aware produces the following benefits: You can perform type-aware operations on the nodes by validating the input trees and attaching the type annotations to the XML nodes.
This also ensures that invalid input is not processed by the stylesheet. You can validate output trees with a particular schema, thereby making sure that you don't produce invalid output from the XSLT transformation.
This provides enhanced static typing, which is beneficial during the compilation phase of the stylesheet. Enhanced compile-time type checking reduces the likelihood of errors popping up in later phases. The sooner that you detect the errors, the less amount of time you require to fix them.
Having user-defined schema types available in the stylesheet makes the type system of XSLT infinitely extensible. As a result, the stylesheet comes closer to solving the business problem.
Read this introduction to the XSLT language and learn where the language comes from, what it's good at, and why you should use it.
Since Saxon 9. The repository does not contain the development branch of the code, only versions that have been released; it is the best way of obtaining bug fixes quickly if you are prepared to build the product from source which is not for the faint-hearted.
Note that bug fixes are typically made available in Subversion as soon as they are available, and are then consolidated periodically into a maintenance release. Source code under development is not held in Subversion, and is not available until a tested release is issued.
Sometimes prereleases of new facility releases are made available for testing; these are announced on the saxon-help mailing list but will not generally be advertised here. If you require a release that is no longer listed, please ask: It supersedes the earlier Saxon-CE product. For information about the product, see the Saxon-JS home page. You are free to enter new bugs here directly, or if bugs are raised by other routes such as the mailing list we will register them there if they need to be tracked.
The Redmine database also offers discussion forums and these are the best way to raise technical issues or questions that need an answer from the Saxonica development team.
The SourceForge project hosts a mailing list, saxon-help, which provides a good way of reaching other Saxon users. Since SourceForge is dedicated to open source, we don't encourage use of this list for issues specific to the commercial versions of the product. The StackOverflow site is the best place to get a good answer to straight coding questions, while the xsl-list also known as the Mulberry list is the place for deeper discussions about the nature of XSLT as a language.
Source code for Saxon-HE 4. The latest maintenance release for Java and. NET is Saxon 9. Saxon 9. Since Saxon 9. The repository does not contain the development branch of the code, only versions that have been released; it is the best way of obtaining bug fixes quickly if you are prepared to build the product from source which is not for the faint-hearted. Note that bug fixes are typically made available in Subversion as soon as they are available, and are then consolidated periodically into a maintenance release.
Source code under development is not held in Subversion, and is not available until a tested release is issued. Sometimes prereleases of new facility releases are made available for testing; these are announced on the saxon-help mailing list but will not generally be advertised here. If you require a release that is no longer listed, please ask: It supersedes the earlier Saxon-CE product. For information about the product, see the Saxon-JS home page.
You are free to enter new bugs here directly, or if bugs are raised by other routes such as the mailing list we will register them there if they need to be tracked.