Download presentation
Presentation is loading. Please wait.
Published byDevonte Austell Modified over 9 years ago
1
Introduction to XSLT
2
What is XML? Design Goals of XML XML Format XML Declaration ElementsAttributes
3
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.
4
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
5
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:
6
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
7
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
8
XSLT Basics What is XSLT? XML Declaration and XSLT Declaration Connecting to an XML Data file
9
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.
10
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:
11
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.
12
XSLT Tags <xsl:template> <xsl:apply-templates><xsl:value-of> <xsl:sort><xsl:if><xsl:choose> position function mod<xsl:call-template><xsl:copy><xsl:copy-of>
13
<xsl:template> 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.
14
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
<xsl:apply-templates> 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
<xsl:value-of> 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.
17
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
<xsl:sort> 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
<xsl:if> 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
<xsl:choose> 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.
21
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.
22
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
<xsl:call-template> 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.
24
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 <xsl:copy” tag but copies the children nodes and data as well.
25
Old vs New
26
Questions?
Similar presentations
© 2024 SlidePlayer.com. Inc.
All rights reserved.