Google
 
   
Login
Username:

Password:


Lost Password?

Register now!
Search
Main Menu
top books
Polls
What do you think about php-deluxe.net?
Excellent!
Cool
Hmm..not bad
What the hell is this?
encyclopedia
recommendation
compare webbrowser
Freenet DSL
Who's Online
5 user(s) are online (3 user(s) are browsing encyclopedia)

Members: 0
Guests: 5

more...
browser tip
Unix Befehle
manual of unix befehle
recommendation!
Sponsored
partner

XSL Transformations

Extensible Stylesheet Language Transformations, or XSLT, is an XML-based language used for the transformation of XML documents. The original document is not changed; rather, a new XML document is created based on the content of an existing document. The new document may be serialized (output) by the processor in standard XML syntax or in another format, such as HTML or Binary and text files. XSLT is most often used to convert data between different XML schemas or to convert XML data into web pages or Portable Document Format documents.

XSLT was produced as a result of the Extensible Stylesheet Language (XSL) development effort within W3C during 1998–1999, which also produced XSL-FO (XSL-FO) and the XML Path Language, XPath. The editor of the first version (and in effect the chief designer of the language) was James Clark (XML expert). The first XSLT specification was published as a Recommendation by the W3C on 16 November 1999. Work on a greatly expanded second version, under the editorship of Michael Kay, is ongoing.

=Overview=

The XSLT language is declarative programming — i.e. rather than listing an imperative programming sequence of actions to perform in a state (computer science) environment, an XSLT stylesheet consists of a template rules collection, each of which specifies what to add to the result tree data structure when the XSLT processor, scanning the source tree , according to a fixed algorithm, finds a node that meets conditions. Instructions within template rules are processed as if they were sequential instructions; but, they, in fact, comprise functional programming expression (programming)s, representing their evaluated results - ultimately, nodes to be added to the result tree.

The XSLT specification defines a transformation in terms of source and result trees to avoid locking implementations into system-specific Application programming interfaces and memory, network and file Input/output issues. For example, the specification does not mandate that a source tree always be derived from an XML file , since it may be more efficient for the processor to read from an in-memory Document Object Model object or some other implementation-specific representation. Output may be in a format not envisioned by the XSLT language s designers. However, XSLT processing often begins by reading a serialized XML input document into the source tree and ends by writing the result tree to an output document. The output document may be XML, but can be HTML, RTF, TeX, comma-separated values, Binary and text files or any other format that the XSLT processor is capable of producing.

XSLT relies upon the W3C s XPath language for identifying subsets of the source document tree, as well as for performing calculations. XPath also provides a range of functions, which XSLT itself further augments. This reliance upon XPath adds a great deal of power and flexibility to XSLT.

Most current operating systems have an XSLT processor installed. For example, Windows XP comes with the MSXML3 library, which includes an XSLT processor. Earlier versions may be upgraded and there are many alternatives, see the External links section.

The W3C finalized the XSLT 1.0 specification in 1999. The XSLT 2.0 specification currently has Working Draft status.

=Example=

Example XSLT Stylesheet:

test1 h1 { padding: 10px; padding-width: 100%; background-color: silver } td, th { width: 40%; border: 1px solid silver; padding: 10px } td:first-child, th:first-child { width: 20% } table { width: 650px } The following host names are currently in use at Host nameURLUsed by

Example of incoming XML for above stylesheet:

www World Wide Web site java Java info www World Wide Web site validator web developers who want to get it right

Output XHTML that this would produce (whitespace has been adjusted here for clarity):

test1 h1 { padding: 10px; padding-width: 100%; background-color: silver } td, th { width: 40%; border: 1px solid silver; padding: 10px } td:first-child, th:first-child { width: 20% } table { width: 650px } Sun Microsystems Inc. The following host names are currently in use at sun.com Host name URL Used by www http://www.sun.com World Wide Web site java http://java.sun.com Java info The World Wide Web Consortium The following host names are currently in use at w3.org Host name URL Used by www http://www.w3.org World Wide Web site validator http://validator.w3.org web developers who want to get it right

= Template rule processing =

XSLT stylesheets are declarative, not procedural; rather than defining a sequence of operations to execute, they define rules and other hints applied during processing, according to a fixed algorithm. The algorithm, which is somewhat complicated, is described below, although many of its esoteric details have been omitted.

