Presentation on theme: "Introduction to XSLT. What is XML? Design Goals of XML XML Format XML Declaration ElementsAttributes."— Presentation transcript:
Introduction to XSLT
What is XML? Design Goals of XML XML Format XML Declaration ElementsAttributes
Design Goals of XML XML shall be straightforwardly usable over the Internet. XML shall support a wide variety of applications. XML shall be compatible with SGML. It shall be easy to write programs which process XML documents. The number of optional features in XML is to be kept to the absolute minimum, ideally zero. XML documents should be human-legible and reasonably clear. The XML design should be prepared quickly. The design of XML shall be formal and concise. XML documents shall be easy to create. Terseness in XML markup is of minimal importance.
XML Format XML contains elements, attributes, and data. An example XML entry would look like: Tom Sawyer Mark Twain XML contains elements, attributes, and data. An example XML entry would look like: Tom Sawyer Mark Twain
XML Declaration The XML Declaration should appear at the top of each XML file and should specify the XML version and the encoding used within the XML. An example XML declaration would look like:
Elements XML Elements are contained within <> symbols and must nest properly. Each node that opens must have a corresponding close node. Nodes can contain attributes, data, and “child” nodes. An example XML element (also called a node) with a single piece of data would look like: Tom Sawyer Tom Sawyer
Attributes An XML Attribute is a single piece of data assigned to an XML Element. If data is assigned as an attribute, the data can not be split further into sub-elements. XML attributes should only be used if the data will never need additional elements created below. An example XML element with an attribute and a single piece of data would look like: Tom Sawyer Tom Sawyer
XSLT Basics What is XSLT? XML Declaration and XSLT Declaration Connecting to an XML Data file
What is XSLT? An XSLT stylesheet utilizes XPath in order to transform the initial XML document into another document. The original XML document must be well formed. The resultant document should also be well formed, though in certain instances, this can be overridden as necessary.
Declarations In addition to the XML declaration, an XSLT stylesheet must specify a style sheet declaration. The style sheet declaration is what enables the XSLT to utilize the binding features. An example XML Style Sheet Declaration would look like:
Connecting to XML Data In order to client-side bind the XML Data with the XSLT Stylesheet, a single line must be added within the XML Data. An example binding line would look like: This line should appear directly beneath the XML Declaration in the XML Data file.
XSLT Tags position function mod
The element is used to create individual templates within a single stylesheet. These templates can be accessed by simple matching or called directly via the name attribute.
When an XSLT style sheet comes across an tag, the style sheet will look for matching nodes. The matching node is determined by the value located within the match attribute. In this case a forward slash (/). In XSLT, a forward slash represents the root node of the XML data. In this case, the template should be matched only a single time as only a single root node can exist within an XML document.
15 When an XSLT style sheet comes across an tag, the style sheet will compare current nodes with available tags. For each match it comes across (in the current node set), the template will be applied. The select statement can be added to the tag in order to specify the order in which the nodes are processed.
16 The tag is used to take the value (or attribute value) from an XML element within the XML Data file and use it within the output stream of the stylesheet. The standard use is to write output to the final output.
The tag allows the XSLT to loop through a set of nodes at which point it can use data within each node for output. The is often used to create lists or tables of repeating data. XPath is used to determine which selection will be looped and can include select statements to filter the looped items.
18 The tag can be used within lops in order to sort the nodes before the final output has been created. This is often useful for alphabetizing items within a repeating list.
19 The statement allows the XSLT to perform a test on the current node set to see if it meets conditions for continued processing. The statement must contain the entire section it will affect. statements are most often used within loops.
20 The statement is used to select a single instance of multiple possibilities. The first condition that is met will be used, if no condition are met, the statement allows the use of which will be the catch-all condition.
position function The position function is used to determine the current position in the node set. This tag will often be used within loops in order to number the output.
mod Mod has many applications, but the most common is alternating row colors within a table. Because of the nature of mod, the developer can determine how often a pattern repeats (every other row, every third row, etc.).
23 The tag works very much like with the exception that the developer is able to call a chosen template regardless of the current node in use. This adds the ability to call template that have nested calls whether or not the original template should have been called in the first place.
and and The tag allows the XSLT to create a copy of the currently selected node. The tag is very similar to the tag is very similar to the
"name": "and and The tag allows the XSLT to create a copy of the currently selected node.",
"description": "The tag is very similar to the tag is very similar to the