Download presentation
Presentation is loading. Please wait.
1
XSLT transformations Or how to get your XML to become HMTL
2
Agenda What is XSL and XSLT How do I use them Example usage
3
What is XSL and XSLT Recap –XSL – EXtensible Stylesheet Language –XSLT - EXtensible Stylesheet Language Transformation One is the mechanism to store the structuring of the document The other is the method of applying that
4
XSLT XSLT transforms an XML document into another document XSLT uses XPath to navigate in XML documents XSLT is a W3C Standard
5
Why? You might have an XML document in one format (the supplier) and it is needed in another structure by another party (the manufacturer) You might want to convert from XML to another XML type language such as HTML or WML
6
How does it work? You create the structure of the new document You find the bits of the original document that you wish to extract information from You then place the original data into the new structure by transforming the data
7
XSLT files Start with an XML declaration Then choosing the node(s) that you wish to use Then state your formatting instructions Place your data in the relevant area For example
8
Base xml file <catalog><cd> Empire Burlesque Empire Burlesque Bob Dylan Bob Dylan <country>USA</country><company>Columbia</company><price>10.90</price><year>1985</year></cd><cd> Hide your heart Hide your heart Bonnie Tyler Bonnie Tyler <country>UK</country> CBS Records CBS Records <price>9.90</price><year>1988</year></cd>…….
9
XSL file My CD Collection My CD Collection Title Title Country Country </xsl:template></xsl:stylesheet> HTML formatting XSL code to choose area of XML file XSL code to choose node to display
10
Output
11
How to filter the list Because you use XPATH to access nodes you can filter data e.g. Will list every cd that costs over £10
12
Templates If you want to break down the formatting of a page to individual efforts you can use templates The command is The command is This can allow you to apply formatting to individual elements e.g
13
<html><body> My CD Collection My CD Collection <xsl:apply-templates/></body></html></xsl:template> <p> </p></xsl:template> : : </span><br/></xsl:template> : : </span><br/></xsl:template></xsl:stylesheet>
14
Write an XML file using an XSL file in ASP <% 'Load XMLxml = Server.CreateObject("Microsoft.XMLDOM").asyn c = false.load(Server.MapPath("cdcatalog.xml")) 'Load XSLxsl = Server.CreateObject("Microsoft.XMLDOM").asyn c = false.load(Server.MapPath("cdcatalog.xsl")) 'Transform file.Write(xml.transformNode(xsl)) %>
Similar presentations
© 2024 SlidePlayer.com. Inc.
All rights reserved.