Every XSLT processor is required to behave as if it had followed the following steps: # Read the XSLT stylesheet with an XML parser and convert (Abstraction (computer science), rather) its content to a tree of nodes (the stylesheet tree ), according to the XPath data model. Compile-time stylesheet syntax errors are detected at this stage. Stylesheets can be modular, so any transclusions (xsl:include, xsl:import instructions) would also be handled at this stage in order to bring template rules and other top-level stylesheet elements from other XSLT documents into the stylesheet tree. # Read the input XML with an XML parser and convert its content to a tree of nodes (the source tree), according to the XPath data model. The stylesheet may reference other XML sources via document() function calls. These are, typically, evaluated at run-time, since their locations may have to be calculated and the function calls may not even be reachable. (The example above does not reference any other source documents.) # Strip whitespace-only text nodes from the stylesheet tree, except those that are descendants of xsl:text elements. This allows nested elements in template rules to be on separate ( pretty ) lines in the original XSLT without resulting in unintended whitespace being added to the result tree. # Strip whitespace-only text nodes from the source tree, if xsl:strip-space instructions are present in the stylesheet. This allows pretty input XML to be processed in a manner that ignores extraneous whitespace. (The example above does not use this feature.) # Supplement the stylesheet tree with a trio of built-in template rules that provide default behavior for any node type that might be encountered during processing. One template rule is provided for processing the root node or any element node ; it directs the processor to continue and process each child node. Another template is provided for any text node or attribute node ; it directs the processor to make a copy of that result tree node. A third template rule is provided for any comment node or processing instruction node ; it is a no-op. Templates, explicitly provided in the stylesheet, will override some or all of these. If the stylesheet contains no explicit template rules, the built-in template rules will result in a recursive source tree descension and only text nodes are copied to the result tree (attribute nodes will not be reached because they are not children of their parent elements). This result is generally never desirable, as it tends to be just a concatenation of the non-markup character data from the XML source. # Process the root node of the source tree. The procedure for node processing is described below. # Serialize the result tree, if desired, according to hints provided in the xsl:output instruction.

When processing a node, the following steps are undertaken: # The best-matching template rule for that node is located. This is facilitated by each template rule s match pattern (an XPath-like expression), indicating the nodes to which it can be applied. Each template is assigned a relative priority and import precedence by the processor to help ease conflict resolution. The order of template rules in the stylesheet can also help resolve conflicts between templates which match the same nodes, but it does not affect the order in which nodes are processed. # Template rule contents are instantiated. Elements in the XSLT namespace (prefixed with xsl:, typically. It is the namespace identifier bound to the prefix — not the prefix, itself — that matters.) are treated as instructions and have special semantics that guide how they are interpreted. Other elements and text nodes in the template rule are copied, verbatim (namespaces and all) to the result tree. Comments and processing instructions are ignored.

The XSLT instruction xsl:apply-templates, when processed, results in a new set of nodes being selected for processing. The nodes are identified via an XPath expression. Each node is processed in document order (the relative order in which they appear in the original document).

XSLT extends XPath s function library and allows XPath variables to be defined. These variables have different scopes in the stylesheet, depending on where they are defined and their values can originate outside the stylesheet. A variable s value cannot be changed during processing.

Although this procedure may sound complicated, it has the net effect of making XSLT much like other web templating languages. If the stylesheet consists only of a single template rule that matches the root node, everything in the template is essentially copied to the output, except for the XSLT instructions (the xsl:… elements), replaced by computed content. XSLT even offers an abbreviated stylesheet format ( literal result element as stylesheet ) for these simple, single-template transformations. However, the ability to define separate template rules greatly increases XSLT s versatility and efficiency, especially when producing output that is very similar to the input.

