Presentation is loading. Please wait.

Presentation is loading. Please wait.

XSLT for Data Manipulation By: April Fleming. What We Will Cover The What, Why, When, and How of XSLT What tools you will need to get started A sample.

Similar presentations


Presentation on theme: "XSLT for Data Manipulation By: April Fleming. What We Will Cover The What, Why, When, and How of XSLT What tools you will need to get started A sample."— Presentation transcript:

1 XSLT for Data Manipulation By: April Fleming

2 What We Will Cover The What, Why, When, and How of XSLT What tools you will need to get started A sample “Hello World” application Enough XSLT Constructs to get started, given from a ColdFusion point-of-view

3 What is XSLT eXstensible Stylesheet Language: Transformations Transformation Language High-Level data manipulation language A language for transforming the structure of an XML document Primarily designed by the W3C for transforming one XML document into another

4 What is XSLT - cont’d The XSLT language is expressed as a well-formed XML document The XSLT language belongs to the XSLT Namespace An XSLT transformation describes rules for transforming a source tree into a result tree. This set of rules is called a “stylesheet”

5 What is XSLT - cont’d These “rules” have two parts Pattern Matched against nodes in the source tree Template Can be instantiated to form part of the result tree

6 What is XSLT - cont’d The result tree is separate from the source tree The result tree can be in a completely different form from the source tree

7 Output Formats Optional Parser will default the output type if the tag is omitted. Top-Level Element used to define the output type desired Enables you to specify encoding for output

8 Output Format - cont’d Three types of output XML output is an XML document or XML document fragment appears in the resulting output

9 Output Formats - Cont’d HTML Output is an HTML document Text Allows output in many other text-based formats Comma-seperated values RTF PDF EDI SQL Javascript

10 Why would I use XSLT XSLT is a supported w3c standard. XSLT Provides the traditional language conventions that we are used to when processing data Looping Conditional Logic Expressions Variables

11 Why would I use XSLT - cont’d Dynamic Efficient Facilitate separation of Data and Presentation

12 How I used XSLT and Why Distributed Search Application I needed to write a search engine that could function independent of the various search interfaces that we had. I needed the engine to be completely independent of the search interfaces or the search result displays.

13 How I used XSLT and Why I chose XML as the data format for I/O to the engine Uniform structure of Data regardless of the source Data could be easily parsed using XML parser

14 How I used XSLT and Why - cont’d I chose XSLT to process the XML data going into and out of the search engine With XSLT I could easily transform the data defintion output packets from the engine and create an html search form I also found XSLT to be a great way to take the search results and transform them into the various display formats we offered to our users

15

16

17

18 When would I use XSLT? When you have XML data from a source (external or internal) with no other way to process that data When the XSLT transformations are faster than the current way you have to process your XML data. Example: XSLT vs. CF processing When you need more power and flexibility than your current XML processing mechanism provides Example: CF MX XML Processing Tags/Functions

19 XML Parser MSXML This is the Parser that I used Free download from Microsoft Excellent Documentation http://msdn.microsoft.com/xml/default.asp Other Parsers - see chart on next slide Good understanding of XPath Used for XSLT expressions MSXML SDK - good Xpath documentation What tools will I need to use XSLT?

20 XML Parser Comparison Chart

21 To perform a transformation we need three things XML Data XSLT Stylesheet XML Parser Simple “Hello World” example

22

23 XML Data - Save as hello.xml Hello World

24 XSLT Stylesheet – Save as hello.xsl XSLT Example

25 Parsing – ColdFusion & MSXML Parser

26 //do not validate the xml xml.validateOnParse=false; xml.async = false; //load the xml file into the xml instance of the parser temp = xml.load("c:\inetpub\wwwroot\hello.xml"); xsl.async=false; //load the xsl file into the xsl instance of the parser xsl.load("c:\inetpub\wwwroot\hello.xsl"); output = xml.transformNode(xsl); #output#

27 XSLT Stylesheet Structure  The XSLT namespace has the URI http://www.w3.org/1999/XSL/Transform. http://www.w3.org/1999/XSL/Transform Remember that an XSLT stylesheet is a well-formed XML document, therefore you must always include the corresponding closing tag. The tag is a synonym for either one is acceptable

28 XSLT Stylesheet Structure - cont’d  Can use any prefix, provided that there is a namespace declaration that binds the prefix to the URI of the XSLT namespace An element occurring as a child of an xsl:stylesheet element is called a top- level element

29 Top Level Elements

30 Top Level Elements - cont’d...

31 Templates “Match” is a pattern, the pattern is expressed using Xpath Pattern describes which nodes in the source tree the template rule matches matches the root node matches the title node

32 Templates - cont’d matches the Title node that is a child to the Chapter node My Title

33 Templates - cont’d matches the title attribute of the chapter node <chapter title=”my title” …

34 Templates - cont’d When the template is instantiated (a match condition is met), the instructions within the template tags are executed and the resulting data is copied to the result tree. ….instructions….

35 For each child of the current node Find the matching template rule Instantiate the template rule

36 Allows you to control the order that template rules are applied

37 Extract the required information from the node directly …

38 - Looping XSLT: … ColdFusion: …

39 - Conditional Logic XSLT:, ColdFusion: #name#, Result: Bob, Mary, John, Martha, Sue

40 - Conditional Logic XSLT: (small) (medium) (large) ColdFusion: (small) (medium) (large)

41 - Variables XSLT:... ColdFusion: #listgetat(list,n)# Variables may be defined Globally or Locally Local variables can be defined within a template body

42 Datatypes Variables are not statically typed, rather they take whatever type of value is assigned to them, just as ColdFusion does String Number Boolean Node-Set A set of nodes in the source tree Tree

43 Expressions Syntax of expressions is defined by the XPath Recommendation Used as attribute values for many XSLT elements

44 Resources XSLT – Programmer’s Reference by Michael Kay (Wrox)* W3C* http://www.w3c.org Microsoft MSXML SDK Documentation* http://msdn.microsoft.com/library/default.asp?url=/library/en- us/xmlsdk/htm/sdk_intro_6g53.asp http://msdn.microsoft.com/library/default.asp?url=/library/en- us/xmlsdk/htm/sdk_intro_6g53.asp XSL-List http://www.mulberrytech.com/xsl/xsl-list * I have relied heavily on these resources not only for the application development I have done, but also in preparation for this presentation. Many of the information and examples come from one of these sources.


Download ppt "XSLT for Data Manipulation By: April Fleming. What We Will Cover The What, Why, When, and How of XSLT What tools you will need to get started A sample."

Similar presentations


Ads by Google