Presentation is loading. Please wait.

Presentation is loading. Please wait.

XSL Transformations Transforming XML document into other (XML) documents 1XSL Transformations.

Similar presentations


Presentation on theme: "XSL Transformations Transforming XML document into other (XML) documents 1XSL Transformations."— Presentation transcript:

1 XSL Transformations Transforming XML document into other (XML) documents 1XSL Transformations

2 What is XSL? XSL = eXtensible Stylesheet Language – Stylesheet language for XML documents XSLT = XSL Transformation – Transformation of XML documents into other formats, like XML documents HTML document Microsoft Word documents, etc XSL itself is an XML application – Defined by an XML Schema XSL uses XPath to navigate XML documents XSL is a W3C recommendation – 1999: XSL Transformations (XSLT), version 1.0 – 2007: XSL Transformations (XSLT), version 2.0 Version 3.0, work in progress 2XSL Transformations

3 XSL document, example Students Students Number Name Address 3XSL Transformations

4 Link and XML document to a XSL document Anders Roskilde Bill London 4XSL Transformations

5 XSL element – Finds the first (if any) occurrence matching ”XPath expression” Examples – Matches the whole document – Matches the element student – The root element in my example XML document – No match → nothing is translated 5XSL Transformations

6 XSL element – Finds the first occurrence (if any) matching the ”XPath expression”, and sends the value to the output stream. Examples – Matches the name element in the current element, and sends the value of the name element to the output stream – Matches the id attribute (note the @) in the current element, and sends the value of the id attribute to the output stream 6XSL Transformations

7 XSL element – Finds every occurrence of elements matching ”XPath expression” – Like a loop in ordinary programming languages Example – Matches every student element (in turn) 7XSL Transformations

8 XSL element – Match if “Boolean expression” evaluates to true Example – True if the value of the id attribute > 14000 > means greater than 8XSL Transformations

9 XSL support in Microsoft Visual Studio Microsoft Visual Studio Ultimate has some interesting XSL features – Support for writing XSL documents – Applying XSLT to XML files Showing the output on the screen If you convert to HTML you can even see the HTML – Right-click -> View source 9XSL Transformations

10 XSL transformation on the client side Most modern browsers can do XSL transformations Browser GETs the XML file Browser recognizes the link to the XSL file Browser GETs the XSL file Browser applies the XSL file to the XML file, and shows the output 10XSL Transformations

11 XSL transformation on the server side An ASP.NET code-behind/C#, example using System.Xml.XPath; using System.Xml.Xsl; protected void Page_Load(object sender, EventArgs e) { string MyXmlPath = Request.PhysicalApplicationPath + "\\students.xml"; string MyXsltPath = Request.PhysicalApplicationPath + "\\students2Html.xslt"; XPathDocument xmlDoc = new XPathDocument(MyXmlPath); XslCompiledTransform XSLTransform = new XslCompiledTransform(); XSLTransform.Load(MyXsltPath); XSLTransform.Transform(MyXmlPath, null, Response.Output); } Source – http://weblogs.asp.net/dotnetstories/archive/2011/02/06/displaying-xml- data-using-xslt-transformations-in-an-asp-net-site.aspx 11XSL Transformations


Download ppt "XSL Transformations Transforming XML document into other (XML) documents 1XSL Transformations."

Similar presentations


Ads by Google