=See also=

  • Streaming Transformations for XML is a high-speed, low memory consumption alternative to XSLT
  • =External links=

  • Implementations
  • Implementations for Java programming language:
  • [http://xml.apache.org/xalan-j/ Xalan-Java]
  • [http://saxon.sourceforge.net/ SAXON] by Michael Kay
  • [http://www.blnz.com/xt/index.html XT] originally by James Clark
  • Oracle XSLT, in the [http://www.oracle.com/technology/tech/xml/xdkhome.html Oracle XDK]
  • Implementations for C programming language or C plus plus:
  • [http://xml.apache.org/xalan-c/ Xalan-C++]
  • [http://xmlsoft.org/XSLT/ libxslt] the XSLT C library for GNOME
  • [http://www.gingerall.com/charlie/ga/xml/p_sab.xml Sablotron], which is integrated into PHP
  • Implementations for Perl:
  • [http://search.cpan.org/~msergeant/XML-LibXSLT-1.57/LibXSLT.pm XML::LibXSLT] is a Perl interface to the libxslt C library
  • Implementations for Python programming language:
  • 4XSLT, in the [http://4suite.org/ 4Suite] toolkit by Fourthought, Inc.
  • [http://codespeak.net/lxml/ lxml] by Martijn Faassen is a Pythonic wrapper of the libxslt C library
  • Implementations for JavaScript:
  • [http://goog-ajaxslt.sourceforge.net/ Google AJAXSLT] AJAXSLT is an implementation of XSL-T in JavaScript, intended for use in fat web pages, which are nowadays referred to as Ajax (programming) applications. Because XSL-T uses XPath, it is also an implementation of XPath that can be used independently of XSL-T.
  • Implementations for specific operating systems:
  • Microsoft s [http://msdn.microsoft.com/XML/XMLDownloads/default.aspx MSXML] library may be used in various Microsoft Windows application development environments and languages, such as .Net, Visual Basic, C, and JScript.
  • Saxon.NET [http://weblog.saxondotnet.org Project Weblog], an IKVM.NET-based port of Dr. Michael Kay s and Saxonica s Saxon Processor provides XSLT 2.0, XPath 2.0, and XQuery 1.0 support on the .NET platform.
  • Implementations integrated into web browsers: (Comparison of layout engines (XML))
  • .
  • Safari (web browser) 1.3+ has [http://www.apple.com/macosx/features/safari/ native XSLT support].
  • X-Smiles has native XSLT support.
  • Opera_(web_browser) has native XSLT support since Version 9.
  • Internet Explorer 6 supports XSLT 1.0 via the MSXML library (described above). IE5 and IE5.5 came with an earlier MSXML component that only supported an older, nonrecommended dialect of XSLT. A newer version of MSXML can be downloaded and installed separately to enable IE5 and IE5.5 to support XSLT 1.0 through scripting, and if certain Windows Registry keys are modified, the newer library will replace the older version as the default used by IE.
  • Documentation
  • [http://www.w3.org/TR/xslt XSLT 1.0 W3C Recommendation]
  • [http://www.w3.org/TR/xslt20/ XSLT 2.0 W3C Working Draft]
  • [http://zvon.org/xxl/XSLTreference/Output/index.html Zvon XSLT 1.0 Reference]
  • [http://www.nwalsh.com/docs/tutorials/xsl/xsl/ XSL Concepts and Practical Use] by Norman Walsh
  • [http://www-106.ibm.com/developerworks/xml/library/x-hands-on-xsl/index.htmldwzone=xml Tutorial from developerWorks] (1 hour)
  • [http://zvon.org/xxl/XSLTutorial/Output/index.html Zvon XSLT Tutorial]
  • [http://www.w3schools.com/xsl/ XSLT Tutorial]
  • [http://www.brics.dk/~amoeller/XML/transformation/ Quick tutorial]
  • [http://www-106.ibm.com/developerworks/xml/library/x-xslt/article=xr What kind of language is XSLT]
  • [http://www.idealliance.org/papers/xml2001/papers/html/05-03-06.html XSLT and Scripting Languages]
  • [http://www.xsltwiki.com/ XSLT Community Wiki]
  • Mailing lists
  • [http://www.mulberrytech.com/xsl/xsl-list/|The XSLT list hosted by Mulberrytech]
  • *Blogs

  • [http://www.xsltblog.com A commentary, news, and evangelism weblog devoted to XSLT]
  • *Books **[http://www.oreilly.com/catalog/xslt/index.html XSLT] by Doug Tidwell, published by O REILLY (ISBN 0-59-600053-7) **[http://www.amazon.com/exec/obidos/tg/detail/-/1861003129/102-8317111-9468103v=glance XSLT Programmer s Reference] by Michael Kay (ISBN 1-86-100312-9) **[http://www.kirsanov.com/xsltwd XSLT 2.0 Web Development] by Dmitry Kirsanov (ISBN 0-13-140635-3) **[http://www.awprofessional.com/title/0201770830 XSL Companion, 2nd Edition] by Neil Bradley, published by Addison-Wesley (ISBN 0-20-177083-0) **[http://www.amazon.co.uk/exec/obidos/ASIN/0764547763/qid=1125175777/sr=1-3/ref=sr_1_2_3/026-5890513-5023639 XSLT and XPath on the Edge (Unlimited Edition)] by Jeni Tennison, published by Hungry Minds Inc, U.S. (ISBN 0-76-454776-3) **[http://www.amazon.com/exec/obidos/tg/detail/-/0130404462/qid=1128046903/sr=1-1/ref=sr_1_1/102-4452158-4354556v=glance&s=books XSLT & XPath, A Guide to XML Transformations] by John Robert Gardner and Zarella Rendon, published by Prentice-Hall (ISBN 0-13-040446-2)

  • Tools
  • Libraries
  • [http://fxsl.sf.net/ FXSL] is a library implementing support for Higher-order functions in XSLT. FXSL is written in XSLT itself.
  • Other
  • ***[http://www.saxonica.com Saxon XSLT and XQuery processor] developed by Michael Kay
  • [http://www.exchangerxml.com/ Exchanger XML Editor with XSLT Debugger] Java based XML Editor with XSLT Debugger.
  • [http://www.editix.com A sample of XSLT Editor and Debugger] A tool for creating and testing XSLT documents
  • [http://www.ultra-fluide.com/ressources/en/semark/presentation.htm XSL Transformation] to provide markup of XML contents from external lexicons
  • [http://www.netbeans.org Netbeans IDE] provides an XSLT development environment
  • [http://www.marrowsoft.com/ Xselerator] dedicated XSLT editor/debugger with support for arbitrary XSLT engines
  • [http://www.stylusstudio.com/ Stylus Studio] XSLT editor/debugger/mapper/profiler with support for various XSLT 1.0/2.0 processors
  • [http://www.oxygenxml.com/ <oXygen /> XML] XML/XSLT editor which also supports XQuery, RelaxNG, XML Schema, SVG, and others.